VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

changing objects to polylines

1 REPLY 1
SOLVED
Reply
Message 1 of 2
Anonymous
430 Views, 1 Reply

changing objects to polylines

Hello,

 

I am new at autocad macros (3-4 days so far, but have worked with VBA in EXCEL), so any help will be greatly apreciated.  I have a VBA macro that creates a shape, made out of 2 lines and 2 arcs (all joined).  I need to convert the final product to a joined polyline, using VBA.  I know normally it may be easier to draw it as a polyline but I do not have the cordinates of all the end points since I have used rotations.  How can I take the 4 segments and conect them.  (if it helps the 4 items will always be the last 4 items created and always at relatively the same spot (relative to variables)).  Here is the code I am using to make the shape.

 

'make variables
Dim UnDataOD As Variant
Dim UnDataID As Variant

Dim NCycles As Double
Dim LDRatio As Double

 

'make variable for origin

Dim Origin(0 To 2) As Double
Origin(0) = 0
Origin(1) = 0
Origin(2) = 0


'create line for data line
Dim LineStart(0 To 2) As Double 'create startpoint
LineStart(0) = 0
LineStart(1) = (DataID / 2)
LineStart(2) = 0

Dim LineEnd(0 To 2) As Double 'create endpoint
LineEnd(0) = 0
LineEnd(1) = (DataOD / 2)
LineEnd(2) = 0

Dim LineObj As AcadLine

Set LineObj = ThisDrawing.ModelSpace.AddLine(LineStart, LineEnd) 'draw line

 

'rotate/mirror line for data line

Dim RotAngle As Double
Dim Pi As Double
Pi = 4 * Atn(1)
RotAngle = LDRatio / (NCycles * Pi) 'calculate the rotation angle in radians
LineObj.Rotate Origin, RotAngle 'rotate line
LineObj.Update 'draws it on screen
LineObj.Mirror Origin, LineEnd 'mirror the line
LineObj.Update

 

'create arcs for data line

Dim ArcObj As AcadArc

Set ArcObj = ThisDrawing.ModelSpace.AddArc(Origin, (DataOD / 2), (Pi / 2 - RotAngle), (Pi / 2 + RotAngle))
ArcObj.Update
Set ArcObj = ThisDrawing.ModelSpace.AddArc(Origin, (DataID / 2), (Pi / 2 - RotAngle), (Pi / 2 + RotAngle))
ArcObj.Update

1 REPLY 1
Message 2 of 2
Anonymous
in reply to: Anonymous

I was able to solve the problem, it was easier to redraw the thing from scratch as a closed polyline.  In case it helps any one here is the code i ended up using:

 

'start declaring points
Dim DataObjPoi(0 To 14) As Double
DataObjPoi(0) = (DataID / 2) * Cos((LDRatio * Pi) / NCycles)
DataObjPoi(1) = (DataID / 2) * Sin((LDRatio * Pi) / NCycles)
DataObjPoi(2) = 0
DataObjPoi(3) = (DataID / 2) * Cos((-LDRatio * Pi) / NCycles)
DataObjPoi(4) = (DataID / 2) * Sin((-LDRatio * Pi) / NCycles)
DataObjPoi(5) = 0
DataObjPoi(6) = (DataOD / 2) * Cos((-LDRatio * Pi) / NCycles)
DataObjPoi(7) = (DataOD / 2) * Sin((-LDRatio * Pi) / NCycles)
DataObjPoi(8) = 0
DataObjPoi(9) = (DataOD / 2) * Cos((LDRatio * Pi) / NCycles)
DataObjPoi(10) = (DataOD / 2) * Sin((LDRatio * Pi) / NCycles)
DataObjPoi(11) = 0
DataObjPoi(12) = (DataID / 2) * Cos((LDRatio * Pi) / NCycles)
DataObjPoi(13) = (DataID / 2) * Sin((LDRatio * Pi) / NCycles)
DataObjPoi(14) = 0

Dim Bulge As Double 'calculate the bulge of the arcs
Bulge = Tan((LDRatio * Pi) / (2 * NCycles))
Dim DataObjPoly As AcadPolyline
Set DataObjPoly = ThisDrawing.ModelSpace.AddPolyline(DataObjPoi) 'create the polyline
DataObjPoly.SetBulge 0, -Bulge
DataObjPoly.SetBulge 2, Bulge
DataObjPoly.Closed = True
DataObjPoly.Layer = "DARK2"
DataObjPoly.Update

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost