Draw a Circle on 3d Maps Excel
Introduction
The thought of drawing objects in AutoCAD by using Excel data has been analyzed several times in this weblog. We accept seen how to draw polylines, 3D polylines, then, today nosotros volition learn how to draw circles. To tell you the truth, the code below was developed equally a response to the diverse requests that I have received the last few weeks from blog readers, likewise equally from Youtube users.
The code is based on the AddCircle method. According to AutoCAD VBA assist, the structure of this method is the following:
RetVal = object.AddCircle(Center, Radius)
Where:
RetVal: Circle object. The newly created Circle object.
Object: ModelSpace Collection, PaperSpace Drove, Block – the objects this method applies to.
Middle: Variant (three-element assortment of doubles); input-merely. The 3D WCS coordinates specifying the circumvolve's center.
Radius: Double; input-simply. The radius of the circle. Must be a positive number.
Remarks: This circumvolve is created on the XY airplane of the WCS.
The sample workbook that you will find in the Downloads section below requires two primary user inputs: the coordinates of the circle eye (in X, Y, Z) and the circle radius. And then, past clicking the "Draw Circumvolve(s)" button the circles are being drawn either in the agile drawing (if AutoCAD is already lunched), or in a new drawing. If you run the workbook with the sample information, 5 circles will be drawn in AutoCAD, which volition look like the Olympic Games logo (a pocket-size tribute to the Winter Olympics that finished the previous month).
VBA lawmaking to draw circles in AutoCAD from Excel
The lawmaking is actually a loop; almost half of it is used for initializing the AutoCAD object, as well as the active/new drawing.
Pick Explicit Sub DrawCircles() '-------------------------------------------------------------------------------------------------- 'Draws circles in AutoCAD using information - circle center coordinates and circumvolve radius - from Excel. 'The code uses tardily binding, so no reference to external AutoCAD (type) library is required. 'It goes without saying that AutoCAD must be installed at your computer before running this code. 'Written by: Christos Samaras 'Date: 04/03/2014 'email: [electronic mail protected] 'site: http://www.myengineeringworld.net '-------------------------------------------------------------------------------------------------- 'Declaring the necessary variables. Dim acadApp As Object Dim acadDoc Every bit Object Dim acadCircle Every bit Object Dim LastRow Every bit Long Dim i As Long Dim CircleCenter(0 To 2) As Double Dim CircleRadius As Double 'Activate the coordinates sail and find the concluding row. With Sheets("Coordinates") .Activate LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row Finish With 'Cheque if there are coordinates for at least one circle. If LastRow < 2 Then MsgBox "There are no coordinates to draw a circle!", vbCritical, "Circle Centre Error" Exit Sub End If 'Cheque if AutoCAD application is open. On Error Resume Adjacent Fix acadApp = GetObject(, "AutoCAD.Application") 'If AutoCAD is not opened create a new instance and arrive visible. If acadApp Is Nix Then Prepare acadApp = CreateObject("AutoCAD.Application") acadApp.Visible = True Stop If 'Check (once more) if at that place is an AutoCAD object. If acadApp Is Nada So MsgBox "Distressing, information technology was impossible to start AutoCAD!", vbCritical, "AutoCAD Mistake" Exit Sub End If On Error GoTo 0 'If at that place is no active drawing create a new i. On Fault Resume Next Set acadDoc = acadApp.ActiveDocument If acadDoc Is Zip Then Ready acadDoc = acadApp.Documents.Add together End If On Error GoTo 0 'Bank check if the active space is paper space and change it to model space. If acadDoc.ActiveSpace = 0 Then '0 = acPaperSpace in early on bounden acadDoc.ActiveSpace = 1 '1 = acModelSpace in early binding Terminate If 'Loop through all the coordinates/radius and draw the corresponding circle(due south). With Sheets("Coordinates") For i = two To LastRow 'Set the circle radius. CircleRadius = .Range("D" & i).Value 'If the circle radius is greater than 0, get the circle center and draw the circumvolve. If CircleRadius > 0 Then 'Set the circle centert. CircleCenter(0) = .Range("A" & i).Value CircleCenter(i) = .Range("B" & i).Value CircleCenter(ii) = .Range("C" & i).Value 'Draw the circle. Fix acadCircle = acadDoc.ModelSpace.AddCircle(CircleCenter, CircleRadius) End If Next i Finish With 'Zoom in to the drawing area. acadApp.ZoomExtents 'Release the objects. Set acadCircle = Nothing Set up acadDoc = Naught Set acadApp = Nil 'Inform the user almost the process. MsgBox "The circumvolve(s) was/were successfully drawn in AutoCAD!", vbInformation, "Finished" End Sub
Notation that if you have AutoCAD 2010 or a newer version, you lot will take to download and install the VBA module, otherwise the code will probably neglect.
- AutoCAD 2010 VBA module 32-bit
- 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-bit
- AutoCAD 2013 VBA module 32-bit
- AutoCAD 2013 VBA module 64-bit
- AutoCAD 2014 VBA module 32-bit
- AutoCAD 2014 VBA module 64-bit
- AutoCAD 2015 VBA module 32-bit
- AutoCAD 2015 VBA module 64-fleck
All links were copied from Autodesk's website.
Demonstration video
The short video below demonstrates the result of the above VBA code; v circles are drawn in a new AutoCAD drawing based on sample information from the Excel workbook.
Downloads
The file can exist opened with Excel 2007 or newer. Please enable macros before using information technology.
Read also
Add 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
Folio last modified: Oct 1, 2021
Source: https://myengineeringworld.net/2014/03/circles-autocad-excel-vba.html
0 Response to "Draw a Circle on 3d Maps Excel"
Publicar un comentario