While not advised, it is possible to get Civil 3D objects from an XREF. I’m not sure of the ramifications of modifying object after getting them in this manner, but one is able to read the Civil 3D object’s information. The code below goes and gets a variety of objects from an XREF and returns their ObjectIds. I even limit the returned values based on the layer they are on.
1: private static void FindObjectsInXREF(GraphNode root, string layerName, string xrefName, out List<ObjectId> polyObjIds)
2: {
3: polyObjIds = new List<ObjectId>();
4: for (int o = 0; o < root.NumOut; o++)
5: {
6: XrefGraphNode child = root.Out(o) as XrefGraphNode;
7: if (child.XrefStatus == XrefStatus.Resolved && child.Name == xrefName)
8: {
9: BlockTableRecord bl = child.BlockTableRecordId.GetObject(OpenMode.ForRead) as BlockTableRecord;
10: foreach (ObjectId objId in bl)
11: {
12: Autodesk.AutoCAD.DatabaseServices.Entity ent = objId.GetObject(OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Entity;
13: Type entType = ent.GetType();
14: if (ent.Layer == xrefName + "|" + layerName && (entType == typeof(Polyline) ||
15: entType == typeof(Polyline) ||
16: entType == typeof(Alignment) ||
17: entType == typeof(Polyline3d) ||
18: entType == typeof(Polyline2d)))
19: {
20: polyObjIds.Add(objId);
21: }
22: }
23: }
24: }
25: }
asdf
3 comments:
I've been trying to find a method to freeze civil 3d object layers by selection, through xrefs. I'm not sure I understand your description, and it appears much of the code is missing. Would you consider sending me the code?
I've been trying to find a method to freeze civil 3d object layers by selection, through xrefs. I'm not sure I understand your description, and it appears much of the code is missing. Would you consider sending me the code?
Or provide an example of this code in a full yet simple application.
Post a Comment