/// <summary> 计算选择的所有曲线的面积与长度之和 </summary> public ExternalCmdResult Polyline2Point(DocumentModifier docMdf, SelectionSet impliedSelection) { _docMdf = docMdf; // var pl = SelectUtils.PickEntity <Polyline3d>(docMdf.acEditor, message: "选择一个三维多段线对象"); if (pl == null) { return(ExternalCmdResult.Cancel); } // var cs = EditStateIdentifier.GetCurrentEditState(docMdf); cs.CurrentBTR.UpgradeOpen(); foreach (ObjectId id in pl) { var vert = id.GetObject(OpenMode.ForRead) as PolylineVertex3d; if (vert != null) { var pt = vert.Position; DBPoint p = new DBPoint(pt); cs.CurrentBTR.AppendEntity(p); docMdf.acTransaction.AddNewlyCreatedDBObject(p, true); } } cs.CurrentBTR.DowngradeOpen(); return(ExternalCmdResult.Commit); }
/// <summary> /// 具体的高度操作的代码模板 /// </summary> /// <param name="docMdf"></param> /// <param name="impliedSelection"></param> private void DoSomethingTemplate(DocumentModifier docMdf, SelectionSet impliedSelection) { var obj = SelectUtils.PickEntity <Entity>(docMdf.acEditor); if (obj != null) { var blkTb = docMdf.acTransaction.GetObject(docMdf.acDataBase.BlockTableId, OpenMode.ForRead) as BlockTable; var btr = docMdf.acTransaction.GetObject(blkTb[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; var ent = new DBText(); // 将新对象添加到块表记录和事务 btr.AppendEntity(ent); docMdf.acTransaction.AddNewlyCreatedDBObject(ent, true); } }
/// <summary> <seealso cref="CommandDescription"/> </summary> public ExternalCmdResult EditEntityAnnotation(DocumentModifier docMdf, SelectionSet impliedSelection) { _docMdf = docMdf; // var ent = SelectUtils.PickEntity <Entity>(_docMdf.acEditor, "查看任意一个元素的注释"); if (ent == null) { return(ExternalCmdResult.Commit); } AnnotationEntity.SetAppName(_docMdf); var annoEnt = new AnnotationEntity(ent); var annots = annoEnt.ExtractAnnotsFromXdata(); // annoEnt.WriteAnnotationsOnEditor(docMdf); bool cont; Entity newEnt = null; do { bool clearAnnot = false; bool editInForm = false; bool setNewValue = false; string newAnno = null; cont = ReadEntityAnnot(docMdf.acEditor, out clearAnnot, out editInForm, out setNewValue, out newEnt); if (!cont) { return(ExternalCmdResult.Commit); } // if (clearAnnot) { annoEnt.ClearAnnotations(); _docMdf.WriteNow(); } else if (editInForm) { _docMdf.WriteNow(); } else if (setNewValue) { newAnno = annots.Count == 0 ? "" : annots[0]; cont = SetAnnotations(docMdf.acEditor, ref newAnno); if (!cont) { return(ExternalCmdResult.Commit); } annoEnt.SetAnnotsToXdata(newAnno); // annoEnt.WriteAnnotationsOnEditor(docMdf); } else { // 选择了另一个元素 if (newEnt != null) { annoEnt = new AnnotationEntity(newEnt); annots = annoEnt.ExtractAnnotsFromXdata(); // annoEnt.WriteAnnotationsOnEditor(docMdf); } } } while (cont); // return(ExternalCmdResult.Commit); }
// 开始具体的调试操作 private ExternalCmdResult CreateViewport(DocumentModifier docMdf, SelectionSet impliedSelection) { _docMdf = docMdf; //// var vp1 = AddinManagerDebuger.PickObject<Entity>(docMdf.acEditor); //var hd = Utils.ConvertToHandle("AA07"); //var vp2 = hd.GetObjectId(docMdf.acDataBase).GetObject(OpenMode.ForRead) as Viewport; //vp2.UpgradeOpen(); //var lot = LayoutManager.Current.GetLayoutId("NewLayout4011").GetObject(OpenMode.ForRead) as Layout; //vp2.RotateViewport(_docMdf, lot, new Point2d(0, 0), 30.0 / 180 * Math.PI); //return ExternalCmdResult.Commit; // 从模型空间中获取视口裁剪框 var pl_Model = SelectUtils.PickEntity <Curve>(docMdf.acEditor); Point3d bottomLeftPt = default(Point3d); Point3d bottomRightPt = default(Point3d); double bottomLength = 0; var succ = GraphicalElementsSelector.GetPoint(docMdf.acEditor, "选择图纸的左下角点", out bottomLeftPt); if (!succ) { return(ExternalCmdResult.Cancel); } succ = GraphicalElementsSelector.GetPoint(docMdf.acEditor, "选择图纸的右下角点", out bottomRightPt); if (!succ) { return(ExternalCmdResult.Cancel); } succ = GraphicalElementsSelector.GetDouble(docMdf.acEditor, "图纸宽度(布局空间的单位)", out bottomLength, defaultValue: 420, allowNegative: false); if (!succ) { return(ExternalCmdResult.Cancel); } var modelUcs = docMdf.acEditor.GetCurrentView().Ucs; // 打开布局 var lm = LayoutManager.Current; Layout layout; ObjectId layoutId; Form_LayoutLister f = new Form_LayoutLister(docMdf); f.ShowDialog(); if (f.CreateNewLayout) { // MessageBox.Show("请先自行创建带图框的布局"); return(ExternalCmdResult.Cancel); /* * var layoutName = "NewLayout" + DateTime.Now.Minute + DateTime.Now.Second; * layoutId = lm.GetLayoutId(layoutName); * if (!layoutId.IsValid) * { * // 重启事务 * docMdf.RestartTransaction(commitCancel: false); * // * layoutId = LayoutUtil.CreateLayout(layoutName); * layout = layoutId.GetObject(OpenMode.ForRead) as Layout; * // * LayoutUtil.SetPlotSettings(layout, "A3", "monochrome.ctb", "交通院道路室 121"); * } * else * { * layout = LayoutManager.Current.GetLayoutId(name: layoutName).GetObject(OpenMode.ForRead) as Layout; * } */ } else if (f.Layout != null) { layout = f.Layout; } else { return(ExternalCmdResult.Cancel); } // docMdf.RestartTransaction(true); // 切换布局 // lm.SetCurrentLayoutId(layout.Id); // AutoCAD 2016 lm.CurrentLayout = layout.LayoutName; // 创建视口 CreateViewport(docMdf, modelUcs, layout, pl_Model, bottomLeftPt, bottomRightPt, bottomLength); // 切换回模型空间 // Autodesk.AutoCAD.ApplicationServices.Core.Application.SetSystemVariable("TILEMODE", 1); // LayoutUtil.SwitchLayout(); return(ExternalCmdResult.Commit); }