ObjectARX

Reply
Valued Contributor
kcimos
Posts: 80
Registered: ‎02-18-2010
Message 1 of 10 (1,372 Views)
Accepted Solution

selection set entities, specifically polylines & 3d polylines

1372 Views, 9 Replies
12-26-2011 04:45 PM

new to VB.net, been using VBA for about 10 years. I have a VBA routine that I'm trying to covert to VB.net / objectARX, with some minor funcational refinments. I'd like the user to select polylines and/or 3d polylines & then my routine will do its things to these items that are in a selection set.

 

Things are working OK up to where I set my ENTITY type variable from the objectID conversion of the ads name of an item in the selection set.

 

I need to process the coordinates. I have tried various CAST implementations but none work. Can't cast

Autodesk.AutoCAD.DatabaseServices.Polyline to entity or acadentity or acadpolyline.

So how do I get the coordinates of a polyline (or a 3d polyline)?

 

 

*Expert Elite*
Alfred.NESWADBA
Posts: 8,866
Registered: ‎06-29-2007
Message 2 of 10 (1,361 Views)

Re: selection set entities, specifically polylines & 3d polylines

12-26-2011 07:17 PM in reply to: kcimos

Hi,

 

can you show a little bit of code, it's quite difficult to find a mistake someone did without seeing what he/she did. :smileywink:

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Valued Contributor
kcimos
Posts: 80
Registered: ‎02-18-2010
Message 3 of 10 (1,358 Views)

Re: selection set entities, specifically polylines & 3d polylines

12-26-2011 08:09 PM in reply to: Alfred.NESWADBA

Since I posted my question have have experimented more & after further investigation,it looks like I'm going to have to use the getpoint3dat method of the Autodesk.AutoCAD.DatabaseServices.Polyline which is the kind of thing I was trying to avoid, since I already have it all worked out in VBA, and was hoping to have to rewrite the whole thing. It looks like there is no way to get an ACADPOLYLINE object out of the GETSELECTION method of the editor.

 

here is the incomplete code for the begining of my routine, hopefully ffrom this you can tell what is happening, if not I guess I'll post the whole thing. FYI, ACF is a class module with various autocad input functions & containers for objects

 

Keep in mind I've been experimenting with different things to see what might work

   

Dim objObj AsObject

'Dim PLObj As AcadLWPolyline

'Dim Plobj As AcadPolyline

Dim PlObj As Autodesk.AutoCAD.DatabaseServices.Polyline

 

 

PublicSub vbREPL()

       

Dim entEntity AsAcadEntity  

Dim ent AsEntity    

Dim i AsInteger    

Dim J AsInteger   

Dim idArray AsObjectId() 

Dim TransMan As Autodesk.AutoCAD.DatabaseServices.TransactionManager   

Dim psResult AsPromptSelectionResult     

Dim tXaction AsTransaction   

Dim idId As ObjectId      

Dim entity As Entity



 InitializeREPL()   'sets strPrompt & DefaultSegments

       

If ACF.SsGetLwPlinesOr3dPolylines() = TrueThen        'continue

           

     If ACF.GetIntFromUser(strPrompt, DefaultSegments) = TrueThen

                X =ACF.iResult

           

     Else

               

        Exit Sub

           

     EndIf

 

            idArray =ACF.ssResult.GetObjectIds()

            TransMan =ACF.Db.TransactionManager          'start a transaction

            tXaction = TransMan.StartTransaction()

           

Try

               

ForEach Id In idArray

                    objObj = TransMan.GetObject(Id, OpenMode.ForRead, True)

                    ent = CType(objObj, Autodesk.AutoCAD.DatabaseServices.Entity)

                                  

' If ent.ObjectName = "AcDbPolyline" Then

                   

'If ent.GetType().FullName = "AcDbPolyline" Then

                   

                  If ent.GetType().FullName = "Autodesk.AutoCAD.DatabaseServices.Polyline"Then

                       

                  'entEntity = CType(ent, AcadEntity)

                                               Plobj = ent

                       

' PLObj = Entry

                        varOrigPLpts = PlObj.Coordinates

                        PLStPT(0) = varOrigPLpts(0)

                        PLStPT(1) = varOrigPLpts(1)

                        PLEndPT(0) = varOrigPLpts(UBound(varOrigPLpts) - 1)

                        PLEndPT(1) = varOrigPLpts(UBound(varOrigPLpts))

                        OrigPLptCount = -2

                        OrigElev = Plobj.Elevation

                        varPolyElms = Plobj.Explode

ADN Support Specialist
Balaji_Ram
Posts: 660
Registered: ‎03-21-2011
Message 4 of 10 (1,356 Views)

Re: selection set entities, specifically polylines & 3d polylines

12-26-2011 09:17 PM in reply to: kcimos

Hi,

 

Can you try this ?

 

Polyline pl = Tx.GetObject(oid, OpenMode.ForWrite) asPolyline;

 

AcadLWPolyline acadPl = pl.AcadObject asAcadLWPolyline;



Balaji
Developer Technical Services
Autodesk Developer Network

ADN Support Specialist
Balaji_Ram
Posts: 660
Registered: ‎03-21-2011
Message 5 of 10 (1,356 Views)

Re: selection set entities, specifically polylines & 3d polylines

12-26-2011 09:23 PM in reply to: Balaji_Ram

Just thought of posting the whole code that I have been using which works ok :

 

<CommandMethod("Test")> _
Public Sub TestMethod()
	Dim activeDoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
	Dim ed As Editor = activeDoc.Editor
	Dim db As Database = HostApplicationServices.WorkingDatabase

	Dim pso As New PromptSelectionOptions()
	Dim psr As PromptSelectionResult = ed.GetSelection(pso)
	If psr.Status <> PromptStatus.OK Then
		Return
	End If

	Using Tx As Transaction = db.TransactionManager.StartTransaction()
		Dim entitites As New ObjectIdCollection(psr.Value.GetObjectIds())
		For Each oid As ObjectId In entitites
			If oid.ObjectClass.Name.Equals("AcDbPolyline") Then
				Dim pl As Polyline = TryCast(Tx.GetObject(oid, OpenMode.ForWrite), Polyline)
				Dim acadPl As AcadLWPolyline = TryCast(pl.AcadObject, AcadLWPolyline)
				Dim isClosed As Boolean = acadPl.Closed
			End If
		Next
		Tx.Commit()
	End Using
End Sub

 



Balaji
Developer Technical Services
Autodesk Developer Network

*Expert Elite*
Alfred.NESWADBA
Posts: 8,866
Registered: ‎06-29-2007
Message 6 of 10 (1,347 Views)

Re: selection set entities, specifically polylines & 3d polylines

12-26-2011 11:30 PM in reply to: kcimos

Hi,

 

to reproduce what happens to your code we see now what you are doing with objects in your selectionset, but you don't show how you do select objects (and how you set your filtering mechanism for building the selection):

So what happens within "InitializeREPL" and "ACF.SsGetLwPlinesOr3dPolylines"?

 

>> It looks like there is no way to get an ACADPOLYLINE object out of the GETSELECTION method of the editor.

Of course, there are methods to get them. One option is to select all objects the user selects and while scanning through the objects within the selectionset.This is what Balaji showed in his second sample.

 

The other option is to define a filter before the user gets asked for selecting entities, define objecttypes to which the selection should get filtered .... and AutoCAD will select only entities that matches the filtering even if the user clicks other object types (they will not be highlighed during "Select Objects: ").

You can see a sample for filtering >>>here<<<, just change:

   New DatabaseServices.TypedValue(DatabaseServices.DxfCode.Start, "POINT")

to:

   New DatabaseServices.TypedValue(DatabaseServices.DxfCode.Start, "*POLYLINE*")

to get all types of Polyline selected, or change it to:

   New DatabaseServices.TypedValue(DatabaseServices.DxfCode.Start, "LWPOLYLINE,3DPOLYLINE")

to select only objects of type LWPolyline or 3DPolyline.

 

HTH, - alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Valued Contributor
kcimos
Posts: 80
Registered: ‎02-18-2010
Message 7 of 10 (1,333 Views)

Re: selection set entities, specifically polylines & 3d polylines

12-27-2011 03:33 PM in reply to: Balaji_Ram

Balaji,

that worked.

thanks much

Valued Contributor
kcimos
Posts: 80
Registered: ‎02-18-2010
Message 8 of 10 (1,333 Views)

Re: selection set entities, specifically polylines & 3d polylines

12-27-2011 03:35 PM in reply to: kcimos

specifically:

 

If oid.ObjectClass.Name.Equals("AcDbPolyline") Then

 

Dim pl As Polyline = TryCast(Tx.GetObject(oid, OpenMode.ForWrite), Polyline)

Dim acadPl As AcadLWPolyline = TryCast(pl.AcadObject, AcadLWPolyline)

 

End If

Valued Contributor
kcimos
Posts: 80
Registered: ‎02-18-2010
Message 9 of 10 (1,328 Views)

Re: selection set entities, specifically polylines & 3d polylines

12-27-2011 08:06 PM in reply to: kcimos

ok, onto the next problem:

attached are 2 classes. classACF contains general autocad interaction stuff, including one I'm having problems with called addlwpolyline.

classREPL cantains the main procedure I'm working on. Again, I'm converting a working VBA routine to VB.net & trying to keep as much of the original as possible.

classREPL references classACF.

REPL creates a new polyline(s) based on the one(s) selected, adding vertices based on how many the user wants. The new polyline only has straight segments.

 

There is also a command called TESTADDPL defined in classACF. This calls the addlwpoly sub & it works.

 

if I select the polyline created from that within REPL ( as a simple test) a new polyline is not drawn,the vertices check out as I'd except, but no new geometry on screen. Of course I tried polylines that I drew in autocad before running the REPL command, with the same result.

 

I get no errors.

 

do I have too many transactions open?

should the transaction at the end of REPL DISPOSE? (tX.Dispose())

is the problem the fact that there already is a polyline occupying that space? (shouldn't be)

I'm I not calling some addition database and/or blockrecordtable methods to get the new polylilne to appear?

 

 

 

 

Valued Contributor
kcimos
Posts: 80
Registered: ‎02-18-2010
Message 10 of 10 (1,321 Views)

Re: selection set entities, specifically polylines & 3d polylines

12-28-2011 06:49 AM in reply to: kcimos

OK, I figured it out. the transaction DSIPOSE  w/in the REPL procedure had to be moved so that transaction ends before the call to the addlwpolyline sub with has its own transaction begin & end.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community