public static void getLineGroup() { // Get the TransactionManager TransactionManager tm = AcadApp.DocumentManager.MdiActiveDocument.Database.TransactionManager; // Get the AutoCAD editor Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor; // PromptEntityOptions pmtEntOpts = new PromptEntityOptions("Select a LineSegment: "); PromptEntityResult pmtEntRes = ed.GetEntity(pmtEntOpts); if (pmtEntRes.Status == PromptStatus.OK) { ObjectId entId = pmtEntRes.ObjectId; // 2.1 Use the using statement and start a transaction // Use the transactionManager created above (tm) // Note: Put the closing curly brace after step 2.14 using (Transaction tr = tm.StartTransaction()) { // 2.2 Declare a variable as a LineSegment. Instantiate // it by making it equal to the GetObject method of the transaction // from step 2.1. Cast it is a (LineSegment) and open it for read // use the ObjectId from above (entID) for the ObjectId parameter. LineSegment sline = (LineSegment)tm.GetObject(entId, OpenMode.ForRead); // 2.3 Test to see if the LineSegment from step 2.2 is null. If it // is null return. if (sline == null) { return; } // 2.4 Declare a variable as a LineStyle. Instantiate // it by making it equal to the GetOjbect method of the transaction // from step 2.1. Cast it is a (LineStyle). Use the StyleID property // of the LineSegment from step 2.2 and open it for read LineStyle linestyle = (LineStyle)tm.GetObject(sline.StyleID, OpenMode.ForRead, true); // 2.5 Create a string variable make it equal to this: // "\nLineStyle: " + // linestyle.Name; sMsg += "\n " + // linestyle.FlagType; sMsg += "\n " + // linestyle.GapPriority; sMsg += "\n " + // linestyle.ShowFlowDirection ; sMsg += "\n"; // Note: change "lineStyle" to the variable used in step 2.4 string sMsg = "\nLineStyle: " + linestyle.Name; sMsg += "\n " + linestyle.FlagType; sMsg += "\n " + linestyle.GapPriority; sMsg += "\n " + linestyle.ShowFlowDirection; sMsg += "\n"; // 2.6 Use the WriteMessage of the Editor declared above (ed) // to put the string from step 2.5 on the command line // pass in the string ed.WriteMessage(sMsg); // 2.7 Declare a variable as a LineGroupManager and get the line group id // and assign it to variable lineGroupId. LineGroupManager lineGroupMgr = new LineGroupManager(); int lineGroupId = lineGroupMgr.GroupId(entId); // 2.8 use the string variable from step 2.5, make it equal to this: // "\nLineGroup: " + lineGroupId.ToString() + " (" + type.ToString() + ")"; // Create the type variable first and assign it. GroupType type = lineGroupMgr.Type(lineGroupId); sMsg = "\nLineGroup: " + lineGroupId.ToString() + " (" + type.ToString() + ")"; // 2.9 Add to the string variable from step 2.8. (use +=) // add the string "\n LineSegments: " plus the Count property // of the LineSegments of the LineGroup from step 2.7 sMsg += "\n LineSegments: " + lineGroupMgr.Count(lineGroupId); // 2.10 Use the WriteMessage of the Editor declared above (ed) // to put the string from step 2.8 and 2.9 on the command line // pass in the string ed.WriteMessage(sMsg); // 2.11 use a foreach loop and iterate through the ObjectId of the // LineSegments of the LineGroup from step 2.7 (use the LineDbIds // property) // Note: Put the closing curly brace after step 2.14 foreach (ObjectId lsId in lineGroupMgr.LineDbIds(lineGroupId)) { // 2.12 Declare a LineSegment variable and instantiate it using // the transaction from step 1.4. Use the ObjectId from the // loop (step 2.11) Open it for read. LineSegment ls = (LineSegment)tm.GetObject(lsId, OpenMode.ForRead); // 2.13 make the string variable from step 2.5 equal to this string: // "\n LineSegment: " plus the ClassName property of the LineSegment // from step 2.12 plus this string " ,Vertices 0 - x,y,z " plus // the Vertices(0).ToString() sMsg = "\n LineSegment: " + ls.ClassName + " ,Vertices 0 - x,y,z " + ls.Vertices[0].ToString(); // 2.14 Use the WriteMessage of the Editor declared above (ed) // to put the string from steps 2.13 the command line // pass in the string ed.WriteMessage(sMsg); // Build and test the code. (run command "LineGroup", you should see // details about the Line Segments on the command line. // Continue to step 2.15 in the lineObjectsAndStylesAccess function } } } }
public static void getLineGroup() { // Get the TransactionManager TransactionManager tm = AcadApp.DocumentManager.MdiActiveDocument.Database.TransactionManager; // Get the AutoCAD editor Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor; // PromptEntityOptions pmtEntOpts = new PromptEntityOptions("Select a LineSegment: "); PromptEntityResult pmtEntRes = ed.GetEntity(pmtEntOpts); if (pmtEntRes.Status == PromptStatus.OK) { ObjectId entId = pmtEntRes.ObjectId; // 2.1 Use the using statement and start a transaction // Use the transactionManager created above (tm) // Note: Put the closing curly brace after step 2.14 using (Transaction tr = tm.StartTransaction()) { // 2.2 Declare a variable as a LineSegment. Instantiate // it by making it equal to the GetObject method of the transaction // from step 2.1. Cast it is a (LineSegment) and open it for read // use the ObjectId from above (entID) for the ObjectId parameter. LineSegment sline = (LineSegment)tm.GetObject(entId, OpenMode.ForRead); // 2.3 Test to see if the LineSegment from step 2.2 is null. If it // is null return. if (sline == null) return; // 2.4 Declare a variable as a LineStyle. Instantiate // it by making it equal to the GetOjbect method of the transaction // from step 2.1. Cast it is a (LineStyle). Use the StyleID property // of the LineSegment from step 2.2 and open it for read LineStyle linestyle = (LineStyle)tm.GetObject(sline.StyleID, OpenMode.ForRead, true); // 2.5 Create a string variable make it equal to this: // "\nLineStyle: " + // linestyle.Name; sMsg += "\n " + // linestyle.FlagType; sMsg += "\n " + // linestyle.GapPriority; sMsg += "\n " + // linestyle.ShowFlowDirection ; sMsg += "\n"; // Note: change "lineStyle" to the variable used in step 2.4 string sMsg = "\nLineStyle: " + linestyle.Name; sMsg += "\n " + linestyle.FlagType; sMsg += "\n " + linestyle.GapPriority; sMsg += "\n " + linestyle.ShowFlowDirection; sMsg += "\n"; // 2.6 Use the WriteMessage of the Editor declared above (ed) // to put the string from step 2.5 on the command line // pass in the string ed.WriteMessage(sMsg); // 2.7 Declare a variable as a LineGroupManager and get the line group id // and assign it to variable lineGroupId. LineGroupManager lineGroupMgr = new LineGroupManager(); int lineGroupId = lineGroupMgr.GroupId(entId); // 2.8 use the string variable from step 2.5, make it equal to this: // "\nLineGroup: " + lineGroupId.ToString() + " (" + type.ToString() + ")"; // Create the type variable first and assign it. GroupType type = lineGroupMgr.Type(lineGroupId); sMsg = "\nLineGroup: " + lineGroupId.ToString() + " (" + type.ToString() + ")"; // 2.9 Add to the string variable from step 2.8. (use +=) // add the string "\n LineSegments: " plus the Count property // of the LineSegments of the LineGroup from step 2.7 sMsg += "\n LineSegments: " + lineGroupMgr.Count(lineGroupId); // 2.10 Use the WriteMessage of the Editor declared above (ed) // to put the string from step 2.8 and 2.9 on the command line // pass in the string ed.WriteMessage(sMsg); // 2.11 use a foreach loop and iterate through the ObjectId of the // LineSegments of the LineGroup from step 2.7 (use the LineDbIds // property) // Note: Put the closing curly brace after step 2.14 foreach (ObjectId lsId in lineGroupMgr.LineDbIds(lineGroupId)) { // 2.12 Declare a LineSegment variable and instantiate it using // the transaction from step 1.4. Use the ObjectId from the // loop (step 2.11) Open it for read. LineSegment ls = (LineSegment)tm.GetObject(lsId, OpenMode.ForRead); // 2.13 make the string variable from step 2.5 equal to this string: // "\n LineSegment: " plus the ClassName property of the LineSegment // from step 2.12 plus this string " ,Vertices 0 - x,y,z " plus // the Vertices(0).ToString() sMsg = "\n LineSegment: " + ls.ClassName + " ,Vertices 0 - x,y,z " + ls.Vertices[0].ToString(); // 2.14 Use the WriteMessage of the Editor declared above (ed) // to put the string from steps 2.13 the command line // pass in the string ed.WriteMessage(sMsg); // Build and test the code. (run command "LineGroup", you should see // details about the Line Segments on the command line. // Continue to step 2.15 in the lineObjectsAndStylesAccess function } } } }