.NET

.NET

Reply
Valued Contributor
dynamicscope
Posts: 95
Registered: ‎04-04-2012
Message 1 of 3 (276 Views)
Accepted Solution

How to get the ObjectIdCollection of all entities in a certain layer?

276 Views, 2 Replies
05-22-2012 07:34 PM

How could I get the ObjectIdCollection of all entities (points, polyline) in a certain layer?

I am using the following code at this moment.

 

private ObjectIdCollection GetEntitiesOnLayer(string layerName)

        {

            Editor ed = doc.Editor;

            TypedValue[] tvs = new TypedValue[1] { new TypedValue((int)DxfCode.LayerName, layerName) };

            SelectionFilter sf = new SelectionFilter(tvs);

            PromptSelectionResult psr = ed.SelectAll(sf);

 

            if (psr.Status == PromptStatus.OK)

                return new ObjectIdCollection(psr.Value.GetObjectIds());

            else

                return new ObjectIdCollection();

        }

 

But it seems the function fetches more ObjectId than I expected.

For example, if I draw 3 points and 2 polylines in "A" layer.

 

ObjectIdCollection obc = GetEntitiesOnLayer("A");

int i = obc.Count;

 

I was expecting i to be 5 (3 points and 2 polylines), but i seems to be more than 5.

 

Any thought?


Your code is working good on my end

Maybe you need to add filter on entities in

the current layout, just a guess, e.g:

 

TypedValue [] tvs = newTypedValue[2] { newTypedValue((int)DxfCode.LayerName, layerName),

newTypedValue((int)DxfCode.LayoutName, "Model") };

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 2 of 3 (270 Views)

Re: How to get the ObjectIdCollection of all entities in a certain layer?

05-22-2012 09:54 PM in reply to: dynamicscope

Your code is working good on my end

Maybe you need to add filter on entities in

the current layout, just a guess, e.g:

 

TypedValue [] tvs = newTypedValue[2] { newTypedValue((int)DxfCode.LayerName, layerName),

newTypedValue((int)DxfCode.LayoutName, "Model") };

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
*Expert Elite*
chiefbraincloud
Posts: 753
Registered: ‎02-13-2008
Message 3 of 3 (249 Views)

Re: How to get the ObjectIdCollection of all entities in a certain layer?

05-23-2012 08:59 AM in reply to: dynamicscope

That would be my guess as well.  SelectAll will return entities that are not in the current space, but otherwise your code should be fine, and I've never had a simple selection filter give me entities that did not meet the criteria.

Dave O.                                                                  Sig-Logos32.png
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.