How to Draw a Circle in Excel With Specific Radius

Drawing Circles In AutoCAD Using Excel VBA


Introduction


The thought of drawing objects in AutoCAD by using Excel data has been analyzed several times in this weblog. We take seen how to draw polylines, 3D polylines, so, today we will acquire how to describe circles. To tell you the truth, the code below was developed as a response to the various requests that I have received the last few weeks from blog readers, as well as from Youtube users.

The lawmaking is based on the AddCircle method. According to AutoCAD VBA assistance, the construction of this method is the post-obit:

RetVal = object.AddCircle(Heart, Radius)

Where:
RetVal: Circumvolve object. The newly created Circle object.
Object: ModelSpace Collection, PaperSpace Collection, Cake – the objects this method applies to.
Center: Variant (three-element array of doubles); input-just. The 3D WCS coordinates specifying the circle's center.
Radius: Double; input-but. The radius of the circle. Must exist a positive number.
Remarks: This circle is created on the XY airplane of the WCS.

The sample workbook that you will find in the Downloads section beneath requires ii primary user inputs: the coordinates of the circle center (in X, Y, Z) and the circle radius. Then, by clicking the "Draw Circle(southward)" button the circles are being drawn either in the active cartoon (if AutoCAD is already lunched), or in a new cartoon. If yous run the workbook with the sample data, five circles will be drawn in AutoCAD, which will wait like the Olympic Games logo (a small tribute to the Winter Olympics that finished the previous month).


VBA code to draw circles in AutoCAD from Excel


The code is really a loop; almost one-half of it is used for initializing the AutoCAD object, every bit well equally the agile/new drawing.

            Selection Explicit   Sub DrawCircles()      '--------------------------------------------------------------------------------------------------     'Draws circles in AutoCAD using information - circle centre coordinates and circle radius - from Excel.     'The code uses late binding, so no reference to external AutoCAD (type) library is required.     'Information technology goes without saying that AutoCAD must be installed at your computer earlier running this code.          'Written by:    Christos Samaras     'Engagement:          04/03/2014     'e-postal service:        [email protected]     'site:          http://world wide web.myengineeringworld.net     '--------------------------------------------------------------------------------------------------              'Declaring the necessary variables.     Dim acadApp                 Every bit Object     Dim acadDoc                 Equally Object     Dim acadCircle              As Object     Dim LastRow                 Equally Long     Dim i                       Equally Long     Dim CircleCenter(0 To ii)    As Double     Dim CircleRadius            Every bit Double          'Activate the coordinates canvas and notice the last row.     With Sheets("Coordinates")         .Activate         LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row     End With              'Check if there are coordinates for at least one circle.     If LastRow < 2 And so         MsgBox "At that place are no coordinates to describe a circle!", vbCritical, "Circumvolve Heart Error"         Get out Sub     Terminate If          'Bank check if AutoCAD application is open up.     On Error Resume Adjacent     Set acadApp = GetObject(, "AutoCAD.Application")          'If AutoCAD is not opened create a new instance and get in visible.     If acadApp Is Nothing Then         Set acadApp = CreateObject("AutoCAD.Application")         acadApp.Visible = True     Stop If          'Bank check (again) if there is an AutoCAD object.     If acadApp Is Nothing Then         MsgBox "Sorry, it was impossible to start AutoCAD!", vbCritical, "AutoCAD Error"         Get out Sub     End If     On Error GoTo 0          'If at that place is no active drawing create a new 1.     On Error Resume Next     Set acadDoc = acadApp.ActiveDocument     If acadDoc Is Nothing And then         Fix acadDoc = acadApp.Documents.Add together     End If     On Fault GoTo 0       'Cheque if the active space is newspaper infinite and alter information technology to model space.     If acadDoc.ActiveSpace = 0 Then '0 = acPaperSpace in early on binding         acadDoc.ActiveSpace = ane '1 = acModelSpace in early binding     Finish If                'Loop through all the coordinates/radius and depict the corresponding circumvolve(s).     With Sheets("Coordinates")         For i = ii To LastRow             'Set the circumvolve radius.             CircleRadius = .Range("D" & i).Value             'If the circle radius is greater than 0, get the circumvolve centre and describe the circle.             If CircleRadius > 0 And then                 'Gear up the circle centert.                 CircleCenter(0) = .Range("A" & i).Value                 CircleCenter(1) = .Range("B" & i).Value                 CircleCenter(2) = .Range("C" & i).Value                 'Depict the circle.                 Set acadCircle = acadDoc.ModelSpace.AddCircle(CircleCenter, CircleRadius)             End If         Adjacent i     Stop With          'Zoom in to the cartoon area.     acadApp.ZoomExtents          'Release the objects.     Set acadCircle = Nothing     Set acadDoc = Nothing     Set acadApp = Nothing          'Inform the user well-nigh the process.     MsgBox "The circle(southward) was/were successfully drawn in AutoCAD!", vbInformation, "Finished"   End Sub                      

Note that if you take AutoCAD 2010 or a newer version, you will have to download and install the VBA module, otherwise the code will probably fail.

  • AutoCAD 2010 VBA module 32-flake
  • AutoCAD 2010 VBA module 64-bit
  • AutoCAD 2011 VBA module 32-bit
  • AutoCAD 2011 VBA module 64-bit
  • AutoCAD 2012 VBA module 32-bit
  • AutoCAD 2012 VBA module 64-fleck
  • AutoCAD 2013 VBA module 32-scrap
  • AutoCAD 2013 VBA module 64-flake
  • AutoCAD 2014 VBA module 32-bit
  • AutoCAD 2014 VBA module 64-bit
  • AutoCAD 2015 VBA module 32-bit
  • AutoCAD 2015 VBA module 64-bit

All links were copied from Autodesk's website.


Demonstration video


The brusque video below demonstrates the event of the higher up VBA code; 5 circles are drawn in a new AutoCAD cartoon based on sample data from the Excel workbook.


Downloads


Download

The file can be opened with Excel 2007 or newer. Please enable macros before using it.


Read as well


Add together Text In AutoCAD Using Excel & VBA
Cartoon Points In AutoCAD Using Excel & VBA
Insert Blocks In AutoCAD Using Excel & VBA
Send AutoCAD Commands From Excel & VBA

Page last modified: October i, 2021

Hi, I am Christos, a Mechanical Engineer past profession (Ph.D.) and a Software Developer by obsession (10+ years of experience)! I founded this site dorsum in 2011 intending to provide solutions to various engineering and programming problems.

Add Content Cake

dentpicarmention.blogspot.com

Source: https://myengineeringworld.net/2014/03/circles-autocad-excel-vba.html

0 Response to "How to Draw a Circle in Excel With Specific Radius"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel