.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Selection of Nested Entities

6 REPLIES 6
Reply
Message 1 of 7
Anonymous
1080 Views, 6 Replies

Selection of Nested Entities

I want to select nested entities (primarily in Xrefs) and then view the selected objects layers. My code works, however it doesn't select every nested entity that i select. if i select by picking an actual entity it adds it, if i select by crossing window (over part of, or an entire block for example) it only selects some or one of the nested entities. Perhaps my understanding of the PromptSelectionOptions.PrepareOptionalDetails property is lacking.

thanks for the help
-Mark Pendergraft

'/////// begin code ////////'
Public Sub GetSubEntities()

Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor

Dim ss As SelectionSet
Dim prmptSSopt As New PromptSelectionOptions()
prmptSSopt.PrepareOptionalDetails = True
prmptSSopt.RejectObjectsOnLockedLayers = False
prmptSSopt.MessageForAdding = "Select objects: "

Dim ssRes As PromptSelectionResult = ed.GetSelection(prmptSSopt)

If Not ssRes.Status = PromptStatus.OK Then Exit Sub
ss = ssRes.Value

Dim objIds() As ObjectId = ss.GetObjectIds()

ed.WriteMessage(vbCrLf + vbCrLf + "Selected Layers: ")
Dim ent As Entity = Nothing
Using trans As Transaction = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction()

For Each objId As ObjectId In objIds
ent = trans.GetObject(objId, OpenMode.ForRead, False, True)
ed.WriteMessage(vbCrLf + ent.Layer.ToString)
Next
End Using


End Sub
6 REPLIES 6
Message 2 of 7
Anonymous
in reply to: Anonymous

You are getting what you are asking for.

If you want to get at nested entities you need to do what is called recursive programming.

take what you have in bold and encapsulate into a function.
when you get your ent declare determine if is a block reference, if so call this function again.

Does this make sense?

pat
Message 3 of 7
Anonymous
in reply to: Anonymous

No, that doesn't make sense.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5859411@discussion.autodesk.com...
You are getting what you are asking for.

If you want to get at nested entities you need to do what is called recursive programming.

take what you have in bold and encapsulate into a function.
when you get your ent declare determine if is a block reference, if so call this function again.

Does this make sense?

pat
Message 4 of 7
Anonymous
in reply to: Anonymous

If you set AllowSubSelections to true, you will get nested entities, but only one nested entity per crossing/window selection will be found, and which of several objects in the crossing box is actually selected is not predictable, so you really can't rely on crossing for selecting nested entities.

Selecting multiple nested objects requires that you select them by picking each one individually.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5859216@discussion.autodesk.com...
I want to select nested entities (primarily in Xrefs) and then view the selected objects layers. My code works, however it doesn't select every nested entity that i select. if i select by picking an actual entity it adds it, if i select by crossing window (over part of, or an entire block for example) it only selects some or one of the nested entities. Perhaps my understanding of the PromptSelectionOptions.PrepareOptionalDetails property is lacking.

thanks for the help
-Mark Pendergraft

'/////// begin code ////////'
Public Sub GetSubEntities()

Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor

Dim ss As SelectionSet
Dim prmptSSopt As New PromptSelectionOptions()
prmptSSopt.PrepareOptionalDetails = True
prmptSSopt.RejectObjectsOnLockedLayers = False
prmptSSopt.MessageForAdding = "Select objects: "

Dim ssRes As PromptSelectionResult = ed.GetSelection(prmptSSopt)

If Not ssRes.Status = PromptStatus.OK Then Exit Sub
ss = ssRes.Value

Dim objIds() As ObjectId = ss.GetObjectIds()

ed.WriteMessage(vbCrLf + vbCrLf + "Selected Layers: ")
Dim ent As Entity = Nothing
Using trans As Transaction = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction()

For Each objId As ObjectId In objIds
ent = trans.GetObject(objId, OpenMode.ForRead, False, True)
ed.WriteMessage(vbCrLf + ent.Layer.ToString)
Next
End Using


End Sub
Message 5 of 7
Anonymous
in reply to: Anonymous

If you think the only way to get nested entities is to select them one at a time - well i could not disagree with more.

pat
Message 6 of 7
Anonymous
in reply to: Anonymous

It's the only way to do it using standard object selection (e.g., the GetSelection() method and PromptSelectionOptions ), which is what the OP is trying to use.

If you don't agree, feel free to provide some substance supporting your opinion.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5859676@discussion.autodesk.com...
If you think the only way to get nested entities is to select them one at a time - well i could not disagree with more.

pat
Message 7 of 7
Anonymous
in reply to: Anonymous

Thanks Tony,
The documentation wasn't quite specific enough about the :N option of the AcEdSSGet function. it only says "The additional information will only be available for entities selected via graphical selection methods such as window, crossing, point pick, etc."

I suppose i will just write a program which will use a typical selection set, with a keyword to use the editor's getnestedentity method.

-Mark Pendergraft

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost