Extracting Polyline Coordinates Problem

Extracting Polyline Coordinates Problem

alexisgacia
Advocate Advocate
6,487 Views
9 Replies
Message 1 of 10

Extracting Polyline Coordinates Problem

alexisgacia
Advocate
Advocate

Hello Guys,

 

Good day.

 

I'm having problem in the extraction of coordinates of Polyline. When I try to compare the extracted coordinates in VBA and the List command in AutoCAD they are both different value.

 

Sample value below:

alexisgacia_0-1588080100236.png

 

Code that I use to extract:

dim pp as variant
dim oEnt as acadentity
dim oPL as acadlwPolyline

ThisDrawing.Utility.GetEntity oEnt, pp, vbCrLf & "Select Polyline: "

set oPL = oEnt
mCoord = oPL.Coordinates

 

Thank you in advance.

 

Best regards,

 

Alex

0 Likes
Accepted solutions (2)
6,488 Views
9 Replies
Replies (9)
Message 2 of 10

Ed__Jobe
Mentor
Mentor

They have the same values, just that the vba version is in the form of an array. To get x,y pairs from the array, you need to extract 2 indexed values at a time. For example, vertex 1 of the polyline is mcoord(0), mcoord(1). The only difference in values is that vba is showing the full number and the list command is truncating it according to the UNITS command.

 

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 3 of 10

norman.yuan
Mentor
Mentor

In addition to what @Ed__Jobe has said, the difference you referred to, maybe, is the fact that the vertices' X value, being positive in VBA and being negative in List Command.

 

The LIST command's text window CLEARLY shows that the "Extrusion direction relative to UCS: ... Z=-1.000". That means the UCS's Z direction is away from user on XY plane, while the VBA code's numbers are always based on World CS, which has its Z direction toward user on XY plane, thus the different (positive/negative) X value.

Norman Yuan

Drive CAD With Code

EESignature

Message 4 of 10

alexisgacia
Advocate
Advocate

Sorry I didn't get it. Is there any way that I can get a similar value? Do I need a certain computation to do before I get the proper value? Some objects are properly extracted with an equal coordinates. But some few object are not equal due to the negative sign. But when I try to use flatten command it gives a proper coordinates but it losses some of the data of the objects such as elevation.

0 Likes
Message 5 of 10

alexisgacia
Advocate
Advocate

Is there a better way to extract the coordinates? Even the object was created in a different UCS settings?

 

Thanks in advance.

0 Likes
Message 6 of 10

Ed__Jobe
Mentor
Mentor

Perhaps you should just explain what you're trying to do. The FLATTEN command is working properly. That's how is works, by moving all the z coordinates to 0. Naturally, you will "lose data".

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 7 of 10

alexisgacia
Advocate
Advocate

 

What I'm planning to do is to get the coordinates, then base from the coordinate that I extracted I will add another vertices and create another object base on the vertices. Then when I try create, it will not create on the exact location, it will create far from the object reference.

Still not able to find the solution for this one.

 

0 Likes
Message 8 of 10

Ed__Jobe
Mentor
Mentor
Accepted solution

That description doesn't have anything to do with FLATTEN as you previously mentioned. What criteria are you using to alter the coordinates of the polyline? You can also post the code you are using?

As to the problem of being far away, the help for the Coordinates property states: Polyline object: The variant is an array of 3D points: the X and Y coordinates are in OCS; the Z coordinate is ignored.

Note that the coordinates are in OCS. If your new points are in WCS, that would explain it. You would need to transform the coords to the correct system. There is also an example of how to create a polyline and modify a vertex.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 9 of 10

alexisgacia
Advocate
Advocate
Accepted solution

It works using Translate Coordinates. Thank you 

    '' testing coordinates created with UCS
    Dim oEnt As AcadEntity
    Dim oPL As AcadLWPolyline
    Set oEnt = SelectSingleItem()
    If (TypeOf oEnt Is AcadLWPolyline) Then
        Set oPL = oEnt
        Dim v As Variant
        Dim v1(2) As Double
        
        v = oPL.Coordinates
        
         
        ReDim newCoord(UBound(v)) As Double
        Dim plineNormal As Variant
        Dim coordinateWCS As Variant
        For x = LBound(v) To UBound(v) Step 2
            v1(0) = v(x)
            v1(1) = v(x + 1)
            v1(2) = oPL.Elevation
                        
            plineNormal = oPL.Normal
                        
            coordinateWCS = ThisDrawing.Utility.TranslateCoordinates(v1, acOCS, acWorld, False, plineNormal)
            
            newCoord(x) = coordinateWCS(0)
            newCoord(x + 1) = coordinateWCS(1)
        Next
        Dim oPL1 As AcadLWPolyline
        Set oPL1 = ThisDrawing.ModelSpace.AddLightWeightPolyline(newCoord)
        oPL1.Elevation = coordinateWCS(2)
        oPL1.Layer = "0"
        
        ThisDrawing.ModelSpace.AddCircle coordinateWCS, 0.5
    End If

 

0 Likes
Message 10 of 10

lachezarzhekov03
Observer
Observer

you can use the user to pick point and you know how to create the objects you need just use the picked point as starting poing and do the calculation from there.

0 Likes