Getting coordinates of a selected PolyLine

Getting coordinates of a selected PolyLine

Anonymous
Not applicable
810 Views
6 Replies
Message 1 of 7

Getting coordinates of a selected PolyLine

Anonymous
Not applicable
Hi all

I have to get coordinates of a selected PolyLine by a SelectionSet.
I've already created a Selection set:

Set sset = ThisDrawing.SelectionSets.Add("SS_Preis_Poly")
sset.Select acSelectionSetPrevious

Now i only need the coordinates of the PolyLine... can someone help me?

Thanx!
Paul Blaszczyk
0 Likes
811 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable
Hi!Paul Blaszczyk,

I hope the following VB code would serve your purpose.

Iam assuming you are using A2000 and the you want to get coordinates of
LWpolyline.

bye,

P.Murali

'_________________________begin______________________
Private Sub f_getCoord()
Dim a_app As AcadApplication
Dim a_doc As AcadDocument

Dim po_ss As AcadSelectionSet
Dim po_ent As AcadEntity
Dim po_arr As Variant
Dim pi_i As Integer

Dim po_ftype(0) As Integer
Dim po_fdata(0) As Variant

Set a_app = GetObject(, "Autocad.Application.15")
Set a_doc = a_app.Documents(0)

'set the selection set
'I have taken clue from Frank Oquendo reply
Set po_ss = a_doc.SelectionSets("ss1")
If Err Then Set po_ss = a_doc.SelectionSets.Add("ss1")
po_ss.Clear

'set the filter
po_ftype(0) = 0
po_fdata(0) = "Lwpolyline"

'select on the screen
po_ss.SelectOnScreen po_ftype, po_fdata

Set po_ent = po_ss.Item(0)
po_arr = po_ent.Coordinates

'prints to immediate window
'note that you should pick the elements in pairs to get the coordinates
'i.e po_arr(0) and po_arr(1) will get you the first coordinates of the first
vertex
For pi_i = 0 To UBound(po_arr)
Debug.Print po_arr(pi_i)
Next

End Sub
'__________________end of sub_________________________

Paul Blaszczyk <3d@alpharay.de> wrote in message
<381DBD2E.DFE03C2C@alpharay.de>...
>Hi all
>
>I have to get coordinates of a selected PolyLine by a SelectionSet.
>I've already created a Selection set:
>
> Set sset = ThisDrawing.SelectionSets.Add("SS_Preis_Poly")
> sset.Select acSelectionSetPrevious
>
>Now i only need the coordinates of the PolyLine... can someone help me?
>
>Thanx!
> Paul Blaszczyk
>
0 Likes
Message 3 of 7

Anonymous
Not applicable
Murali P schrieb:

> Hi!Paul Blaszczyk,
>
> I hope the following VB code would serve your purpose.
>
> Iam assuming you are using A2000 and the you want to get coordinates of
> LWpolyline.
>
> bye,
>
> P.Murali

---------------------------------

It works fine!! Thanx! 🙂
Paul Blaszczyk
0 Likes
Message 4 of 7

Anonymous
Not applicable
I am having the same problem. It's a closed rectangle. When I try to get the
corners with :

dim boxmin (0 to 2) as double
dim boxmax (0 to 2) as double
...
mypline.getboundingbox boxmin, boxmax

I have plugged the line with mypline.delete just to make sure I have the
right entity, and it deletes it just fine. But all getboundingbox gets 0,0,0
for both corners. I had this program working in R14 but I'm having a lot of
trouble getting it to work in ACAD2K. I have painfully cobbled most of it
together but with this problem I can think of no where to turn. The program
seems perfectly happy with the 0s but if that's all I get I'm dead, and I'm
afraid I won't be able to reccommend that whe roll out the release to a
hundred users or whatever we have.

Is there a paper on all the changes that have made to this release of VBA
for AutoCAD?
0 Likes
Message 5 of 7

Anonymous
Not applicable
I am having the same problem as Paul. The polygon is a rectangle so I can
get everything I need from the boundingbox. This code blithely returns 0,0,0
and 0,0,0 as the two corners, which ofcourse, neither is. Help!!!

mode = acSelectionSetCrossing
gpCode(0) = 0
dataValue(0) = "LWPOLYLINE"

Dim groupCode As Variant, dataCode As Variant
groupCode = gpCode
dataCode = dataValue

Set ssetObj = ThisDrawing.SelectionSets.Add("SSET")
ssetObj.Select mode, Pt1, Pt2, groupCode, dataCode

Dim ent As AcadLWPolyline
Dim BoxMin(0 To 2) As Double
Dim BoxMax(0 To 2) As Double
Set ent = ssetObj.item(0)
'ent.Delete [when this is online and the line below is not,
indeed, the correct pline is deleted...]
ent.GetBoundingBox BoxMin, BoxMax

Is there a paper that lists all the changes to VBA in ACAD2K? Converting all
our AutoCAD VB and VBA code is turning out to be unexpectly vexing. This
problem is a great example. We want to upgrade our 50-100 users but...

Help!
Thanks

Paul Blaszczyk <3d@alpharay.de> wrote in message
news:381DBD2E.DFE03C2C@alpharay.de...
> Hi all
>
> I have to get coordinates of a selected PolyLine by a SelectionSet.
> I've already created a Selection set:
>
> Set sset = ThisDrawing.SelectionSets.Add("SS_Preis_Poly")
> sset.Select acSelectionSetPrevious
>
> Now i only need the coordinates of the PolyLine... can someone help me?
>
> Thanx!
> Paul Blaszczyk
>
0 Likes
Message 6 of 7

