Jump to content

Recommended Posts

Posted

i want to get the vertices from an already created .dxf file.

Posted

Do you intend to parse the text associated with a .dxf file without opening the file in AutoCAD?

Posted

I want to store it in an array so that i can modify.

Posted

I will not be near the office for the remainder of the day, so won’t be able to offer any coding suggestions until later tonight. I will ask a few questions to help clarify your situation, though.

 

Will the file be open in AutoCAD? What program language will you be using? Are all the polylines coplanar to the World Coordinate System, or is there some arbitrary orientation in space - or, better still, can you post a sample file that demonstrates the data?

Posted

I'm using The Autocad VBA for this purpose and using Autocad2007. assume i have file of a coplanar closed polygon(say a triangle) in space then i should be able to store the vertices data(x,y,z coordinates) in an array.

Posted

The Coordinates property (AcadLWPolyline.Coordinates) returns a 1 dimensional array. If a 2 dimensional array were needed (a logical requirement) then something like this might serve the purpose.

 

Edit: Code removed. See modified code in post #8

Posted

thanks a ton. it works. how did you do it? is there a general way you can find solutions?

Thanks again

Posted

It takes a bit of time with the ActiveX and VBA Reference to get accustom to the data structure of an AutoCAD file. The help documents are very good.

 

The For/Next loops have to be set up in accordance with the entiy's underlying data structure.

 

 

 

In the interest of completeness; here is a more generic routine that will analyze LWPolys at any orientation or elevation.

 

Sub StoreCoordsInArray3d()
Dim entPline As AcadLWPolyline
Dim varPt As Variant
Dim ent As AcadEntity
Dim coords As Variant
Dim dblPtArray() As Double
Dim intBound As Integer
Dim i As Integer
Dim strMsg As String
Dim varNormal As Variant
Dim dblElev As Double
Dim dblPt(2) As Double
Dim varTrans As Variant

  With ThisDrawing
     On Error Resume Next
     .Utility.GetEntity ent, varPt, "Select a Poly:"
     If Err <> 0 Then Exit Sub
     On Error GoTo 0
     If TypeOf ent Is AcadLWPolyline Then
        Set entPline = ent
        dblElev = entPline.Elevation
        varNormal = entPline.Normal
        coords = entPline.Coordinates
        intBound = ((UBound(coords) + 1) / 2) - 1
        ReDim dblPtArray(intBound, 2)
        For i = 0 To intBound
           dblPt(0) = coords(2 * i)
           dblPt(1) = coords((2 * i) + 1)
           dblPt(2) = dblElev
           varTrans = .Utility.TranslateCoordinates(dblPt, acOCS, acWorld, 0, varNormal)
           dblPtArray(i, 0) = varTrans(0)
           dblPtArray(i, 1) = varTrans(1)
           dblPtArray(i, 2) = varTrans(2)
           strMsg = strMsg & CStr(dblPtArray(i, 0)) & ", "
           strMsg = strMsg & CStr(dblPtArray(i, 1)) & ", "
           strMsg = strMsg & CStr(dblPtArray(i, 2)) & vbCr
        Next

        MsgBox strMsg
        
     End If
     
  End With
End Sub

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...