I've been writing AuoLISP code for several years, but I'm iun the process of migrating to the .NET API for my code in Civil 3D. I need to write a command that will create some custom text based on the properties of a pair of Civil 3D point objects. Is there any code examples that show how to filter a selection set for Civil 3D point objects and then access the properties of the selected points?
I'm just looking for some code that would get me started in the right direction.
Thanks.
Landon
Solved! Go to Solution.
Solved by Partha.Sarkar. Go to Solution.
Solved by Jeff_M. Go to Solution.
To get a selection set of CogoPoints:
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; PromptSelectionOptions prOpts = new PromptSelectionOptions();
prOpts.MessageForAdding = "\nSelect points: ";
prOpts.MessageForRemoval = "\nRemove points: ";
TypedValue[] filter = { new TypedValue(0, "AECC_COGO_POINT") };
SelectionFilter ssFilter = new SelectionFilter(filter);
PromptSelectionResult res = null; res = ed.GetSelection(prOpts, ssFilter);
Then loop through the selected objects, knowing they are all CogoPoint objects due to the filter used:
using (Transaction tr = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction()) { foreach (ObjectId id in res.GetObjectIds()) { CogoPoint pt = (CogoPoint)id.GetObject(OpenMode.ForRead); ed.WriteMessage("\nPoint Number: {0}, Elevation: {1}, Northing: {2}, Easting: {3}", pt.PointNumber.ToString(), pt.Elevation.ToString("F2"), pt.Northing.ToString("F2"), pt.Easting.ToString("F2")); } tr.Commit(); }
You can use SelectionFilter and TypedValue as mentioned by Jeff.
You can see relevant code snippet in ADN AutoCAD DevBlog and ADN IM DevBlog.
Thanks,
Thanks for the example code Jeff and the links Partha. Looks like that is just what I needed to get going.
Landon
Hi Jeff,
Thanks for your code snippet -- it helped me a lot.
However, I have a question regarding selecting other objects. You mention "AECC_COGO_POINT" for cogo points, and I found "CIRCLE" and "LINE" as well as valid arguments. What is its equivalent for other entities? Particularly, I am trying to have the user select Survey Figures, but I don't know what to use as the second argument of TypedValue. "AECC_SURVEY_FIGURE" does not do the trick.
Your help is gratefully appreciated.
I gave up on trying to find the correct name and use this instead:
RXClass.GetClass(typeof(FeatureLabel)).DxfName
this should return the name you seek.
Good evening,
I copied your code into my program and it works great for the selection part. For the iteration through the selection set I am having Visual Studio 2017 showing an error.
Apparently
PromptSelectionResult
does not contain a definition for
GetObjectIds
thus the line
foreach (ObjectId id in res.GetObjectIds())
Gives an error. What am I missing?
Thank you.