Anonymous
Not applicable
This is my code:

'---Selection set
Set poly_sset = ThisDrawing.SelectionSets.Add("SS_Price_Poly")
'Dim ftype(0) As Integer
Dim ftype(0) As Integer
Dim Fdata(0) As Variant

'---dxf code 0 = object type
ftype(0) = 0

'---filter for lwpolylines
Fdata(0) = "Lwpolyline"

'---get current selection
poly_sset.Select acSelectionSetPrevious, , , ftype, Fdata

'---is a polyline selected?
If poly_sset.Count <= 0 Then exit sub '---or put a error-msg here

'---if the user must select only one poly-line
If poly_sset.Count > 1 Then exit sub '---or errormsg "select only one
polyline"

Dim poly_ent As AcadEntity
Dim poly_coords As Variant '---or it is double?? variant
make no problems...
Set poly_ent = poly_sset.Item(0) '---if you are selecting more
than one polyline, you must create a loop and replace the (0) with a variable
poly_coords = poly_ent.Coordinates

'---numer of coords of poly
numer_of_points=ubound(poly_coords)-1 '---see NOTE !!

........

'---afert reading all the coordinates/polys delete the selection set---'
poly_sset.Clear
poly_sset.Delete
Set poly_sset = Nothing
End Sub
'---END---'

NOTE:
The last coordinate in he poly_coords() is the FIRST point of the poly-line!
(the position, at you begin drawin the polyline...and also the same as the first
point in the poly_coords() ).

I think, that this code is enought for you. 🙂

Bye
Paul Blaszczyk

My homepage: http://www.alpharay.de
-----------------------------------------------------------------------

Morgan Rauh wrotes:

> I am having the same problem as Paul. The polygon is a rectangle so I can
> get everything I need from the boundingbox. This code blithely returns 0,0,0
> and 0,0,0 as the two corners, which ofcourse, neither is. Help!!!
>
> mode = acSelectionSetCrossing
> gpCode(0) = 0
> dataValue(0) = "LWPOLYLINE"
>
> Dim groupCode As Variant, dataCode As Variant
> groupCode = gpCode
> dataCode = dataValue
>
> Set ssetObj = ThisDrawing.SelectionSets.Add("SSET")
> ssetObj.Select mode, Pt1, Pt2, groupCode, dataCode
>
> Dim ent As AcadLWPolyline
> Dim BoxMin(0 To 2) As Double
> Dim BoxMax(0 To 2) As Double
> Set ent = ssetObj.item(0)
> 'ent.Delete [when this is online and the line below is not,
> indeed, the correct pline is deleted...]
> ent.GetBoundingBox BoxMin, BoxMax
>
> Is there a paper that lists all the changes to VBA in ACAD2K? Converting all
> our AutoCAD VB and VBA code is turning out to be unexpectly vexing. This
> problem is a great example. We want to upgrade our 50-100 users but...
>
> Help!
> Thanks
0 Likes
Message 7 of 7

Anonymous
Not applicable
Hi Murali P!
Your code solved me too. Thanks!

Ps to all- Sorry about my duplicate posting. Config problems...

Murali P wrote in message
news:7vrcnm$4j59@adesknews2.autodesk.com...
> Hi!Paul Blaszczyk,
>
> I hope the following VB code would serve your purpose.
>
> Iam assuming you are using A2000 and the you want to get coordinates of
> LWpolyline.
>
> bye,
>
> P.Murali
>
> '_________________________begin______________________
> Private Sub f_getCoord()
> Dim a_app As AcadApplication
> Dim a_doc As AcadDocument
>
> Dim po_ss As AcadSelectionSet
> Dim po_ent As AcadEntity
> Dim po_arr As Variant
> Dim pi_i As Integer
>
> Dim po_ftype(0) As Integer
> Dim po_fdata(0) As Variant
>
> Set a_app = GetObject(, "Autocad.Application.15")
> Set a_doc = a_app.Documents(0)
>
> 'set the selection set
> 'I have taken clue from Frank Oquendo reply
> Set po_ss = a_doc.SelectionSets("ss1")
> If Err Then Set po_ss = a_doc.SelectionSets.Add("ss1")
> po_ss.Clear
>
> 'set the filter
> po_ftype(0) = 0
> po_fdata(0) = "Lwpolyline"
>
> 'select on the screen
> po_ss.SelectOnScreen po_ftype, po_fdata
>
> Set po_ent = po_ss.Item(0)
> po_arr = po_ent.Coordinates
>
> 'prints to immediate window
> 'note that you should pick the elements in pairs to get the coordinates
> 'i.e po_arr(0) and po_arr(1) will get you the first coordinates of the
first
> vertex
> For pi_i = 0 To UBound(po_arr)
> Debug.Print po_arr(pi_i)
> Next
>
> End Sub
> '__________________end of sub_________________________
>
> Paul Blaszczyk <3d@alpharay.de> wrote in message
> <381DBD2E.DFE03C2C@alpharay.de>...
> >Hi all
> >
> >I have to get coordinates of a selected PolyLine by a SelectionSet.
> >I've already created a Selection set:
> >
> > Set sset = ThisDrawing.SelectionSets.Add("SS_Preis_Poly")
> > sset.Select acSelectionSetPrevious
> >
> >Now i only need the coordinates of the PolyLine... can someone help me?
> >
> >Thanx!
> > Paul Blaszczyk
> >
>
>
0 Likes