public static ObjectId[] GetObjectIDs(string dxfName, string layerName) { Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; if (layerName == null || layerName == "") { layerName = "*"; } TypedValue[] array = new TypedValue[0]; array = new TypedValue[] { new TypedValue(-4, "<or"), new TypedValue(-4, "<and"), new TypedValue((int)DxfCode.LayerName, layerName), new TypedValue((int)DxfCode.Start, dxfName), new TypedValue(-4, "and>"), new TypedValue(-4, "or>") }; PromptSelectionResult selection = editor.SelectAll(new SelectionFilter(array)); if (selection.Status == (PromptStatus.Cancel)) { CommandLineQuerries.OnCancelled(); } if (selection.Status != PromptStatus.OK) { return(null); } return(selection.Value.GetObjectIds()); }
public static ObjectId[] getAllLines() { ObjectId[] objectIDs = null; Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; try { TypedValue[] filter = new TypedValue[] { new TypedValue(-4, "<or"), new TypedValue(0, "LINE"), new TypedValue(0, "LWPOLYLINE"), new TypedValue(0, "POLYLINE2D"), new TypedValue(0, "POLYLINE"), new TypedValue(-4, "or>") }; PromptSelectionResult selection = editor.SelectAll(new SelectionFilter(filter)); if (selection.Status == (PromptStatus.Cancel)) { CommandLineQuerries.OnCancelled(); } if (selection.Status != PromptStatus.OK) { return(null); } objectIDs = selection.Value.GetObjectIds(); //Region region= AddRegion(objectIDs); } catch (System.Exception ex) { } return(objectIDs); }
public static PointSet getPointFromText(ScaleProp scale) { Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; try { PointSet pointSet = new PointSet(); TypedValue[] filter = null; filter = new TypedValue[] { new TypedValue(0, "TEXT") }; PromptSelectionResult selection = editor.SelectAll(new SelectionFilter(filter)); if (selection.Status == (PromptStatus)(-5002)) { CommandLineQuerries.OnCancelled(); } if (selection.Status != (PromptStatus)5100) { return(null); } ObjectId[] objectIDs = selection.Value.GetObjectIds(); if (objectIDs != null) { Database workingDatabase = HostApplicationServices.WorkingDatabase; using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction()) { for (int i = 0; i < objectIDs.Length; i++) { DBText dbText = (DBText)transaction.GetObject(objectIDs[i], OpenMode.ForRead, true); string text = dbText.TextString; double z = 0; double.TryParse(text, out z); pointSet.Add(new ngeometry.VectorGeometry.Point(dbText.Position.X * scale.X, dbText.Position.Y * scale.Y, z * scale.Z)); } transaction.Commit(); } } else { editor.WriteMessage("没有选择到点.\n"); } return(pointSet); } catch (System.Exception ex) { } return(null); }
public void SliceLineCommand() { Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; Database arg_15_0 = HostApplicationServices.WorkingDatabase; try { //LicenseManager.CheckValid("FULL"); ObjectId[] objectId_ = CommandLineQuerries.SelectLines(false); ngeometry.VectorGeometry.Plane planeNormalized = CommandLineQuerries.Specify3PSystem().GetPlaneNormalized(); int num = 0; while (num == 0) { Point left = new Point(); PromptPointResult promptPointResult = CommandLineQuerries.SpecifyPointOrKeepBothSides(); if (promptPointResult.Status == (PromptStatus)(-5005)) { num = 0; IL_F2_: this.method_0(objectId_, planeNormalized, num); return; } if (promptPointResult.Status == (PromptStatus)5100) { Point3d value = promptPointResult.Value; left = new Point(value.X, value.Y, value.Z); num = Math.Sign(ngeometry.VectorGeometry.Vector3d.Dot(planeNormalized.NormalVector, new ngeometry.VectorGeometry.Vector3d(left - planeNormalized.Point))); if (num == 0) { editor.WriteMessage("\nInvalid point: point is on plane."); } } else if (promptPointResult.Status == (PromptStatus)(-5002)) { CommandLineQuerries.OnCancelled(); } else if (promptPointResult.Status != (PromptStatus)5100) { CommandLineQuerries.OnNotOK(); } } goto IL_F2; IL_F2: { this.method_0(objectId_, planeNormalized, num); return; } } catch (System.Exception ex) { editor.WriteMessage(Environment.NewLine + ex.Message + Environment.NewLine); } }
public static ObjectId[] GetObjectIDs(CommandLineQuerries.EntityType type, string layerName) { Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; if (layerName == null || layerName == "") { layerName = "*"; } TypedValue[] array = new TypedValue[0]; switch (type) { case CommandLineQuerries.EntityType.Region: array = new TypedValue[] { new TypedValue(-4, "<or"), new TypedValue(-4, "<and"), new TypedValue((int)DxfCode.LayerName, layerName), new TypedValue((int)DxfCode.Start, "REGION"), new TypedValue(-4, "and>"), new TypedValue(-4, "or>") }; break; case CommandLineQuerries.EntityType.FACE: array = new TypedValue[] { new TypedValue(-4, "<or"), new TypedValue(-4, "<and"), new TypedValue((int)DxfCode.LayerName, layerName), new TypedValue(0, "3DFACE"), new TypedValue(-4, "and>"), new TypedValue(-4, "or>") }; break; case CommandLineQuerries.EntityType.PLINES: array = new TypedValue[] { new TypedValue(-4, "<or"), new TypedValue(-4, "<and"), new TypedValue((int)DxfCode.LayerName, layerName), new TypedValue(-4, "<or"), new TypedValue(0, "POLYLINE2D"), new TypedValue(0, "POLYLINE3D"), new TypedValue(0, "POLYLINE"), new TypedValue(-4, "or>"), new TypedValue(-4, "and>"), new TypedValue(-4, "or>") }; break; } PromptSelectionResult selection = editor.SelectAll(new SelectionFilter(array)); if (selection.Status == (PromptStatus.Cancel)) { CommandLineQuerries.OnCancelled(); } if (selection.Status != PromptStatus.OK) { return(null); } return(selection.Value.GetObjectIds()); }
public void DevelopmentCommand() { Database arg_05_0 = HostApplicationServices.WorkingDatabase; Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; try { //LicenseManager.CheckValid("FULL"); PromptEntityOptions promptEntityOptions = new PromptEntityOptions("Select polyline"); promptEntityOptions.SetRejectMessage("\nNo polyline selected"); promptEntityOptions.AddAllowedClass(typeof(Polyline3d), true); promptEntityOptions.AddAllowedClass(typeof(Polyline2d), true); promptEntityOptions.AddAllowedClass(typeof(Polyline), true); promptEntityOptions.AllowNone = (false); PromptEntityResult entity = editor.GetEntity(promptEntityOptions); if (entity.Status == (PromptStatus)(-5002)) { CommandLineQuerries.OnCancelled(); } if (entity.Status != (PromptStatus)5100) { CommandLineQuerries.OnNotOK(); } CMD_Development.string_2 = CommandLineQuerries.KeywordYesNo("Reverse polyline", CMD_Development.string_2, false, false); CMD_Development.string_3 = CommandLineQuerries.KeywordYesNo("Specify range", CMD_Development.string_3, false, false); if (CMD_Development.string_3 == "Y") { CMD_Development.double_0 = CommandLineQuerries.SpecifyDouble("Specify start arc length", CMD_Development.double_0, false, false, false, true); CMD_Development.double_1 = CommandLineQuerries.SpecifyDouble("Specify end arc length", CMD_Development.double_1, false, false, false, true); } CMD_Development.double_2 = CommandLineQuerries.SpecifyDouble("Specify z-scaling", CMD_Development.double_2, false, false, false, false); CMD_Development.string_5 = CommandLineQuerries.KeywordYesNo("Include first derivative (slope)", CMD_Development.string_5, false, false); if (CMD_Development.string_5 == "Y") { CMD_Development.double_3 = CommandLineQuerries.SpecifyDouble("Specify z-scaling for derivative", CMD_Development.double_3, false, false, false, false); } CMD_Development.string_4 = CommandLineQuerries.SpecifyOutfileType(CMD_Development.string_4); CommandLineQuerries.SpecifyFileNameForWrite(ref CMD_Development.string_0, ref CMD_Development.string_1, CMD_Development.string_4); bool reverse = CMD_Development.string_2 == "Y"; double startBGL = 0.0; double endBGL = 1.7976931348623157E+308; if (CMD_Development.string_3 == "Y") { startBGL = CMD_Development.double_0; endBGL = CMD_Development.double_1; } List <Point> list = this.DevelopPolyline(entity.ObjectId, reverse, startBGL, endBGL); List <Point> points = new List <Point>(); if (CMD_Development.string_5 == "Y") { points = this.Derivative(list); } CMD_Development.Result result = new CMD_Development.Result(list, startBGL); editor.WriteMessage("\n" + result.ToString()); Database database = new Database(true, true); using (Transaction transaction = database.TransactionManager.StartTransaction()) { BlockTable blockTable = (BlockTable)transaction.GetObject(database.BlockTableId, (OpenMode)1); BlockTableRecord blockTableRecord = (BlockTableRecord)transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], (OpenMode)1); bool flag = false; ObjectId layerId = DBManager.CreateLayer("profile", 7, false, ref flag, database); Point3dCollection point3dCollection = Conversions.ToPoint3dCollection(list); Polyline3d polyline3d = new Polyline3d(0, point3dCollection, false); point3dCollection.Dispose(); polyline3d.LayerId = (layerId); blockTableRecord.AppendEntity(polyline3d); transaction.AddNewlyCreatedDBObject(polyline3d, true); if (CMD_Development.string_5 == "Y") { bool flag2 = false; ObjectId layerId2 = DBManager.CreateLayer("slope", 4, false, ref flag2, database); Point3dCollection point3dCollection2 = Conversions.ToPoint3dCollection(points); Polyline3d polyline3d2 = new Polyline3d(0, point3dCollection2, false); point3dCollection2.Dispose(); polyline3d2.LayerId = (layerId2); blockTableRecord.AppendEntity(polyline3d2); transaction.AddNewlyCreatedDBObject(polyline3d2, true); } transaction.Commit(); polyline3d.Dispose(); } DBManager.SaveDrawing(database, CMD_Development.string_0, CMD_Development.string_4, (DwgVersion)29); } catch (System.Exception ex) { editor.WriteMessage(Environment.NewLine + ex.Message + Environment.NewLine); } }
public void SliceFacesCommand() { Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; try { //LicenseManager.CheckValid("FULL"); ObjectId[] objectId_ = CommandLineQuerries.SelectFaces(false); CoordinateSystem coordinateSystem = CommandLineQuerries.Specify3PSystem(); ngeometry.VectorGeometry.Plane planeNormalized = coordinateSystem.GetPlaneNormalized(); int num = 0; while (num == 0) { Point left = new Point(); PromptPointResult promptPointResult = CommandLineQuerries.SpecifyPointOrKeepBothSides(); if (promptPointResult.Status == (PromptStatus)(-5005)) { num = 0; IL_F3_: EntitySlicer.string_0 = CommandLineQuerries.KeywordYesNo("Keep coplanar faces", EntitySlicer.string_0, false, false); int num2 = 0; int num3 = 0; int num4 = 0; bool bool_ = false; if (EntitySlicer.string_0.Trim().ToUpper() == "Y") { bool_ = true; } this.method_1(objectId_, planeNormalized, num, bool_, ref num2, ref num3, ref num4); editor.WriteMessage("\nFailed faces : " + num3.ToString()); editor.WriteMessage("\nFaces sliced : " + num2.ToString()); editor.WriteMessage("\nFaces remaining: " + num4.ToString()); return; } if (promptPointResult.Status == (PromptStatus)5100) { Point3d value = promptPointResult.Value; left = new Point(value.X, value.Y, value.Z); num = Math.Sign(ngeometry.VectorGeometry.Vector3d.Dot(planeNormalized.NormalVector, new ngeometry.VectorGeometry.Vector3d(left - planeNormalized.Point))); if (num == 0) { editor.WriteMessage("\nInvalid point: point is on slicing plane."); } } else if (promptPointResult.Status == (PromptStatus)(-5002)) { CommandLineQuerries.OnCancelled(); } else if (promptPointResult.Status != (PromptStatus)5100) { CommandLineQuerries.OnNotOK(); } } goto IL_F3; IL_F3: { EntitySlicer.string_0 = CommandLineQuerries.KeywordYesNo("Keep coplanar faces", EntitySlicer.string_0, false, false); int num2 = 0; int num3 = 0; int num4 = 0; bool bool_ = false; if (EntitySlicer.string_0.Trim().ToUpper() == "Y") { bool_ = true; } this.method_1(objectId_, planeNormalized, num, bool_, ref num2, ref num3, ref num4); editor.WriteMessage("\nFailed faces : " + num3.ToString()); editor.WriteMessage("\nFaces sliced : " + num2.ToString()); editor.WriteMessage("\nFaces remaining: " + num4.ToString()); return; } } catch (System.Exception ex) { editor.WriteMessage("\n" + ex.Message + "\n"); } }