Convert objects

Convert objects

Anonymous
Not applicable
704 Views
13 Replies
Message 1 of 14

Convert objects

Anonymous
Not applicable
Hi all,

I've got a converting problem, please, help me!

So, I'd like to select on the screen only one object, a polyline. To this I use the GetEntity methods. But at first I haven't already known what object is this therefore I write it an entity object to test it. And later if the entity is polyline I'd like to write it to a polyline object.

But this doesn't run. Have anybody a good idea?

Greg
0 Likes
705 Views
13 Replies
Replies (13)
Message 2 of 14

Anonymous
Not applicable
For starters, show the code you try to run.

wrote in message news:5495169@discussion.autodesk.com...
Hi all,

I've got a converting problem, please, help me!

So, I'd like to select on the screen only one object, a polyline. To this I
use the GetEntity methods. But at first I haven't already known what object
is this therefore I write it an entity object to test it. And later if the
entity is polyline I'd like to write it to a polyline object.

But this doesn't run. Have anybody a good idea?

Greg
0 Likes
Message 3 of 14

arcticad
Advisor
Advisor
If you select an object you can use the typeof to determine what it. Then If what you want is compatable, you can create a new entity from the old data.

Your question was unclear.
---------------------------



(defun botsbuildbots() (botsbuildbots))
0 Likes
Message 4 of 14

Anonymous
Not applicable
Hi articad,

ok, once more. I'd like to select a polyline on the screen, only one polyline. But I wouldn't like if the user selects more object. So I'd use a "GetPolyline" methode but this methode doesn't exist. What can I do? I think I can use GetEntity methode. But in this case I can't use the entity object such as a polyline therefore I need to convert it.

Or have you other solution?

Greg
0 Likes
Message 5 of 14

Anonymous
Not applicable
Hi Jeff,

Sub sGetPolyline()
Dim aEntity as AcadEntity
Dim aPolyline as AcadPolyline
dim vPP As Variant

ThisDrawing.Utility.GetEntity aEntity, vPP, ""

If not (Right(aEntity,8) like "Polyline") then
MsgBox "It isn't polyline.", vbCritical, "ERROR !!!"
Exit Sub
End if

Set aPolyline = aEntity

.... 'other operations with aPolyline

End Sub
0 Likes
Message 6 of 14

Anonymous
Not applicable
Hi Greg,

You are right, with GetEntity you can't pre-determine what to select.

So you need to select an object then check if it is the type of object you
want.

Polylines are a pest as there are two types of polyline which look the same,
but are different programmatically.

You need code like the following pseudo code:

Object = GetEntity
if typeof Object is Polyline then
do your thing to a polyline
elseif typeof Object is Lightweightpolyline
do your thing to a Lightweightpolyline
else
if msgbox ("selected object was not a polyline do you want to try to
select again? ", vbYesNo) = vbYes then Start selection again
end if

If you create a Selection set then you can filter what gets selected in vast
detail, but you can't control the number selected.

We certainly need Autodesk to provide a filter for GetEntity.

--

Laurie Comerford
CADApps
www.cadapps.com.au
www.civil3Dtools.com
wrote in message news:5495477@discussion.autodesk.com...
Hi articad,

ok, once more. I'd like to select a polyline on the screen, only one
polyline. But I wouldn't like if the user selects more object. So I'd use a
"GetPolyline" methode but this methode doesn't exist. What can I do? I think
I can use GetEntity methode. But in this case I can't use the entity object
such as a polyline therefore I need to convert it.

Or have you other solution?

Greg
0 Likes
Message 7 of 14

Anonymous
Not applicable
Ola Laurie,

Thanks very much. I think that it is a big problem but I hoped somebody knows a good solution. I am sorry to hear that doesn't exist a really good solution. But...

At first I thought that I use the GetEntity - so it's created an AcadEntity object - and than I check it. And if it's right than I convert it to an AcadPolyline/AcadLWPolyline object. But it didn't run...

Later I thought that I use the SelectOnScreen method of a SelectionSet object. (Now I'm using it.) And I check what are in this. But in this SelectionSet object I can use the items as AcadEntity object. Why?

Greg
0 Likes
Message 8 of 14

Anonymous
Not applicable
Try using an error handler. Something like this:

Sub sGetPolyline()

Dim aPolyline As AcadPolyline
Dim aLWPolyline As AcadLWPolyline
Dim vPP As Variant

On Error GoTo NotLWPolyline
ThisDrawing.Utility.GetEntity aLWPolyline, vPP, "Select a polyline: "

MsgBox "Do other operations with aLWPolyline"

End
NotLWPolyline:
On Error GoTo NotPolyline
ThisDrawing.Utility.GetEntity aPolyline, vPP, "Select a polyline: "

MsgBox "Do other operations with aPolyline"

End
NotPolyline:

MsgBox "Object is not a polyline!", vbExclamation, "You Idiot!"

End Sub


I didnt have time to sort it out properly, so it will want some more work on it.

Hope this helps

RaNDoM Message was edited by: RaNDoM
0 Likes
Message 9 of 14

Anonymous
Not applicable
Try this - Add to the handler to resolve missed picks.
[code]
Sub foo()
Dim pl As AcadLWPolyline
Dim pp

On Error GoTo fooHandler

ThisDrawing.Utility.GetEntity pl, pp

fooExit:
On Error GoTo 0
Exit Sub

fooHandler:
Select Case Err.Number
Case 13
Err.Clear
ThisDrawing.Utility.Prompt "Not a LWPoly pick again: "
Resume
Case Else
Err.Clear
Resume fooExit
End Select
End Sub
[/code]
wrote in message news:5495480@discussion.autodesk.com...
Hi Jeff,

Sub sGetPolyline()
Dim aEntity as AcadEntity
Dim aPolyline as AcadPolyline
dim vPP As Variant

ThisDrawing.Utility.GetEntity aEntity, vPP, ""

If not (Right(aEntity,8) like "Polyline") then
MsgBox "It isn't polyline.", vbCritical, "ERROR !!!"
Exit Sub
End if

Set aPolyline = aEntity

.... 'other operations with aPolyline

End Sub
0 Likes
Message 10 of 14

Anonymous
Not applicable
Ola Paul,

thanks, but my problem is a little more sophisticated: on the draw there are 3D-polylines and 2D-polylines and when I select I haven't know yet what type of polyline I'm selecting.

Therefore I'd like to select an AcadEntity object and later I'd convert to form of the good polyline. Or if I would asked the index in the modelspace than I can select it programatically.

Greg
0 Likes
Message 11 of 14

Anonymous
Not applicable
Hi RaNDoM,

Thanks very much! Your code is better then my code, but it isn't really good. Imegine it:

1. I select a polyline object.
2.a If it is LWPolyline than everything is OK
2.b If it isn't LWPolyline than I need to select again

I!d like to select only one time.

Greg
0 Likes
Message 12 of 14

Anonymous
Not applicable
Here is what the others have suggested you do...
[code]
Sub foo()
Dim ent As AcadEntity
Dim pp

On Error GoTo fooHandler

pickagain:
ThisDrawing.Utility.GetEntity ent, pp

If TypeOf ent Is AcadLWPolyline Then
Dim pl As AcadLWPolyline
Set pl = ent
ElseIf TypeOf ent Is Acad3DPolyline Then
Dim pl3 As Acad3DPolyline
Set pl3 = ent
Else
ThisDrawing.Utility.Prompt "Pick a polyline: "
GoTo pickagain
End If

fooExit:
On Error GoTo 0
Exit Sub

fooHandler:
Select Case Err.Number
Case -2147352567
Err.Clear
ThisDrawing.Utility.Prompt "Missed pick again: "
Resume
Case Else
Err.Clear
Resume fooExit
End Select
End Sub
[/code]
wrote in message news:5497498@discussion.autodesk.com...
Ola Paul,

thanks, but my problem is a little more sophisticated: on the draw there are
3D-polylines and 2D-polylines and when I select I haven't know yet what type
of polyline I'm selecting.

Therefore I'd like to select an AcadEntity object and later I'd convert to
form of the good polyline. Or if I would asked the index in the modelspace
than I can select it programatically.

Greg
0 Likes
Message 13 of 14

Anonymous
Not applicable
Hi Paul,

Thanks, I think, this is the best solution. 🙂

Greg
0 Likes
Message 14 of 14

Anonymous
Not applicable
I didnt know how to solve this one, but i just learnt "TypeOf" and thought i'd let you know:

Sub sGetPolyline()

Dim aEntity As AcadEntity
Dim aPolyline As AcadPolyline
Dim aLWPolyline As AcadLWPolyline
Dim vPP As Variant

ThisDrawing.Utility.GetEntity aEntity, vPP, "Select a polyline: "

If TypeOf aEntity Is AcadLWPolyline Then
Set aLWPolyline = aEntity
MsgBox "Do other operations with aLWPolyline"
Else
If TypeOf aEntity Is AcadPolyline Then
Set aPolyline = aEntity
MsgBox "Do other operations with aPolyline"
Else
MsgBox "Object is not a polyline!", vbExclamation, "You Idiot!"
End If
End If

End Sub
0 Likes