public static DBText CreateText(string text, Point3d pos, EntityOptions entityOptions= null) { var dbText = new DBText(); dbText.TextString = text; dbText.Position = pos; dbText.SetOptions(entityOptions); return dbText; }
static string GetTag(DBText dbtext) { AttributeDefinition attdef = dbtext as AttributeDefinition; if (attdef != null) return attdef.Tag; AttributeReference attref = dbtext as AttributeReference; if (attref != null) return attref.Tag; throw new ArgumentException("requires an AttributeDefintion or AttributeReference"); }
private static void ControlTextLength(DBText text, double lenMax) { if (text.Bounds.HasValue) { var lenTextX = text.Bounds.Value.MaxPoint.X - text.Bounds.Value.MinPoint.X; var lenTextY = text.Bounds.Value.MaxPoint.Y - text.Bounds.Value.MinPoint.Y; var lenText = lenTextX > lenTextY ? lenTextX : lenTextY; if (lenText > lenMax) { text.WidthFactor -= 0.1; ControlTextLength(text, lenMax); } } }
public void Create(Point2d ptCell, BlockTableRecord cs, Transaction t) { var cellWidth = ColorBookHelper.CellWidth; var cellHeight = ColorBookHelper.CellHeight; var margin = ColorBookHelper.Margin; var marginHalf = margin * 0.5; Point3d ptText = new Point3d(ptCell.X + cellWidth * 0.5, ptCell.Y - ColorBookHelper.TextHeight-margin, 0); Polyline pl = new Polyline(4); pl.AddVertexAt(0, new Point2d(ptCell.X+margin, ptText.Y- marginHalf), 0, 0, 0); pl.AddVertexAt(1, new Point2d(ptCell.X+cellWidth- margin, ptText.Y- marginHalf), 0, 0, 0); pl.AddVertexAt(2, new Point2d(ptCell.X + cellWidth-margin, ptCell.Y-cellHeight+margin), 0, 0, 0); pl.AddVertexAt(3, new Point2d(ptCell.X+margin, ptCell.Y - cellHeight+margin), 0, 0, 0); pl.Closed = true; pl.SetDatabaseDefaults(); pl.Color = Color; cs.AppendEntity(pl); t.AddNewlyCreatedDBObject(pl, true); Hatch h = new Hatch(); h.SetDatabaseDefaults(); h.SetHatchPattern(HatchPatternType.PreDefined, "Solid"); h.Annotative = AnnotativeStates.False; cs.AppendEntity(h); t.AddNewlyCreatedDBObject(h, true); h.Associative = true; h.AppendLoop(HatchLoopTypes.Default, new ObjectIdCollection(new[] { pl.Id })); h.Color = Color; h.EvaluateHatch(true); DBText text = new DBText(); text.SetDatabaseDefaults(); text.HorizontalMode = TextHorizontalMode.TextCenter; text.Annotative = AnnotativeStates.False; text.Height = ColorBookHelper.TextHeight; text.AlignmentPoint = ptText; text.AdjustAlignment(cs.Database); text.TextStyleId = ColorBookHelper.IdTextStylePik; text.TextString = Name; cs.AppendEntity(text); t.AddNewlyCreatedDBObject(text, true); }
//public AttributeRefInfo(AttributeReference attr) //{ // Tag = attr.Tag; // Text = attr.TextString; // IdAtrRef = attr.Id; //} /// <summary> /// DBText - должен быть или AttributeDefinition или AttributeReference /// иначе исключение ArgumentException /// </summary> /// <param name="attr"></param> public AttributeRefInfo(DBText attr) { AttributeDefinition attdef = attr as AttributeDefinition; if (attdef != null) { Tag = attdef.Tag; } else { AttributeReference attref = attr as AttributeReference; if (attref != null) { Tag = attref.Tag; } else { throw new ArgumentException("requires an AttributeDefintion or AttributeReference"); } } Text = attr.TextString; IdAtrRef = attr.Id; }
public void Test_method_name() { // Arrange Database db = HostApplicationServices.WorkingDatabase; Document doc = Application.DocumentManager.GetDocument(db); DBText dbText = new DBText {TextString = "cat"}; string testMe; // Act using (doc.LockDocument()) { using (db.TransactionManager.StartTransaction()) { ObjectId dbTextObjectId = DbEntity.AddToModelSpace(dbText, db); dbText.TextString = "dog"; DBText testText = dbTextObjectId.Open(OpenMode.ForRead, false) as DBText; testMe = testText != null ? testText.TextString : string.Empty; } } // Assert StringAssert.AreEqualIgnoringCase("dog", testMe, "DBText string was not changed to \"dog\"."); StringAssert.AreNotEqualIgnoringCase("cat", testMe, "DBText string was not changed."); }
// 道路边线在上面 public void Flag1() { Database db = HostApplicationServices.WorkingDatabase; // 获取命令行窗口 Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; PromptPointOptions ppo = new PromptPointOptions("请指定第一个点:"); ppo.AllowNone = true; PromptPointResult ppr = GetPoint(ppo); if (ppr.Status == PromptStatus.Cancel) { return; } if (ppr.Status == PromptStatus.OK) { // p1 为点击的第1个点 Point3d p1 = ppr.Value; ppo.Message = "请指定第二个点"; ppo.BasePoint = p1; ppo.UseBasePoint = true; ppr = GetPoint(ppo); if (ppr.Status == PromptStatus.Cancel) { return; } if (ppr.Status == PromptStatus.None) { return; } if (ppr.Status == PromptStatus.OK) { // p2 为点击的第2个点 Point3d p2 = ppr.Value; // 利用p1和p2 计算p3、p4和p5 double valueX = p2.X - p1.X; double valueY = p2.Y - p1.Y; double radian = Math.Atan2(valueY, valueX); double X3 = p1.X + 20 * Math.Cos(radian); double Y3 = p1.Y + 20 * Math.Sin(radian); Point3d p3 = new Point3d(X3, Y3, 0); double X4 = p1.X + 28 * Math.Cos(radian); double Y4 = p1.Y + 28 * Math.Sin(radian); Point3d p4 = new Point3d(X4, Y4, 0); double X5 = p1.X + 35 * Math.Cos(radian); double Y5 = p1.Y + 35 * Math.Sin(radian); Point3d p5 = new Point3d(X5, Y5, 0); // 垂直的两条线 double radian2 = radian + Math.PI / 2; double X6 = p3.X + 15 * Math.Cos(radian2); double Y6 = p3.Y + 15 * Math.Sin(radian2); Point3d p6 = new Point3d(X6, Y6, 0); double X7 = p4.X + 15 * Math.Cos(radian2); double Y7 = p4.Y + 15 * Math.Sin(radian2); Point3d p7 = new Point3d(X7, Y7, 0); // db.AddLineToModeSpace(p1, p2); db.AddLineToModeSpace(p1, p5); db.AddLineToModeSpace(p3, p6); db.AddLineToModeSpace(p4, p7); ObjectId C1 = db.AddCircleModeSpace(p1, 0.755); db.HatchEnity(HatchTools.HatchPatternName.solid, 1, 45, C1); ObjectId C2 = db.AddCircleModeSpace(p2, 0.755); db.HatchEnity(HatchTools.HatchPatternName.solid, 1, 45, C2); // 文字定位的点 double XX3 = p1.X + 21 * Math.Cos(radian); double YY3 = p1.Y + 21 * Math.Sin(radian); Point3d pp3 = new Point3d(XX3, YY3, 0); double XX4 = p1.X + 29 * Math.Cos(radian); double YY4 = p1.Y + 29 * Math.Sin(radian); Point3d pp4 = new Point3d(XX4, YY4, 0); double XX6 = pp3.X + 8 * Math.Cos(radian2); double YY6 = pp3.Y + 8 * Math.Sin(radian2); Point3d pp6 = new Point3d(XX6, YY6, 0); double XX7 = pp4.X + 8 * Math.Cos(radian2); double YY7 = pp4.Y + 8 * Math.Sin(radian2); Point3d pp7 = new Point3d(XX7, YY7, 0); // 通过事务添加文字 using (Transaction trans = db.TransactionManager.StartTransaction()) { DBText text0 = new DBText(); // 新建单行文本对象 text0.Position = pp6; // 设置文本位置 text0.TextString = "燃气管道"; // 设置文本内容 text0.Height = 3; // 设置文本高度 text0.WidthFactor = 0.7; text0.Rotation = radian2 + Math.PI; // 设置文本选择角度 text0.HorizontalMode = TextHorizontalMode.TextCenter; // 设置对齐方式 text0.AlignmentPoint = text0.Position; //设置对齐点 db.AddEntityToModeSpace(text0); DBText text1 = new DBText(); // 新建单行文本对象 text1.Position = pp7; text1.TextString = "道路边线"; text1.Height = 3; text1.WidthFactor = 0.7; text1.Rotation = radian2 + Math.PI; text1.HorizontalMode = TextHorizontalMode.TextCenter; text1.AlignmentPoint = text1.Position; // 设置对齐点 db.AddEntityToModeSpace(text1); trans.Commit(); } } } }
public void insertBalloon() { Settings setting = Settings.getInstance(); // make the line and circle. Line _lineBal = new Line(); Circle _circleBal = new Circle(); // set properties for line and circle. _lineBal.ColorIndex = setting.IndexColorLine; _circleBal.ColorIndex = setting.IndexColorCircle; _circleBal.Diameter = setting.Diameter; // get the first point. Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; PromptPointOptions ptPointOpt = new PromptPointOptions("Pick the first point: "); PromptPointResult ptPointRes = ed.GetPoint(ptPointOpt); if (ptPointRes.Status != PromptStatus.OK) { return; } // Turn the point at UCS into the point at WCS. Point3d ptUCS = ptPointRes.Value; _lineBal.StartPoint = ptUCS.TransformBy(ed.CurrentUserCoordinateSystem); // Jig action. BalloonJig jigBalloon = new BalloonJig(_lineBal, _circleBal); PromptResult prompt = ed.Drag(jigBalloon); if (prompt.Status == PromptStatus.Cancel || prompt.Status == PromptStatus.Error) { return; } // save all of elements into Database. Database dwg = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database; using (Transaction trans = dwg.TransactionManager.StartTransaction()) { try { BlockTable blk = trans.GetObject(dwg.BlockTableId, OpenMode.ForWrite) as BlockTable; if (blk == null) { return; } // make text for circle. DBText _textBal = makeText(_circleBal.Center); _textBal.ColorIndex = setting.IndexColorText; _textBal.TextString = setting.Text; // make the list of objectId of each elements. List <ObjectId> lstObjectId = new List <ObjectId>(); // append elements into database. BlockTableRecord blkRecord = trans.GetObject(blk[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; ObjectId objLineId = blkRecord.AppendEntity(_lineBal); lstObjectId.Add(objLineId); ObjectId objCircleId = blkRecord.AppendEntity(_circleBal); lstObjectId.Add(objCircleId); ObjectId objTextId = blkRecord.AppendEntity(_textBal); lstObjectId.Add(objTextId); // save id of each elements. ImplementationDatabase.LstObjectId = lstObjectId; trans.AddNewlyCreatedDBObject(_lineBal, true); trans.AddNewlyCreatedDBObject(_circleBal, true); trans.AddNewlyCreatedDBObject(_textBal, true); trans.Commit(); } catch (System.Exception) { trans.Abort(); throw; } } // get name for this group. PromptStringOptions strOptions = new PromptStringOptions("The name of this entity: "); strOptions.AllowSpaces = true; PromptResult promptRes = ed.GetString(strOptions); if (promptRes.Status != PromptStatus.OK) { ImplementationDatabase.NameGroup = "*"; } else { ImplementationDatabase.NameGroup = promptRes.StringResult; } // make group. ImplementationDatabase.makeGroup(); }
public static void ImportAsXref() { Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; bool Aborted = false; SaveFileDialog sfd; ObjectId SurveyTextStyle; //Make all the drawing changes using (DocumentLock dl = acDoc.LockDocument()) { using (Transaction tr = acDoc.Database.TransactionManager.StartTransaction()) { //Remove all sheets ObjectId newLayout = LayoutManager.Current.CreateLayout("Paper"); LayoutManager.Current.SetCurrentLayoutId(newLayout); DBDictionary lays = tr.GetObject(acDoc.Database.LayoutDictionaryId, OpenMode.ForWrite) as DBDictionary; foreach (DBDictionaryEntry item in lays) { string layoutName = item.Key; if (layoutName != "Model" && layoutName != "Paper") { LayoutManager.Current.DeleteLayout(layoutName); // Delete layout. } } //Get or create the survey text style TextStyleTable tst = tr.GetObject(acDoc.Database.TextStyleTableId, OpenMode.ForRead) as TextStyleTable; if (!tst.Has("JPP_Survey")) { tst.UpgradeOpen(); TextStyleTableRecord tstr = new TextStyleTableRecord(); tstr.FileName = "romans.shx"; tstr.Name = "JPP_Survey"; tst.Add(tstr); tr.AddNewlyCreatedDBObject(tstr, true); } SurveyTextStyle = tst["JPP_Survey"]; //Get all model space drawing objects TypedValue[] tv = new TypedValue[1]; tv.SetValue(new TypedValue(67, 0), 0); SelectionFilter sf = new SelectionFilter(tv); PromptSelectionResult psr = acDoc.Editor.SelectAll(sf); //Lengthy operations so show progress bar ProgressMeter pm = new ProgressMeter(); Byte alpha = (Byte)(255 * (1)); Transparency trans = new Transparency(alpha); //Iterate over all layer and set them to color 8, 0 transparency and continuous linetype // Open the Layer table for read LayerTable acLyrTbl = tr.GetObject(acDoc.Database.LayerTableId, OpenMode.ForRead) as LayerTable; int layerCount = 0; foreach (ObjectId id in acLyrTbl) { layerCount++; } pm = new ProgressMeter(); pm.Start("Updating layers..."); pm.SetLimit(layerCount); foreach (ObjectId id in acLyrTbl) { LayerTableRecord ltr = tr.GetObject(id, OpenMode.ForWrite) as LayerTableRecord; ltr.IsLocked = false; ltr.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 8); ltr.LinetypeObjectId = acDoc.Database.ContinuousLinetype; ltr.LineWeight = acDoc.Database.Celweight; ltr.Transparency = trans; pm.MeterProgress(); System.Windows.Forms.Application.DoEvents(); } pm.Stop(); pm.Start("Updating objects..."); pm.SetLimit(psr.Value.Count); foreach (SelectedObject so in psr.Value) { //For each object set its color, transparency, lineweight and linetype to ByLayer Entity obj = tr.GetObject(so.ObjectId, OpenMode.ForWrite) as Entity; obj.ColorIndex = 256; obj.LinetypeId = acDoc.Database.Celtype; obj.LineWeight = acDoc.Database.Celweight; pm.MeterProgress(); System.Windows.Forms.Application.DoEvents(); if (obj is Polyline) { Polyline pl = obj as Polyline; pl.Elevation = 0; } if (obj is Polyline2d) { Polyline2d pl = obj as Polyline2d; pl.Elevation = 0; } if (obj is Polyline3d) { Polyline3d pl3d = obj as Polyline3d; foreach (ObjectId id in pl3d) { PolylineVertex3d plv3d = tr.GetObject(id, OpenMode.ForWrite) as PolylineVertex3d; Point3d p3d = plv3d.Position; plv3d.Position = new Point3d(p3d.X, p3d.Y, 0); } } //Change all text to Romans if (obj is DBText) { DBText text = obj as DBText; text.Position = new Point3d(text.Position.X, text.Position.Y, 0); text.Height = 0.4; text.TextStyleId = SurveyTextStyle; } if (obj is MText) { MText text = obj as MText; text.Location = new Point3d(text.Location.X, text.Location.Y, 0); text.Height = 0.4; text.TextStyleId = SurveyTextStyle; } } pm.Stop(); //Operate over all blocks BlockTable blkTable = (BlockTable)tr.GetObject(acDoc.Database.BlockTableId, OpenMode.ForRead); int blockCount = 0; foreach (ObjectId id in blkTable) { blockCount++; } pm = new ProgressMeter(); pm.Start("Updating blocks..."); pm.SetLimit(blockCount); foreach (ObjectId id in blkTable) { BlockTableRecord btRecord = (BlockTableRecord)tr.GetObject(id, OpenMode.ForRead); if (!btRecord.IsLayout) { foreach (ObjectId childId in btRecord) { //For each object set its color, transparency, lineweight and linetype to ByLayer Entity obj = tr.GetObject(childId, OpenMode.ForWrite) as Entity; obj.ColorIndex = 256; obj.LinetypeId = acDoc.Database.Celtype; obj.LineWeight = acDoc.Database.Celweight; //Adjust Z values } } pm.MeterProgress(); System.Windows.Forms.Application.DoEvents(); } pm.Stop(); //Run the cleanup commands Core.Utilities.Purge(); acDoc.Database.Audit(true, false); //Prompt for the save location sfd = new SaveFileDialog(); sfd.Filter = "Drawing File|*.dwg"; sfd.Title = "Save drawing as"; sfd.ShowDialog(); if (sfd.FileName != "") { tr.Commit(); Aborted = false; } else { tr.Abort(); Aborted = true; } } } if (!Aborted) { acDoc.Database.SaveAs(sfd.FileName, Autodesk.AutoCAD.DatabaseServices.DwgVersion.Current); //Close the original file as its no longer needed acDoc.CloseAndDiscard(); } }
private Dictionary <string, PanelBase> matchingPlans(List <FacadeMounting> facadesMounting, List <FloorArchitect> floorsAr) { // Определение окон в монтажных планах по архитектурным планам var panelsBase = new Dictionary <string, PanelBase>(); // string - ключ - маркаСБ + Марки Окон по порядку. // Список монтажных планов - уникальных var floorsMount = facadesMounting.SelectMany(f => f.Floors); foreach (var floorMount in floorsMount) { // Найти соотв арх план var floorAr = floorsAr.Find(f => f.Section == floorMount.Section && f.IsEqualMountingStorey(floorMount.Storey) ); //Test Добавить текст имени плана Ар в блок монтажного плана #if Test { if (floorAr != null) { using (var btrMount = floorMount.IdBtrMounting.Open(OpenMode.ForWrite) as BlockTableRecord) { DBText textFindPlanAr = new DBText(); textFindPlanAr.TextString = floorAr.BlName; btrMount.AppendEntity(textFindPlanAr); //btrMount.Database.TransactionManager.TopTransaction.AddNewlyCreatedDBObject(textFindPlanAr, true); } } } #endif if (floorAr == null) { Inspector.AddError($"Не найден блок архитектурного плана для соответствующего монтажного плана '{floorMount.BlRefName}'", floorMount.IdBlRefMounting, icon: System.Drawing.SystemIcons.Error); } else if (floorAr.Windows.Count == 0) { Inspector.AddError($"Не найдено ни одного окна в блоке архитектурного плана '{floorMount.BlRefName}'.", floorAr.IdBlRef, icon: System.Drawing.SystemIcons.Error); } foreach (var panelMount in floorMount.PanelsSbInFront) { Panel panelXml = GetPanelXml(panelMount.MarkSb, panelMount); if (panelXml == null) { continue; } PanelBase panelBase = new PanelBase(panelXml, this, panelMount); // Определение окон в панели по арх плану if (panelXml.windows?.window != null) { foreach (var window in panelXml.windows.window) { if (floorAr == null || floorAr.Windows.Count == 0) { break; } // Точка окна внутри панели по XML описанию Point3d ptOpeningCenter = new Point3d(window.posi.X + window.width * 0.5, 0, 0); // Точка окна внутри монтажного плана Point3d ptWindInModel = panelMount.ExtTransToModel.MinPoint.Add(ptOpeningCenter.GetAsVector()); Point3d ptWindInArPlan = ptWindInModel.TransformBy(floorMount.Transform.Inverse()); var windowKey = floorAr?.Windows.GroupBy(w => w.Key.DistanceTo(ptWindInArPlan))?.MinBy(w => w.Key); if (windowKey == null || windowKey.Key > 600) { Inspector.AddError( $"Не найдено соответствующее окно в архитектурном плане. Блок монтажной панели {panelMount.MarkSb}", panelMount.ExtTransToModel, panelMount.IdBlRef, icon: System.Drawing.SystemIcons.Error); continue; } panelBase.WindowsBaseCenters.Add(ptOpeningCenter, windowKey.First().Value); // Test Добавление точек окна в блоке монтажки #if Test { using (var btrMountPlan = floorMount.IdBtrMounting.Open(OpenMode.ForWrite) as BlockTableRecord) { using (DBPoint ptWinInPlan = new DBPoint(ptWindInArPlan)) { ptWinInPlan.ColorIndex = 2; btrMountPlan.AppendEntity(ptWinInPlan); //btrMountPlan.Database.TransactionManager.TopTransaction.AddNewlyCreatedDBObject(ptWinInPlan, true); } using (DBText dbText = new DBText()) { dbText.Position = ptWindInArPlan; dbText.TextString = windowKey.First().Value; btrMountPlan.AppendEntity(dbText); //btrMountPlan.Database.TransactionManager.TopTransaction.AddNewlyCreatedDBObject(dbText, true); } } using (var btrArPlan = floorAr.IdBtr.Open(OpenMode.ForWrite) as BlockTableRecord) { using (DBPoint ptWinInArPlan = new DBPoint(ptWindInArPlan)) { ptWinInArPlan.ColorIndex = 1; btrArPlan.AppendEntity(ptWinInArPlan); //btrArPlan.Database.TransactionManager.TopTransaction.AddNewlyCreatedDBObject(ptWinInArPlan, true); } } } #endif } } // Уникальный ключ панели - МаркаСБ + Марки окон string key = panelBase.MarkWithoutElectric; if (panelBase.WindowsBaseCenters.Count > 0) { string windowMarks = string.Join(";", panelBase.WindowsBaseCenters.Values); key += windowMarks; } PanelBase panelBaseUniq; if (!panelsBase.TryGetValue(key, out panelBaseUniq)) { panelsBase.Add(key, panelBase); panelBaseUniq = panelBase; } panelMount.PanelBase = panelBaseUniq; } } return(panelsBase); }
private void addWindows(BlockTableRecord btrPanel, Transaction t) { // все окна и балеоны в панели var windows = Panel.windows?.window?.Select(w => new { posi = w.posi, width = w.width, height = w.height }); var balconys = Panel.balconys?.balcony?.Select(b => new { posi = b.posi, width = b.width, height = b.height }); var apertures = balconys==null? windows: windows?.Union(balconys)?? balconys; if (apertures != null) { foreach (var item in apertures) { // контур окон Polyline plWindow = new Polyline(); plWindow.LayerId = Service.Env.IdLayerContourPanel; Point2d ptMinWindow = new Point2d(item.posi.X, item.posi.Y); plWindow.AddVertexAt(0, ptMinWindow, 0, 0, 0); plWindow.AddVertexAt(0, new Point2d(ptMinWindow.X, ptMinWindow.Y + item.height), 0, 0, 0); Point2d ptMaxWindow = new Point2d(ptMinWindow.X + item.width, ptMinWindow.Y + item.height); plWindow.AddVertexAt(0, ptMaxWindow, 0, 0, 0); plWindow.AddVertexAt(0, new Point2d(ptMinWindow.X + item.width, ptMinWindow.Y), 0, 0, 0); plWindow.Closed = true; btrPanel.AppendEntity(plWindow); t.AddNewlyCreatedDBObject(plWindow, true); // добавление точек для верхнего образмеривания. PtsForTopDim.Add(ptMinWindow.X); PtsForTopDim.Add(ptMaxWindow.X); Openings.Add(new Extents3d(ptMinWindow.Convert3d(), ptMaxWindow.Convert3d())); // Вставка окон if (WindowsBaseCenters.Count > 0) { var xCenter = item.posi.X + item.width * 0.5; var winMarkMin = WindowsBaseCenters.Where(w => Math.Abs(w.Key.X - xCenter) < 600); if (winMarkMin.Count() > 0) { var winMark = winMarkMin.MinBy(g => (g.Key.X - xCenter)); if (string.IsNullOrWhiteSpace(winMark.Value)) { continue; } // Точка вставки блока окна Point3d ptWin = new Point3d(item.posi.X, item.posi.Y, 0); // Вставка блока окна if (!Service.Env.IdBtrWindow.IsNull) { BlockReference blRefWin = new BlockReference(ptWin, Service.Env.IdBtrWindow); blRefWin.LayerId = Service.Env.IdLayerWindow; btrPanel.AppendEntity(blRefWin); t.AddNewlyCreatedDBObject(blRefWin, true); var resSetDyn = BlockWindow.SetDynBlWinMark(blRefWin, winMark.Value); if (!resSetDyn) { // Добавление текста марки окна DBText dbTextWin = new DBText(); dbTextWin.Position = ptWin; dbTextWin.LayerId = Service.Env.IdLayerWindow; dbTextWin.TextString = winMark.Value; dbTextWin.Height = 180; btrPanel.AppendEntity(dbTextWin); t.AddNewlyCreatedDBObject(dbTextWin, true); } } #if Test // Test else { // Добавление текста марки окна DBText dbTextWin = new DBText(); dbTextWin.Position = ptWin; dbTextWin.LayerId = Service.Env.IdLayerWindow; dbTextWin.TextString = winMark.Value; dbTextWin.Height = 180; btrPanel.AppendEntity(dbTextWin); t.AddNewlyCreatedDBObject(dbTextWin, true); } #endif } } // Сортировка окон слева-направо Openings.Sort((w1, w2) => w1.MinPoint.X.CompareTo(w2.MinPoint.X)); } } }
private void addCheekViewText(bool doTrans, Matrix3d trans, double xMinCheek) { // Текст с именем вида DBText textView = new DBText(); textView.TextString = "Вид А"; textView.Height = 75; Point3d ptTextPos = new Point3d(xMinCheek, panelBase.Height + 170, 0); if (doTrans) { ptTextPos = ptTextPos.TransformBy(trans); ptTextPos = new Point3d(ptTextPos.X - 290, ptTextPos.Y, 0); } textView.Position = ptTextPos; btrDim.AppendEntity(textView); t.AddNewlyCreatedDBObject(textView, true); }
private static void addLayout(Point3d pt,int layout ,double width, double height , BlockTableRecord cs, Transaction t) { // Полилиния контура листа Polyline pl = new Polyline(4); pl.AddVertexAt(0, new Point2d(pt.X, pt.Y), 0, 0, 0); pl.AddVertexAt(1, new Point2d(pt.X +width, pt.Y), 0, 0, 0); pl.AddVertexAt(2, new Point2d(pt.X + width, pt.Y - height), 0, 0, 0); pl.AddVertexAt(3, new Point2d(pt.X, pt.Y-height), 0, 0, 0); pl.Closed = true; pl.SetDatabaseDefaults(); cs.AppendEntity(pl); t.AddNewlyCreatedDBObject(pl, true); // Подпись номера листа var textHeight = height * 0.008; Point3d ptText = new Point3d(pt.X+textHeight*0.5, pt.Y-textHeight*1.5, 0); DBText text = new DBText(); text.SetDatabaseDefaults(); text.Height = textHeight; text.TextStyleId = IdTextStylePik; text.TextString = layout.ToString(); text.Position = ptText; cs.AppendEntity(text); t.AddNewlyCreatedDBObject(text, true); // Layout //createLayout(pl, layout, width, height, t); }
protected override SamplerStatus Sampler(JigPrompts prompts) { PromptPointResult promptPointResult = prompts.AcquirePoint(new JigPromptPointOptions("\r\n请指定下一点:") { Cursor = 3, UseBasePoint = false }); Point3d value = promptPointResult.Value; checked { SamplerStatus result; if (value != this.point3d_1) { double x = this.point3d_2[0].X; int num = 0; int num2 = (int)this.short_0; int num3 = num; Point3d point3d; for (;;) { int num4 = num3; int num5 = num2; if (num4 > num5) { break; } this.double_2 = Math.Min(this.point3d_2[num3].X, this.double_2); this.double_1 = Math.Max(this.point3d_2[num3].X, this.double_1); point3d..ctor(this.point3d_2[num3].X, value.Y, 0.0); Line line = new Line(this.point3d_2[num3], point3d); line.Layer = "Y_引线"; this.entity_0[num3] = line; num3++; } Line line2; DBText dbtext; unchecked { Point3d point3d2; Point3d pointAngle; if (this.double_2 > value.X) { point3d..ctor(this.double_2 - 1000.0 * this.double_0, value.Y, 0.0); point3d2..ctor(this.double_1, value.Y, 0.0); pointAngle = CAD.GetPointAngle(point3d, 50.0 * this.double_0, 90.0); } else { point3d..ctor(this.double_1 + 1000.0 * this.double_0, value.Y, 0.0); point3d2..ctor(this.double_2, value.Y, 0.0); pointAngle..ctor(this.double_1 + 100.0 * this.double_0, value.Y, 0.0); pointAngle = CAD.GetPointAngle(pointAngle, 50.0 * this.double_0, 90.0); } line2 = new Line(point3d2, point3d); line2.Layer = "Y_引线"; dbtext = new DBText(); dbtext.Height = 300.0 * this.double_0; dbtext.WidthFactor = 0.7; dbtext.TextString = "2%%13212"; dbtext.Position = pointAngle; dbtext.Layer = "Y_引注"; } this.entity_0[(int)(this.short_0 + 1)] = dbtext; this.entity_0[(int)(this.short_0 + 2)] = line2; this.point3d_1 = value; result = 0; } else { result = 1; } return(result); } }
private static string SelectPk(string msg) //Указание ПК поперечного профиля { DBText acDbText = new DBText(); Document acDoc = Application.DocumentManager.MdiActiveDocument; //Текущий документ. Editor acDocEd = acDoc.Editor; // Editor текущего документа. Database acDocDb = acDoc.Database; // Database текущего документа. using (Transaction acTrans = acDocDb.TransactionManager.StartTransaction()) // Начало Транзакции. { ReturnIfNullOrEmpty: // Создание TypedValue array для определение параметров фильтра. var acTypedValueArray = new TypedValue[1]; acTypedValueArray.SetValue(new TypedValue((int)DxfCode.Start, "TEXT"), 0); // Параметр фильтра под номером 0. // Assign the filter criteria to a SelectionFilter object var acSelectionFilterObject = new SelectionFilter(acTypedValueArray); // Задание опций выбора объектов. var acSelectionSetOptions = new PromptSelectionOptions { AllowDuplicates = false, RejectObjectsOnLockedLayers = true, SingleOnly = true, MessageForAdding = msg }; // Выбор объектов var acSelectionSetPrompt = acDocEd.GetSelection(acSelectionSetOptions, acSelectionFilterObject); if (acSelectionSetPrompt.Status == PromptStatus.OK) { var acSelectionSet = acSelectionSetPrompt.Value; foreach (SelectedObject acSelectedObject in acSelectionSet) { if (acSelectedObject != null) { var acEnt = acTrans.GetObject(acSelectedObject.ObjectId, OpenMode.ForWrite) as Entity; if (acEnt != null) { acDbText = (DBText)acEnt; } } } } if (acSelectionSetPrompt.Status == PromptStatus.Error) { MessageBox.Show("ПК не выбран, повторите попытку!", myCommands.msgBoxCaption_acVolume, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); goto ReturnIfNullOrEmpty; } if (acSelectionSetPrompt.Status == PromptStatus.Cancel) { //MessageBox.Show("Статус Cancel"); //MessageBox.Show("Выбор пикета отменен!\nТаблица объемов не будет привязана к пикету и не будет учитываться при экспорте объемов в Excel.", "acVolume", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); acTrans.Commit(); return "-1"; } acTrans.Commit(); } //MessageBox.Show("acDBText = " + acDBText.TextString.Trim()); return acDbText.TextString.Trim(); }
public void TcJianTuDuiBi() { int num; int num5; object obj; try { IL_01: ProjectData.ClearProjectError(); num = -2; IL_09: int num2 = 2; Polyline polyline = (Polyline)Class36.smethod_72("选择原配筋简图边框:"); IL_1C: num2 = 3; Class36.smethod_73(polyline.ObjectId); IL_2A: num2 = 4; Polyline polyline2 = (Polyline)Class36.smethod_72("选择新配筋简图边框:"); IL_3D: num2 = 5; Class36.smethod_73(polyline2.ObjectId); IL_4B: num2 = 6; Point3d minPoint = polyline.GeometricExtents.MinPoint; Vector3d vectorTo = minPoint.GetVectorTo(polyline2.GeometricExtents.MinPoint); IL_78: num2 = 7; Point3dCollection point3dCollection = new Point3dCollection(); IL_81: num2 = 8; Point3d minPoint2 = polyline.GeometricExtents.MinPoint; IL_95: num2 = 9; Point3d maxPoint = polyline.GeometricExtents.MaxPoint; IL_AA: num2 = 10; point3dCollection.Add(minPoint2); IL_B7: num2 = 11; Point3dCollection point3dCollection2 = point3dCollection; minPoint..ctor(minPoint2.X, maxPoint.Y, minPoint2.Z); point3dCollection2.Add(minPoint); IL_E0: num2 = 12; point3dCollection.Add(maxPoint); IL_ED: num2 = 13; Point3dCollection point3dCollection3 = point3dCollection; minPoint..ctor(maxPoint.X, minPoint2.Y, minPoint2.Z); point3dCollection3.Add(minPoint); IL_116: num2 = 14; TypedValue[] array = new TypedValue[1]; IL_120: num2 = 15; Array array2 = array; TypedValue typedValue; typedValue..ctor(0, "TEXT"); array2.SetValue(typedValue, 0); IL_13D: num2 = 16; DBObjectCollection dbobjectCollection = 结构分析.WindowPolygon(point3dCollection, array); IL_14A: num2 = 17; IEnumerator enumerator = dbobjectCollection.GetEnumerator(); while (enumerator.MoveNext()) { DBText dbtext = (DBText)enumerator.Current; IL_170: num2 = 18; Application.DoEvents(); IL_178: num2 = 19; TypedValue[] array3 = new TypedValue[2]; IL_183: num2 = 20; Array array4 = array3; typedValue..ctor(0, "TEXT"); array4.SetValue(typedValue, 0); IL_1A1: num2 = 21; Array array5 = array3; typedValue..ctor(8, dbtext.Layer); array5.SetValue(typedValue, 1); IL_1C1: num2 = 22; Point3d entCenter = CAD.GetEntCenter(dbtext); IL_1CD: num2 = 23; entCenter..ctor(entCenter.X + vectorTo.X, entCenter.Y + vectorTo.Y, entCenter.Z + vectorTo.Z); IL_204: num2 = 24; Point3dCollection point3dCollection4 = new Point3dCollection(); IL_20E: num2 = 25; double num3 = dbtext.Height / 3.0; IL_224: num2 = 26; Point3dCollection point3dCollection5 = point3dCollection4; minPoint..ctor(entCenter.X - num3, entCenter.Y - num3, entCenter.Z); point3dCollection5.Add(minPoint); IL_253: num2 = 27; Point3dCollection point3dCollection6 = point3dCollection4; minPoint..ctor(entCenter.X - num3, entCenter.Y + num3, entCenter.Z); point3dCollection6.Add(minPoint); IL_282: num2 = 28; Point3dCollection point3dCollection7 = point3dCollection4; minPoint..ctor(entCenter.X + num3, entCenter.Y + num3, entCenter.Z); point3dCollection7.Add(minPoint); IL_2B1: num2 = 29; Point3dCollection point3dCollection8 = point3dCollection4; minPoint..ctor(entCenter.X + num3, entCenter.Y - num3, entCenter.Z); point3dCollection8.Add(minPoint); IL_2E0: num2 = 30; DBObjectCollection dbobjectCollection2 = 结构分析.CrossingPolygon(point3dCollection4, array3); IL_2EE: num2 = 31; ObjectId objectId = dbobjectCollection2[0].ObjectId; IL_300: num2 = 32; string textString = dbtext.TextString; IL_30C: num2 = 33; string txt = this.GetTxt(objectId); IL_319: num2 = 34; if (Operators.CompareString(textString, txt, false) == 0) { IL_32B: num2 = 35; Class36.smethod_64(objectId); } else { IL_338: num2 = 37; IL_33B: num2 = 38; bool flag = this.StrBiJiao(textString, txt); IL_34A: num2 = 39; if (!flag) { IL_354: num2 = 40; this.method_1(objectId); } else { IL_362: num2 = 42; IL_365: num2 = 43; this.method_0(objectId); } } IL_371: num2 = 46; } if (enumerator is IDisposable) { (enumerator as IDisposable).Dispose(); } IL_394: num2 = 47; Class36.smethod_74(polyline.ObjectId); IL_3A3: num2 = 48; Class36.smethod_74(polyline2.ObjectId); IL_3B2: num2 = 49; Interaction.MsgBox("简图对比完毕!", MsgBoxStyle.OkOnly, null); IL_3C2: goto IL_4E8; IL_3C7: int num4 = num5 + 1; num5 = 0; @switch(ICSharpCode.Decompiler.ILAst.ILLabel[], num4); IL_49F: goto IL_4DD; IL_4A1: num5 = num2; if (num <= -2) { goto IL_3C7; } @switch(ICSharpCode.Decompiler.ILAst.ILLabel[], num); IL_4BA :; } catch when(endfilter(obj is Exception & num != 0 & num5 == 0)) { Exception ex = (Exception)obj2; goto IL_4A1; } IL_4DD: throw ProjectData.CreateProjectError(-2146828237); IL_4E8: if (num5 != 0) { ProjectData.ClearProjectError(); } }
public static void ColneToText() { DBText sourText = null; DBText targetText = null; var doc = Application.DocumentManager.MdiActiveDocument; var peo = new PromptEntityOptions("\n" + CommandStringResources.ResourceManager.GetString("SelectSourceText", GLOBAL.CurrentCulture)); peo.SetRejectMessage("\n" + CommandStringResources.ResourceManager.GetString("ObjectTypeIsNotSupported", GLOBAL.CurrentCulture)); peo.AddAllowedClass(typeof(DBText), false); var per = doc.Editor.GetEntity(peo); if (per.Status != PromptStatus.OK) { return; } var sId = per.ObjectId; using (var tr = doc.TransactionManager.StartTransaction()) { var t = tr.GetObject(sId, OpenMode.ForRead) as DBText; if (t != null) { sourText = t; } } doc.Editor.WriteMessage("\nSource Text Content: " + sourText.TextString); bool continueSelect = true; while (continueSelect) { var peo2 = new PromptEntityOptions("\nSelect Target Text"); peo2.SetRejectMessage("\n" + CommandStringResources.ResourceManager.GetString("ObjectTypeIsNotSupported", GLOBAL.CurrentCulture)); peo2.AddAllowedClass(typeof(DBText), false); var per2 = doc.Editor.GetEntity(peo2); if (per2.Status == PromptStatus.OK) { var tId = per2.ObjectId; using (var tr = doc.TransactionManager.StartTransaction()) { var t = tr.GetObject(tId, OpenMode.ForWrite) as DBText; if (t != null) { targetText = t; } } using (Transaction tr = doc.TransactionManager.StartTransaction()) { var text = tr.GetObject(targetText.ObjectId, OpenMode.ForWrite) as DBText; if (text != null) { text.TextString = sourText.TextString; } tr.Commit(); } } else { continueSelect = false; } } }
public void LDel() { string text = Interaction.InputBox("输入编号调整的起始号(比如KL*或者LL*等):", "田草结构工具箱.Net版", "KL2", -1, -1); checked { short num = (short)Math.Round(NF.CVal(text)); string text2 = this.LiangMing(text); short num2; if (Strings.InStr(text, "/", CompareMethod.Binary) > 0) { num2 = (short)Math.Round(NF.CVal(text.Substring(Strings.InStr(text, "/", CompareMethod.Binary)))); } Document mdiActiveDocument = Application.DocumentManager.MdiActiveDocument; Database database = mdiActiveDocument.Database; TypedValue[] array = new TypedValue[1]; Array array2 = array; TypedValue typedValue; typedValue..ctor(0, "TEXT"); array2.SetValue(typedValue, 0); SelectionFilter selectionFilter = new SelectionFilter(array); PromptSelectionResult selection = mdiActiveDocument.Editor.GetSelection(selectionFilter); if (selection.Status == 5100) { SelectionSet value = selection.Value; short num3 = (short)(value.Count - 1); short num4 = 0; short num5 = num3; short num6 = num4; for (;;) { short num7 = num6; short num8 = num5; if (num7 > num8) { break; } using (Transaction transaction = database.TransactionManager.StartTransaction()) { DBText dbtext = (DBText)transaction.GetObject(value[(int)num6].ObjectId, 1); string text3 = dbtext.TextString; if (Operators.CompareString(text3.Substring(0, text2.Length), text2, false) == 0) { short num9 = (short)Math.Round(NF.CVal(text3)); if (num2 == 0) { if (num9 >= num) { text3 = text3.Replace(text2 + num9.ToString(), text2 + ((int)(num9 - 1)).ToString()); dbtext.TextString = text3; } } else if (num9 >= num & num9 <= num2) { text3 = text3.Replace(text2 + num9.ToString(), text2 + ((int)(num9 - 1)).ToString()); dbtext.TextString = text3; } } transaction.Commit(); } unchecked { num6 += 1; } } } database.Regenmode = true; } }
/// <summary> /// Retreive all text data from dwg file and store them in CADModels /// @CreatBridgeForRevit2018 /// </summary> public static List <CADTextModel> GetCADText(string dwgPath) { List <CADTextModel> listCADModels = new List <CADTextModel>(); using (new Services()) { using (Database database = new Database(false, false)) { database.ReadDwgFile(dwgPath, FileShare.Read, true, ""); using (var trans = database.TransactionManager.StartTransaction()) { using (BlockTable table = (BlockTable)database.BlockTableId.GetObject(OpenMode.ForRead)) { using (SymbolTableEnumerator enumerator = table.GetEnumerator()) { StringBuilder sb = new StringBuilder(); while (enumerator.MoveNext()) { using (BlockTableRecord record = (BlockTableRecord)enumerator.Current.GetObject(OpenMode.ForRead)) { foreach (ObjectId id in record) { Entity entity = (Entity)id.GetObject(OpenMode.ForRead, false, false); CADTextModel model = new CADTextModel(); switch (entity.GetRXClass().Name) { case "AcDbText": DBText text = (DBText)entity; model.Location = ConverCADPointToRevitPoint(text.Position); model.Text = text.TextString; Debug.Print(model.Text); model.Angel = text.Rotation; model.Layer = text.Layer; listCADModels.Add(model); break; case "AcDbMText": MText mText = (MText)entity; model.Location = ConverCADPointToRevitPoint(mText.Location); model.Text = mText.Text; model.Angel = mText.Rotation; model.Layer = mText.Layer; listCADModels.Add(model); break; case "AcDbBlockReference": BlockReference br = (BlockReference)entity; AttributeCollection attcol = br.AttributeCollection; foreach (ObjectId attId in attcol) { AttributeReference attRef = (AttributeReference)trans.GetObject(attId, OpenMode.ForRead); if (IsLabel(attRef.TextString)) { model.Text = attRef.TextString; model.Location = ConverCADPointToRevitPoint(br.Position); model.Angel = br.Rotation; model.Layer = br.Layer; listCADModels.Add(model); } } break; } } } } } } } } } return(listCADModels); }
private void paint_Click(object sender, EventArgs e) { this.Hide(); Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database acCurDb = acDoc.Database; using (DocumentLock doclock = acDoc.LockDocument()) { using (Transaction trans = acCurDb.TransactionManager.StartTransaction()) { PromptPointResult pPtRes; PromptPointOptions pPtOpts = new PromptPointOptions(""); pPtOpts.Message = "\nВведи точку: "; pPtRes = acDoc.Editor.GetPoint(pPtOpts); // pPtRes.Value - точка типа Point3D Data.table_x = pPtRes.Value.X - 185; Data.table_y = pPtRes.Value.Y; BlockTableRecord btr; BlockTable bt; DBObjectCollection ObjColl = new DBObjectCollection(); //ObjColl.Add(new Line(new Point3d(Data.table_x, Data.table_y, 0), new Point3d(Data.table_x, Data.table_y, 0))); //Вставили шапку таблицы. ObjColl.Add(new Line(new Point3d(Data.table_x, Data.table_y, 0), new Point3d(Data.table_x + 185, Data.table_y, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x, Data.table_y - 15, 0), new Point3d(Data.table_x + 185, Data.table_y - 15, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x, Data.table_y, 0), new Point3d(Data.table_x, Data.table_y - 15, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 185, Data.table_y, 0), new Point3d(Data.table_x + 185, Data.table_y - 15, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 20, Data.table_y, 0), new Point3d(Data.table_x + 20, Data.table_y - 15, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 130, Data.table_y, 0), new Point3d(Data.table_x + 130, Data.table_y - 15, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 140, Data.table_y, 0), new Point3d(Data.table_x + 140, Data.table_y - 15, 0))); #region Текст в шапке MText objText = new MText(); objText.SetDatabaseDefaults(); objText.Location = new Point3d(Data.table_x + 2, Data.table_y - 1, 0); objText.Contents = "Поз.\nОбозна-\nчение"; objText.TextStyleId = acCurDb.Textstyle; objText.TextHeight = 3; objText.Height = 15; objText.Width = 20; ObjColl.Add(objText); MText objText1 = new MText(); objText1.SetDatabaseDefaults(); objText1.TextStyleId = acCurDb.Textstyle; objText1.TextHeight = 3; objText1.Location = new Point3d(Data.table_x + 65, Data.table_y - 6, 0); objText1.Contents = "Наименование"; objText1.Height = 15; objText1.Width = 110; ObjColl.Add(objText1); MText objText2 = new MText(); objText2.SetDatabaseDefaults(); objText2.TextStyleId = acCurDb.Textstyle; objText2.TextHeight = 3; objText2.Location = new Point3d(Data.table_x + 132, Data.table_y - 6, 0); objText2.Contents = "Кол."; objText2.Height = 15; objText2.Width = 10; ObjColl.Add(objText2); MText objText3 = new MText(); objText3.SetDatabaseDefaults(); objText3.TextStyleId = acCurDb.Textstyle; objText3.TextHeight = 3; objText3.Location = new Point3d(Data.table_x + 143, Data.table_y - 6, 0); objText3.Contents = "Примечание"; objText3.Height = 15; objText3.Width = 45; ObjColl.Add(objText3); #endregion Data.table_y = Data.table_y - 8; double table_xx = Data.table_x, table_yy = Data.table_y - 20; #region Вставляем строки таблицы for (int j = 0; j < dataGridView1.Rows.Count - 1; j++) { Data.table_y = Data.table_y - 7; ObjColl.Add(new Line(new Point3d(Data.table_x, Data.table_y, 0), new Point3d(Data.table_x, Data.table_y - 7, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 20, Data.table_y, 0), new Point3d(Data.table_x + 20, Data.table_y - 7, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 130, Data.table_y, 0), new Point3d(Data.table_x + 130, Data.table_y - 7, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 140, Data.table_y, 0), new Point3d(Data.table_x + 140, Data.table_y - 7, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 185, Data.table_y, 0), new Point3d(Data.table_x + 185, Data.table_y - 7, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x, Data.table_y - 7, 0), new Point3d(Data.table_x + 185, Data.table_y - 7, 0))); DBText acText6 = new DBText(); acText6.SetDatabaseDefaults(); acText6.Height = 3; acText6.Position = new Point3d(Data.table_x + 2, Data.table_y - 5, 0); acText6.TextString = dataGridView1.Rows[j].Cells["Обозначение"].Value.ToString(); ObjColl.Add(acText6); DBText acText7 = new DBText(); acText7.SetDatabaseDefaults(); acText7.Height = 3; acText7.Position = new Point3d(Data.table_x + 21, Data.table_y - 5, 0); acText7.TextString = dataGridView1.Rows[j].Cells["Наименование"].Value.ToString(); ObjColl.Add(acText7); DBText acText8 = new DBText(); acText8.SetDatabaseDefaults(); acText8.Height = 3; acText8.Position = new Point3d(Data.table_x + 132, Data.table_y - 5, 0); acText8.TextString = dataGridView1.Rows[j].Cells["Кол"].Value.ToString(); ObjColl.Add(acText8); DBText acText9 = new DBText(); acText9.SetDatabaseDefaults(); acText9.Height = 3; acText9.Position = new Point3d(Data.table_x + 141, Data.table_y - 5, 0); acText9.TextString = dataGridView1.Rows[j].Cells["Примечание"].Value.ToString(); ObjColl.Add(acText9); } #endregion ObjColl.Add(new Line(new Point3d(Data.table_x, Data.table_y - 7, 0), new Point3d(Data.table_x + 185, Data.table_y - 7, 0))); Database wbd = HostApplicationServices.WorkingDatabase; bt = (BlockTable)trans.GetObject(wbd.BlockTableId, OpenMode.ForRead); btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite); foreach (Entity ent in ObjColl) { btr.AppendEntity(ent); trans.AddNewlyCreatedDBObject(ent, true); } trans.Commit(); trans.Dispose(); } } this.Show(); }
public AC_DBText(DBText text) { this.ObjectId = text.ObjectId; this.BaseDBText = text; }
// ����ͼ�� public void SetData( ) { string stmplate = string.Empty; stmplate = GetRbCheck(); Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; DocumentLock docLock = doc.LockDocument(); Editor ed = doc.Editor; string PathName = @"\\172.16.7.55\dt$\" + stmplate + ".dwg"; ed.WriteMessage(PathName); try { using (Database dbsource = new Database(false, false)) { dbsource.ReadDwgFile(PathName, System.IO.FileShare.Read, true, null); PromptPointOptions pmops = new PromptPointOptions("please select a point :"); PromptPointResult pmres; pmres = ed.GetPoint(pmops); Point3d insertPt = pmres.Value; ed.WriteMessage(insertPt[0].ToString()); ObjectId blockId = ObjectId.Null; using (Transaction tr = db.TransactionManager.StartTransaction()) { #region ����ѡ��ͼ�����ͣ���������Ϣ������ͼ��� //7�ֱ���+5��ֻ����ͼ�źͰ汾=12 if (stmplate == "A4����" || stmplate == "A3����" || stmplate == "A2����" || stmplate == "A1����" || stmplate == "A0����" || stmplate == "��֪ͨ��" || stmplate == "��֪ͨ��(�Ӽ�)" || stmplate == "A4���ݱ����" || stmplate == "A3���ݱ����" || stmplate == "A2���ݱ����" || stmplate == "A1���ݱ����" || stmplate == "A0���ݱ����") { blockId = db.Insert("tk", dbsource, false); BlockTableRecord btupdate = (BlockTableRecord)tr.GetObject(blockId, OpenMode.ForWrite); foreach (ObjectId otmp in btupdate) { DBObject dbo = tr.GetObject(otmp, OpenMode.ForWrite); if (dbo is Autodesk.AutoCAD.DatabaseServices.DBText) { DBText mText = (DBText)dbo; switch (mText.TextString) { case "Input Project Name Here": mText.TextString = lblpfullname.Text; break; case "Input Owner Here": mText.TextString = lblowner.Text; break; case "YRO***-***-***": mText.TextString = txtDrawNo.Text; break; case "0": mText.TextString = txtRev.Text; break; } } else if (dbo is Autodesk.AutoCAD.DatabaseServices.MText) { MText mText = (MText)dbo; switch (mText.Contents) { case "ͼֽ����": mText.Contents = lblname1.Text; break; case "Input Title Here": mText.Contents = lblname2.Text; break; case "Input Class Here": mText.Contents = lblclass.Text; break; } } } if (stmplate == "A4����" || stmplate == "A3����" || stmplate == "A2����" || stmplate == "A1����" || stmplate == "A0����" || stmplate == "��֪ͨ��" || stmplate == "��֪ͨ��(�Ӽ�)") { double qtnum = 0.0; ; if (stmplate == "A4����" || stmplate == "��֪ͨ��(�Ӽ�)" || stmplate == "��֪ͨ��") qtnum = 63.3; else if (stmplate == "A2����" || stmplate == "A1����" || stmplate == "A0����") qtnum = 68.5; else qtnum = 66.3; Point3d insertionPointnums = new Point3d(0, 0, 0); DBText txt = new DBText(); try { if (yt != "") { insertionPointnums = new Point3d(19, qtnum - 4.5, 0); txt = new DBText(); txt.TextString = yt; txt.Position = insertionPointnums; btupdate.AppendEntity(txt); tr.AddNewlyCreatedDBObject(txt, true); } if (hy != "") { insertionPointnums = new Point3d(19, qtnum - 4.5 * 2, 0); txt = new DBText(); txt.TextString = hy; txt.Position = insertionPointnums; btupdate.AppendEntity(txt); tr.AddNewlyCreatedDBObject(txt, true); } if (lk != "") { insertionPointnums = new Point3d(19, qtnum - 4.5 * 3, 0); txt.TextString = lk; txt.Position = insertionPointnums; btupdate.AppendEntity(txt); tr.AddNewlyCreatedDBObject(txt, true); } if (om != "") { insertionPointnums = new Point3d(19, qtnum - 4.5 * 4, 0); txt.TextString = om; txt.Position = insertionPointnums; btupdate.AppendEntity(txt); tr.AddNewlyCreatedDBObject(txt, true); } if (qc != "") { insertionPointnums = new Point3d(19, qtnum - 4.5 * 5, 0); txt = new DBText(); txt.TextString = qc; txt.Position = insertionPointnums; btupdate.AppendEntity(txt); tr.AddNewlyCreatedDBObject(txt, true); } if (xm != "") { insertionPointnums = new Point3d(19, qtnum - 4.5 * 6, 0); txt = new DBText(); txt.TextString = xm; txt.Position = insertionPointnums; btupdate.AppendEntity(txt); tr.AddNewlyCreatedDBObject(txt, true); } if (pc != "") { insertionPointnums = new Point3d(19, qtnum - 4.5 * 7, 0); txt.TextString = om; txt.Position = insertionPointnums; btupdate.AppendEntity(txt); tr.AddNewlyCreatedDBObject(txt, true); } if (total != "") { insertionPointnums = new Point3d(19, qtnum - 4.5 * 9, 0); txt = new DBText(); txt.TextString = total; txt.Position = insertionPointnums; btupdate.AppendEntity(txt); tr.AddNewlyCreatedDBObject(txt, true); } } catch (Autodesk.AutoCAD.Runtime.Exception re) { MessageBox.Show(re.Message); } } } //else if (stmplate == "��·СƱ�����" || stmplate == "��֪ͨ��A4�����" || stmplate == "��֪ͨ��A3�����") { } BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead); BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite); BlockReference bref = new BlockReference(insertPt, blockId); btr.AppendEntity(bref); tr.AddNewlyCreatedDBObject(bref, true); tr.Commit(); // bref.ExplodeToOwnerSpace(); #endregion } } #region �����ӡ��¼ string sp = string.Empty; sp = cmbproject.Text + ";" + txtDrawNo.Text + ";" + txtRev.Text + ";" + yt + ";" + hy + ";" + lk + ";" + om + ";" + qc + ";" + xm + ";" + pc + ";" + total; if (pi.GetDrawingPrintAddQuota(sp) != "0") MessageBox.Show("�Ѳ���ͼ��ģ�壬������˴�ͼ�ŵĴ�ӡ����"); #endregion } catch (System.Exception et) { MessageBox.Show(et.Message); } finally { docLock.Dispose(); this.Show(); } }
public static void DrawShape(PosShape shape, Point3d inspt, double height) { Extents3d? bounds = shape.Bounds; if (!bounds.HasValue) return; Point3d p1 = bounds.Value.MinPoint; Point3d p2 = bounds.Value.MaxPoint; double scale = height / (p2.Y - p1.Y); Matrix3d trans = Matrix3d.AlignCoordinateSystem(p1, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, inspt, Vector3d.XAxis * scale, Vector3d.YAxis * scale, Vector3d.ZAxis * scale); Database db = HostApplicationServices.WorkingDatabase; using (Transaction tr = db.TransactionManager.StartTransaction()) { try { BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite); Point3dCollection vertices = new Point3dCollection(new Point3d[]{ new Point3d(p1.X, p1.Y, 0), new Point3d(p2.X, p1.Y, 0), new Point3d(p2.X, p2.Y, 0), new Point3d(p1.X, p2.Y, 0), }); Polyline2d rec = new Polyline2d(Poly2dType.SimplePoly, vertices, 0, true, 0, 0, null); rec.TransformBy(trans); btr.AppendEntity(rec); tr.AddNewlyCreatedDBObject(rec, true); ObjectId hiddenLayer = PosUtility.DefpointsLayer; foreach (PosShape.Shape item in shape.Items) { Entity en = null; if (item is PosShape.ShapeLine) { PosShape.ShapeLine line = (PosShape.ShapeLine)item; en = new Line(new Point3d(line.X1, line.Y1, 0), new Point3d(line.X2, line.Y2, 0)); } else if (item is PosShape.ShapeArc) { PosShape.ShapeArc arc = (PosShape.ShapeArc)item; en = new Arc(new Point3d(arc.X, arc.Y, 0), arc.R, arc.StartAngle, arc.EndAngle); } else if (item is PosShape.ShapeCircle) { PosShape.ShapeCircle circle = (PosShape.ShapeCircle)item; en = new Circle(new Point3d(circle.X, circle.Y, 0), Vector3d.ZAxis, circle.R); } else if (item is PosShape.ShapeText) { PosShape.ShapeText text = (PosShape.ShapeText)item; DBText dbobj = new DBText(); dbobj.TextString = text.Text; dbobj.Position = new Point3d(text.X, text.Y, 0); dbobj.TextStyleId = PosUtility.CreateTextStyle("ShapeDump_" + shape.Name, text.Font, text.Width); dbobj.Height = text.Height; dbobj.WidthFactor = text.Width; dbobj.HorizontalMode = text.HorizontalAlignment; if (text.VerticalAlignment == TextVerticalMode.TextBottom) dbobj.VerticalMode = TextVerticalMode.TextBase; else dbobj.VerticalMode = text.VerticalAlignment; if (dbobj.HorizontalMode != TextHorizontalMode.TextLeft || dbobj.VerticalMode != TextVerticalMode.TextBase) { dbobj.AlignmentPoint = new Point3d(text.X, text.Y, 0); } en = dbobj; } if (en != null) { en.Color = item.Color; if (!item.Visible) en.LayerId = hiddenLayer; en.TransformBy(trans); btr.AppendEntity(en); tr.AddNewlyCreatedDBObject(en, true); } } tr.Commit(); } catch (System.Exception ex) { System.Windows.Forms.MessageBox.Show("Error: " + ex.Message, "RebarPos", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } } }
private Tuple <double, double> CalculateArea(Transaction t, Polyline p1, Polyline p2) { Point3d startPoint1; Point3d startPoint2; if (p1.StartPoint.X > p2.StartPoint.X) { startPoint2 = p2.GetClosestPointTo(p1.StartPoint, Vector3d.YAxis, true); startPoint1 = p1.StartPoint; } else { startPoint1 = p1.GetClosestPointTo(p2.StartPoint, Vector3d.YAxis, true); startPoint2 = p2.StartPoint; } Point3d endPoint1; Point3d endPoint2; if (p1.EndPoint.X < p2.EndPoint.X) { endPoint2 = p2.GetClosestPointTo(p1.EndPoint, Vector3d.YAxis, true); endPoint1 = p1.EndPoint; } else { endPoint1 = p1.GetClosestPointTo(p2.EndPoint, Vector3d.YAxis, true); endPoint2 = p2.EndPoint; } var btr = (BlockTableRecord)t.GetObject(Db.CurrentSpaceId, OpenMode.ForWrite); var pts = new Point3dCollection(); p1.IntersectWith(p2, Intersect.OnBothOperands, pts, IntPtr.Zero, IntPtr.Zero); var interArray = new Point3d[pts.Count]; pts.CopyTo(interArray, 0); var interList = interArray.ToList(); interList.Sort((pt1, pt2) => (int)Math.Floor(pt1.X - pt2.X)); var interQueue = new Queue <Point3d>(interList); var cutArea = 0.0; var fillArea = 0.0; var curPolyline = new Polyline(); var VertexYSum = 0.0; var curInd = 1; var curInterPt = interQueue.Count > 0? interQueue.Dequeue() : endPoint1; var i2 = 0; curPolyline.AddVertexAt(0, new Point2d(startPoint1.X, startPoint1.Y), 0, 0, 0); VertexYSum += startPoint1.Y; curPolyline.AddVertexAt(1, new Point2d(startPoint2.X, startPoint2.Y), 0, 0, 0); for (var i = 0; i < p1.NumberOfVertices; i++) { // Could also get the 3D point here var pt = p1.GetPoint2dAt(i); if (pt.X <= startPoint1.X) { continue; } if (pt.X > curInterPt.X) { var vertexAvY = VertexYSum / curInd; curPolyline.AddVertexAt(curInd++, new Point2d(curInterPt.X, curInterPt.Y), 0, 0, 0); if (curInterPt == endPoint1) { curPolyline.AddVertexAt(curInd++, new Point2d(endPoint2.X, endPoint2.Y), 0, 0, 0); } var reverseList = new List <Point2d>(); for (; i2 < p2.NumberOfVertices; i2++) { var pt2 = p2.GetPoint2dAt(i2); if (pt.X <= startPoint1.X) { continue; } if (pt2.X <= curInterPt.X) { reverseList.Add(pt2); } if (pt2.X >= curInterPt.X) { reverseList.Reverse(); var vertexYSum2 = 0.0; reverseList.ForEach(p => { curPolyline.AddVertexAt(curInd++, p, 0, 0, 0); vertexYSum2 += pt.Y; }); var vertexAvY2 = vertexYSum2 / reverseList.Count; curPolyline.Closed = true; var isCut = vertexAvY < vertexAvY2; if (isCut) { cutArea += curPolyline.Area; } else { fillArea += curPolyline.Area; } var lPoint = CalculateMedianPoint(curPolyline); var label = new DBText { TextString = curPolyline.Area.ToString("N", new NumberFormatInfo() { NumberDecimalDigits = 2 }), Height = 0.2, Position = new Point3d(lPoint.X, lPoint.Y, 0) }; btr.AppendEntity(label); t.AddNewlyCreatedDBObject(label, true); if (curInterPt == endPoint1) { return(new Tuple <double, double>(cutArea, fillArea)); } curPolyline = new Polyline(); VertexYSum = 0; curInd = 1; curPolyline.AddVertexAt(0, new Point2d(curInterPt.X, curInterPt.Y), 0, 0, 0); VertexYSum += curInterPt.Y; curInterPt = interQueue.Count > 0 ? interQueue.Dequeue() : endPoint1; break; } } } curPolyline.AddVertexAt(curInd++, pt, 0, 0, 0); VertexYSum += pt.Y; } return(new Tuple <double, double>(cutArea, fillArea)); }
public static void DrawOrDiscardEntity(BlockTableRecord btr, Transaction tx, Matrix3d transform, Svg.SvgGroup group)//, int upscale) { foreach (oid oid in btr) { switch (oid.ObjectClass.Name) { case "AcDbLine": //prdDbg(oid.ObjectClass.Name); Line line = oid.Go <Line>(tx); using (Line newLine = new Line(line.StartPoint, line.EndPoint)) { newLine.TransformBy(transform); SvgLine sline = new Svg.SvgLine { StartX = ts(newLine.StartPoint.X), StartY = ts(-newLine.StartPoint.Y), EndX = ts(newLine.EndPoint.X), EndY = ts(-newLine.EndPoint.Y), StrokeWidth = ts(0.1), Stroke = new Svg.SvgColourServer(System.Drawing.Color.Black) }; //if (flip != Flip.PP) //{ // sline.Transforms = AddTransforms(flip, // sline.StartX + sline.EndX, // sline.StartY + sline.EndY); //} group.Children.Add(sline); //mSpc.AppendEntity(newLine); //tx.AddNewlyCreatedDBObject(newLine, true); } break; case "AcDbPolyline": //prdDbg(oid.ObjectClass.Name); Polyline pline = oid.Go <Polyline>(tx); using (Polyline newPline = new Polyline(pline.NumberOfVertices)) { for (int i = 0; i < pline.NumberOfVertices; i++) { newPline.AddVertexAt(i, pline.GetPoint2dAt(i), 0, 0, 0); } newPline.TransformBy(transform); Extents3d bbox = newPline.GeometricExtents; //Prepare for Svg.Transforms SvgPointCollection pcol = new SvgPointCollection(); for (int i = 0; i < newPline.NumberOfVertices; i++) { Point2d p2d = newPline.GetPoint2dAt(i); pcol.Add(ts(p2d.X)); pcol.Add(ts(-p2d.Y)); } SvgPolyline sPline = new SvgPolyline(); sPline.Points = pcol; if (pline.NumberOfVertices == 2) { sPline.StrokeWidth = ts(0.1); sPline.Stroke = new SvgColourServer(System.Drawing.Color.Black); } else { sPline.Fill = new SvgColourServer(System.Drawing.Color.Black); } //if (flip != Flip.PP) //{ // sPline.Transforms = AddTransforms(flip, // ts(bbox.MinPoint.X + bbox.MaxPoint.X), // ts(bbox.MinPoint.Y + bbox.MaxPoint.Y)); //} group.Children.Add(sPline); } break; case "AcDbCircle": //prdDbg(oid.ObjectClass.Name); Circle circle = oid.Go <Circle>(tx); using (Circle newCircle = new Circle()) { newCircle.SetDatabaseDefaults(); newCircle.Center = circle.Center; newCircle.Radius = circle.Radius; newCircle.TransformBy(transform); SvgCircle sCircle = new Svg.SvgCircle { CenterX = ts(newCircle.Center.X), CenterY = ts(-newCircle.Center.Y), Radius = ts(newCircle.Radius), Fill = new Svg.SvgColourServer(System.Drawing.Color.Black), }; //if (flip != Flip.PP) //{ // sCircle.Transforms = AddTransforms(flip, // 2 * sCircle.CenterX, // 2 * sCircle.CenterY); //} group.Children.Add(sCircle); //mSpc.AppendEntity(newCircle); //tx.AddNewlyCreatedDBObject(newCircle, true); } break; case "AcDbMText": prdDbg(oid.ObjectClass.Name); MText mText = oid.Go <MText>(tx); string text = mText.Contents; using (DBText newText = new DBText()) { newText.SetDatabaseDefaults(); newText.TextString = text; newText.Position = mText.Location; newText.Rotation = mText.Rotation; //newText.TransformBy(transform); SvgText sText = new SvgText(newText.TextString); prdDbg(ts(newText.Position.X).ToString()); prdDbg(ts(newText.Position.Y).ToString()); sText.X.Add(ts(newText.Position.X)); sText.Y.Add(ts(newText.Position.Y + 0.1)); sText.FontFamily = "Arial"; sText.FontSize = ts(0.50); prdDbg(ts(newText.Rotation * (180 / Math.PI)).ToString()); sText.Rotate = ts(newText.Rotation * (180 / Math.PI)).ToString(); sText.Fill = new SvgColourServer(System.Drawing.Color.Black); group.Children.Add(sText); } break; case "AcDbBlockReference": DrawOrDiscardEntity(tx.GetObject(oid, OpenMode.ForRead) as BlockReference, tx, group); //, upscale); break; default: //prdDbg("Not implemented: " + oid.ObjectClass.Name); break; } } }
//public void DefYForUpperAndParapetStorey() //{ // // определение уровней для Ч и П этажей в этом фасаде // // уровеь последнего этажа в фасаде // var floorsNumberType = Floors.Where(f => f.Storey.Type == EnumStorey.Number); // double yLastNumberFloor = 0; // if (floorsNumberType.Count() > 0) // { // yLastNumberFloor = floorsNumberType.Max(f => f.Storey.Y); // } // // чердак // // double yParapet = 0; // var floorUpper = Floors.Where(f => f.Storey.Type == EnumStorey.Upper).FirstOrDefault(); // if (floorUpper != null) // { // //var maxHeightPanel = floorUpper.PanelsSbInFront.Where(p => p.PanelAkr != null)?.Max(p => p.PanelAkr?.HeightPanelByTile); // //if (maxHeightPanel.HasValue) // //{ // floorUpper.Storey.Y = yLastNumberFloor + Settings.Default.FacadeFloorHeight; // //yParapet = floorUpper.Storey.Y + maxHeightPanel.Value; // //floorUpper.Height = maxHeightPanel.Value; // //} // } // var floorParapet = Floors.Where(f => f.Storey.Type == EnumStorey.Parapet).FirstOrDefault(); // if (floorParapet != null) // { // yParapet = yParapet != 0 ? yParapet : yLastNumberFloor + Settings.Default.FacadeFloorHeight; // floorParapet.Storey.Y = yParapet; // var maxHeightPanel = floorParapet.PanelsSbInFront.Where(p => p.PanelAkr != null)?.Max(p => p.PanelAkr?.HeightPanelByTile); // if (maxHeightPanel.HasValue) // { // floorParapet.Height = maxHeightPanel.Value; // } // } //} private static void captionFloor(double x, double yFloor, FloorMounting floor, BlockTableRecord ms, Transaction t) { // Подпись номера этажа DBText textFloor = new DBText(); textFloor.SetDatabaseDefaults(ms.Database); textFloor.Annotative = AnnotativeStates.False; textFloor.Height = Settings.Default.FacadeCaptionFloorTextHeight;// 250;// FacadeCaptionFloorTextHeight textFloor.TextString = floor.Storey.ToString(); var height =floor.Storey.Height != 0? floor.Storey.Height: 2000; textFloor.Position = new Point3d(x - Settings.Default.FacadeCaptionFloorIndent, yFloor + (height * 0.5), 0); ms.AppendEntity(textFloor); t.AddNewlyCreatedDBObject(textFloor, true); }
private static DBText addText(BlockTableRecord btr, Transaction t, Point3d pt, string value, double height, TextHorizontalMode horMode = TextHorizontalMode.TextCenter) { // Подпись развертки - номер вида DBText text = new DBText(); text.SetDatabaseDefaults(); text.Height = height; text.TextStyleId = IdTextStylePik; text.TextString = value; if (horMode == TextHorizontalMode.TextLeft) { text.Position = pt; } else { text.HorizontalMode = horMode; text.AlignmentPoint = pt; text.AdjustAlignment(btr.Database); } btr.AppendEntity(text); t.AddNewlyCreatedDBObject(text, true); return text; }
public void TcWuMian() { int num; int num18; object obj; try { IL_01: ProjectData.ClearProjectError(); num = -2; IL_09: int num2 = 2; long[] array = null; IL_0D: num2 = 3; Document mdiActiveDocument = Application.DocumentManager.MdiActiveDocument; IL_1A: num2 = 4; Database database = mdiActiveDocument.Database; IL_24: num2 = 5; using (Transaction transaction = database.TransactionManager.StartTransaction()) { TypedValue[] array2 = new TypedValue[1]; Array array3 = array2; TypedValue typedValue; typedValue..ctor(0, "TEXT"); array3.SetValue(typedValue, 0); SelectionFilter selectionFilter = new SelectionFilter(array2); Class36.smethod_60("请按照顺序选择>"); PromptSelectionResult selection = mdiActiveDocument.Editor.GetSelection(selectionFilter); short num3; double num9; Point3d[] array4; short num15; checked { short num6; if (selection.Status == 5100) { SelectionSet value = selection.Value; num3 = (short)(value.Count - 1); array = new long[(int)(num3 + 1)]; short num4 = 0; short num5 = num3; num6 = num4; for (;;) { short num7 = num6; short num8 = num5; if (num7 > num8) { break; } DBText dbtext = (DBText)transaction.GetObject(value[(int)num6].ObjectId, 1); array[(int)num6] = (long)Math.Round(Conversion.Val(dbtext.TextString)); unchecked { num6 += 1; } } } num9 = Class36.smethod_30("请输入跨度(默认6000):", 6000.0); array4 = new Point3d[(int)(num3 + 1)]; array4[0] = CAD.GetPoint("选择插入点: "); Point3d point3d; if (array4[0] == point3d) { goto IL_5A1; } short num10 = 0; short num11 = (short)(Information.UBound(array, 1) - 1); num6 = num10; Point3d pointAngle; for (;;) { short num12 = num6; short num8 = num11; if (num12 > num8) { break; } pointAngle = CAD.GetPointAngle(array4[(int)num6], num9, 0.0); CAD.AddLine(array4[(int)num6], pointAngle, "0"); array4[(int)(num6 + 1)] = CAD.GetPointAngle(array4[(int)num6], (double)array[(int)num6], 270.0); unchecked { num6 += 1; } } pointAngle = CAD.GetPointAngle(array4[(int)num6], num9, 0.0); CAD.AddLine(array4[(int)num6], pointAngle, "0"); Point3d[] array5 = new Point3d[4]; Point3d[] array6 = new Point3d[4]; pointAngle = CAD.GetPointAngle(array4[0], num9, 0.0); array5[0] = CAD.GetPointAngle(array4[0], 200.0, 45.0); array5[1] = CAD.GetPointAngle(array4[0], 200.0, 315.0); array6[0] = CAD.GetPointAngle(pointAngle, 200.0, 135.0); array6[1] = CAD.GetPointAngle(pointAngle, 200.0, 225.0); pointAngle = CAD.GetPointAngle(array4[1], num9, 0.0); Point3d p = Class36.smethod_46(array4[1], pointAngle); array5[2] = CAD.GetPointAngle(p, 200.0, 135.0); array5[3] = CAD.GetPointAngle(p, 200.0, 225.0); array6[2] = CAD.GetPointAngle(p, 200.0, 45.0); array6[3] = CAD.GetPointAngle(p, 200.0, 315.0); Point3d pointAngle2 = CAD.GetPointAngle(p, 141.0, 90.0); Point3d pointAngle3 = CAD.GetPointAngle(p, (double)(array[0] + 141L), 270.0); CAD.AddPline(array5, 0.0, false, ""); CAD.AddPline(array6, 0.0, false, ""); CAD.AddLine(pointAngle2, pointAngle3, "0"); short num13 = (short)Math.Round(unchecked ((double)Information.UBound(array, 1) / 2.0 - 1.0)); short num14 = 1; num15 = num13 - 1; num3 = num14; } for (;;) { short num16 = num3; short num8 = num15; if (num16 > num8) { break; } Point3d pointAngle = CAD.GetPointAngle(array4[(int)num3], num9 / 2.0 + Math.Pow(-1.0, (double)num3) * 70.0, 0.0); Point3d pointAngle4 = CAD.GetPointAngle(pointAngle, (double)array[(int)num3], 270.0); CAD.AddLine(pointAngle, pointAngle4, "0"); num3 += 1; } transaction.Commit(); } IL_4FC: num2 = 7; if (Information.Err().Number <= 0) { goto IL_521; } IL_50D: num2 = 8; Interaction.MsgBox(Information.Err().Description, MsgBoxStyle.OkOnly, null); IL_521: goto IL_5A1; IL_523: int num17 = num18 + 1; num18 = 0; @switch(ICSharpCode.Decompiler.ILAst.ILLabel[], num17); IL_55B: goto IL_596; IL_55D: num18 = num2; if (num <= -2) { goto IL_523; } @switch(ICSharpCode.Decompiler.ILAst.ILLabel[], num); IL_573 :; } catch when(endfilter(obj is Exception & num != 0 & num18 == 0)) { Exception ex = (Exception)obj2; goto IL_55D; } IL_596: throw ProjectData.CreateProjectError(-2146828237); IL_5A1: if (num18 != 0) { ProjectData.ClearProjectError(); } }
public ObjectId createTextGroup(ObjectIdCollection texts) { DBObjectCollection DbTexts = new DBObjectCollection(); foreach (ObjectId txt in texts) { DBText text = tr.openObject(txt, OpenMode.ForWrite) as DBText; text.Erase(true); DBText nTxt = new DBText(); nTxt.Justify = text.Justify; nTxt.Height = text.Height; nTxt.TextString = text.TextString; nTxt.Rotation = text.Rotation; nTxt.AlignmentPoint = text.AlignmentPoint; tr.closeObject(); DbTexts.Add(nTxt); } return tr.addGroup(GUID, DbTexts,false); }
Point3dCollection ReadPoints(IEnumerable <ObjectId> items, double maxSpacing) { Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; HashSet <Point3d> points = new HashSet <Point3d>(new Point3dComparer(new Tolerance(maxSpacing, maxSpacing))); using (Transaction tr = db.TransactionManager.StartTransaction()) { try { foreach (ObjectId id in items) { // Point if (SelectPoints && id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(DBPoint)).UnmanagedObject) { DBPoint item = (DBPoint)tr.GetObject(id, OpenMode.ForRead); points.Add(item.Position); } // Line else if (SelectLines && id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(Line)).UnmanagedObject) { Line item = (Line)tr.GetObject(id, OpenMode.ForRead); points.Add(item.StartPoint); points.Add(item.EndPoint); } // LW Polyline else if (SelectPolylines && id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(Polyline)).UnmanagedObject) { Polyline item = (Polyline)tr.GetObject(id, OpenMode.ForRead); for (int i = 0; i < item.NumberOfVertices; i++) { points.Add(item.GetPoint3dAt(i)); } } // 2D Polyline else if (SelectPolylines && id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(Polyline2d)).UnmanagedObject) { Polyline2d item = (Polyline2d)tr.GetObject(id, OpenMode.ForRead); foreach (ObjectId vId in item) { Vertex2d vertex = (Vertex2d)tr.GetObject(vId, OpenMode.ForRead); points.Add(vertex.Position); } } // 3D Polyline else if (SelectPolylines && id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(Polyline3d)).UnmanagedObject) { Polyline3d item = (Polyline3d)tr.GetObject(id, OpenMode.ForRead); foreach (ObjectId vId in item) { PolylineVertex3d vertex = (PolylineVertex3d)tr.GetObject(vId, OpenMode.ForRead); points.Add(vertex.Position); } } // Text else if (SelectTexts && id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(DBText)).UnmanagedObject) { DBText item = (DBText)tr.GetObject(id, OpenMode.ForRead); points.Add(item.Position); } // Text with Z else if (SelectTextsWithZ && id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(DBText)).UnmanagedObject) { DBText item = (DBText)tr.GetObject(id, OpenMode.ForRead); if (double.TryParse(item.TextString, out double z)) { Point3d pt = item.Position; points.Add(new Point3d(pt.X, pt.Y, z)); } } // Blocks else if (SelectBlocks && id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(BlockReference)).UnmanagedObject) { BlockReference item = (BlockReference)tr.GetObject(id, OpenMode.ForRead); points.Add(item.Position); } // 3DFace else if (Select3DFace && id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(Face)).UnmanagedObject) { Face item = (Face)tr.GetObject(id, OpenMode.ForRead); points.Add(item.GetVertexAt(0)); points.Add(item.GetVertexAt(1)); points.Add(item.GetVertexAt(2)); points.Add(item.GetVertexAt(3)); } // PolyFaceMesh else if (SelectPolyfaceMesh && id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(PolyFaceMesh)).UnmanagedObject) { PolyFaceMesh item = (PolyFaceMesh)tr.GetObject(id, OpenMode.ForRead); foreach (ObjectId faceId in item) { DBObject obj = tr.GetObject(faceId, OpenMode.ForRead); if (obj is PolyFaceMeshVertex vertex) { points.Add(vertex.Position); } } } // Solid (2D) else if (SelectSolid && id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(Solid)).UnmanagedObject) { Solid item = (Solid)tr.GetObject(id, OpenMode.ForRead); points.Add(item.GetPointAt(0)); points.Add(item.GetPointAt(1)); points.Add(item.GetPointAt(3)); points.Add(item.GetPointAt(2)); } } } catch (System.Exception ex) { MessageBox.Show("Error: " + ex.ToString(), "XCOM", MessageBoxButtons.OK, MessageBoxIcon.Error); } tr.Commit(); } if (points.Count == 0) { return(new Point3dCollection()); } else { return(new Point3dCollection(points.ToArray())); } }
private static void placementAparts(Database db) { using (var t = db.TransactionManager.StartTransaction()) { ObjectId idTextStylePik = db.GetTextStylePIK(); var bt = db.BlockTableId.GetObject(OpenMode.ForRead) as BlockTable; var ms = bt[BlockTableRecord.ModelSpace].GetObject(OpenMode.ForWrite) as BlockTableRecord; int countAparts; var btrApartGroups = getGroupedAparts(bt, out countAparts); Point3d pt = Point3d.Origin; Point3d ptCenterPlace; using (var progress = new ProgressMeter()) { progress.SetLimit(countAparts); progress.Start("Расстановка квартир..."); foreach (var btrApartGroup in btrApartGroups) { progress.MeterProgress(); foreach (var idBtrApart in btrApartGroup) { var curPlaceWidth = placeWidth; var blRefApart = new BlockReference(pt, idBtrApart); blRefApart.SetDatabaseDefaults(db); var extApart = blRefApart.GeometricExtents; var lenApart = extApart.MaxPoint.X - extApart.MinPoint.X; if (lenApart > placeWidth) { curPlaceWidth = lenApart + 1000; } ptCenterPlace = new Point3d(pt.X + curPlaceWidth * 0.5, pt.Y - placeHeight * 0.5, 0); var ptBlCenter = extApart.Center(); // Перемещение блока в центр прямоугольной области Matrix3d displace = Matrix3d.Displacement(ptCenterPlace - ptBlCenter); blRefApart.TransformBy(displace); ms.AppendEntity(blRefApart); t.AddNewlyCreatedDBObject(blRefApart, true); // Подпись квартиры DBText text = new DBText(); text.SetDatabaseDefaults(); text.TextStyleId = idTextStylePik; text.Height = 900; text.TextString = getApartName(blRefApart.Name); text.Position = new Point3d(pt.X + 300, pt.Y + 300, 0); ms.AppendEntity(text); t.AddNewlyCreatedDBObject(text, true); // Прямоугольник расположения квартиры Polyline pl = new Polyline(4); pl.AddVertexAt(0, pt.Convert2d(), 0, 0, 0); pl.AddVertexAt(1, new Point2d(pt.X + curPlaceWidth, pt.Y), 0, 0, 0); pl.AddVertexAt(2, new Point2d(pt.X + curPlaceWidth, pt.Y - placeHeight), 0, 0, 0); pl.AddVertexAt(3, new Point2d(pt.X, pt.Y - placeHeight), 0, 0, 0); pl.Closed = true; pl.SetDatabaseDefaults(); ms.AppendEntity(pl); t.AddNewlyCreatedDBObject(pl, true); pt = new Point3d(pt.X + curPlaceWidth, pt.Y, 0); } pt = new Point3d(0, pt.Y - placeHeight - 8000, 0); } progress.Stop(); } t.Commit(); } }
private static Circle GetClosestCircle(Dictionary <int, Dictionary <int, List <Circle> > > allCircle, int xValue, int yValue, DBText text, Transaction trans, BlockTableRecord btr) { var distinctdistict = double.MaxValue; Circle circle = null; if (allCircle.ContainsKey(xValue)) { if (allCircle[xValue].ContainsKey(yValue)) { SetCircle(allCircle, xValue, yValue, text, ref distinctdistict, ref circle, trans, btr); } if (allCircle[xValue].ContainsKey(yValue - 1)) { SetCircle(allCircle, xValue, yValue - 1, text, ref distinctdistict, ref circle, trans, btr); } if (allCircle[xValue].ContainsKey(yValue + 1)) { SetCircle(allCircle, xValue, yValue + 1, text, ref distinctdistict, ref circle, trans, btr); } } if (allCircle.ContainsKey(xValue - 1)) { if (allCircle[xValue - 1].ContainsKey(yValue)) { SetCircle(allCircle, xValue - 1, yValue, text, ref distinctdistict, ref circle, trans, btr); } if (allCircle[xValue - 1].ContainsKey(yValue - 1)) { SetCircle(allCircle, xValue - 1, yValue - 1, text, ref distinctdistict, ref circle, trans, btr); } if (allCircle[xValue - 1].ContainsKey(yValue + 1)) { SetCircle(allCircle, xValue - 1, yValue + 1, text, ref distinctdistict, ref circle, trans, btr); } } if (allCircle.ContainsKey(xValue + 1)) { if (allCircle[xValue + 1].ContainsKey(yValue)) { SetCircle(allCircle, xValue + 1, yValue, text, ref distinctdistict, ref circle, trans, btr); } if (allCircle[xValue + 1].ContainsKey(yValue - 1)) { SetCircle(allCircle, xValue + 1, yValue - 1, text, ref distinctdistict, ref circle, trans, btr); } if (allCircle[xValue + 1].ContainsKey(yValue + 1)) { SetCircle(allCircle, xValue + 1, yValue + 1, text, ref distinctdistict, ref circle, trans, btr); } } return(circle); }
public void ShowPick() { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor editor = doc.Editor; try { using (Transaction trans = db.TransactionManager.StartTransaction()) { // 获取PickFirst选择集 PromptSelectionResult psr = editor.SelectImplied(); // 如果提示状态OK,说明启动命令前选择了对象; if (psr.Status != PromptStatus.OK) { editor.WriteMessage("没有选中对象\n"); return; } SelectionSet sset = psr.Value; editor.WriteMessage("选中{0:d}对象,第一个类型为{1:s}\n", sset.Count, sset[0].ObjectId.ObjectClass.DxfName); StringBuilder sb = new StringBuilder(); foreach (SelectedObject so in sset) { if (so.ObjectId.ObjectClass.DxfName == "TEXT") { DBText text = (DBText)so.ObjectId.GetObject(OpenMode.ForRead); sb.AppendLine(text.TextString); string s = string.Format("( {0:f1}, {1:f1} ) ( {2:f1}, {3:f1} )", text.GeometricExtents.MinPoint.X, text.GeometricExtents.MinPoint.Y, text.GeometricExtents.MaxPoint.X, text.GeometricExtents.MaxPoint.Y ); sb.AppendLine(s); //sb.Append(text.Position.ToString()); } else if (so.ObjectId.ObjectClass.DxfName == "MTEXT") { MText text = (MText)so.ObjectId.GetObject(OpenMode.ForRead); sb.AppendLine(text.Contents); sb.AppendLine(text.Text); string s = string.Format("( {0:f1}, {1:f1} ) ( {2:f1}, {3:f1} )", text.GeometricExtents.MinPoint.X, text.GeometricExtents.MinPoint.Y, text.GeometricExtents.MaxPoint.X, text.GeometricExtents.MaxPoint.Y ); sb.AppendLine(s); //sb.Append(text.Location.ToString()); } else if (so.ObjectId.ObjectClass.DxfName == "LINE") { Line line = (Line)so.ObjectId.GetObject(OpenMode.ForRead); sb.Append(line.StartPoint.ToString()); sb.Append(line.EndPoint.ToString()); } else if (so.ObjectId.ObjectClass.DxfName == "LWPOLYLINE") { Polyline pLine = (Polyline)so.ObjectId.GetObject(OpenMode.ForRead); for (int i = 0; i < pLine.NumberOfVertices; i++) { sb.Append(pLine.GetPoint2dAt(i).ToString()); } } else if (so.ObjectId.ObjectClass.DxfName == "INSERT") { Entity entity = (Entity)so.ObjectId.GetObject(OpenMode.ForWrite); if (entity is BlockReference) { BlockReference br = entity as BlockReference; sb.Append(br.Name); } } } editor.WriteMessage(sb.ToString()); trans.Commit(); } } catch (System.Exception e) { editor.WriteMessage(e.ToString()); } }
private static void SetCircle(Dictionary <int, Dictionary <int, List <Circle> > > allCircle, int xValue, int yValue, DBText text, ref double distinct, ref Circle circle, Transaction trans, BlockTableRecord btr) { var circles = allCircle[xValue][yValue]; foreach (var item in circles) { //var newText = new DBText(); //newText.Position = item.Center; //newText.TextString = text.TextString; //newText.Height = text.Height; //btr.AppendEntity(newText); //try { // trans.AddNewlyCreatedDBObject(newText, true); //} catch (System.Exception ex) { // throw ex; //} var length = GetDistinct(text.Position, item.Center); if (length < distinct) { distinct = length; circle = item; } } }
private static void placementAparts(Database db) { using (var t = db.TransactionManager.StartTransaction()) { ObjectId idTextStylePik = db.GetTextStylePIK(); var bt = db.BlockTableId.GetObject(OpenMode.ForRead) as BlockTable; var ms = bt[BlockTableRecord.ModelSpace].GetObject(OpenMode.ForWrite) as BlockTableRecord; int countAparts; var btrApartGroups = getGroupedAparts(bt, out countAparts); Point3d pt = Point3d.Origin; Point3d ptCenterPlace; using (var progress = new ProgressMeter()) { progress.SetLimit(countAparts); progress.Start("Расстановка квартир..."); foreach (var btrApartGroup in btrApartGroups) { progress.MeterProgress(); foreach (var idBtrApart in btrApartGroup) { var curPlaceWidth = placeWidth; var blRefApart = new BlockReference(pt, idBtrApart); blRefApart.SetDatabaseDefaults(db); var extApart = blRefApart.GeometricExtents; var lenApart = extApart.MaxPoint.X - extApart.MinPoint.X; if (lenApart > placeWidth) { curPlaceWidth = lenApart + 1000; } ptCenterPlace = new Point3d(pt.X + curPlaceWidth*0.5, pt.Y - placeHeight*0.5, 0); var ptBlCenter = extApart.Center(); // Перемещение блока в центр прямоугольной области Matrix3d displace = Matrix3d.Displacement(ptCenterPlace - ptBlCenter); blRefApart.TransformBy(displace); ms.AppendEntity(blRefApart); t.AddNewlyCreatedDBObject(blRefApart, true); // Подпись квартиры DBText text = new DBText(); text.SetDatabaseDefaults(); text.TextStyleId = idTextStylePik; text.Height = 900; text.TextString = getApartName(blRefApart.Name); text.Position = new Point3d (pt.X+300, pt.Y+300,0); ms.AppendEntity(text); t.AddNewlyCreatedDBObject(text, true); // Прямоугольник расположения квартиры Polyline pl = new Polyline(4); pl.AddVertexAt(0, pt.Convert2d(), 0, 0, 0); pl.AddVertexAt(1, new Point2d (pt.X+ curPlaceWidth, pt.Y), 0, 0, 0); pl.AddVertexAt(2, new Point2d(pt.X + curPlaceWidth, pt.Y-placeHeight), 0, 0, 0); pl.AddVertexAt(3, new Point2d(pt.X, pt.Y - placeHeight), 0, 0, 0); pl.Closed = true; pl.SetDatabaseDefaults(); ms.AppendEntity(pl); t.AddNewlyCreatedDBObject(pl, true); pt = new Point3d(pt.X + curPlaceWidth, pt.Y, 0); } pt = new Point3d(0, pt.Y - placeHeight - 8000, 0); } progress.Stop(); } t.Commit(); } }
public static void GetEntitiesFromLayer() { Database db = HostApplicationServices.WorkingDatabase; List <DBText> dbTextList = new List <DBText>(); Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; using (Transaction trans = db.TransactionManager.StartTransaction()) { LayerTable lt = (LayerTable)trans.GetObject(db.LayerTableId, OpenMode.ForRead); Dictionary <int, Dictionary <int, List <DBText> > > allText = new Dictionary <int, Dictionary <int, List <DBText> > >(); Dictionary <int, Dictionary <int, List <Circle> > > allCircle = new Dictionary <int, Dictionary <int, List <Circle> > >(); BlockTableRecord ltr = (BlockTableRecord)trans.GetObject(db.CurrentSpaceId, OpenMode.ForRead); foreach (ObjectId objId in ltr) { Entity ent = (Entity)trans.GetObject(objId, OpenMode.ForRead); if (ent.GetType().Name == "DBText") { AddText(allText, ent); } else if (ent.GetType().Name == "Circle") { AddCircle(allCircle, ent); } } StringBuilder builder = new StringBuilder(); BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead); BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite); foreach (var x in allText) { foreach (var y in x.Value) { foreach (var text in y.Value) { var circle = GetClosestCircle(allCircle, x.Key, y.Key, text, trans, btr); if (circle != null) { builder.AppendLine(string.Format("文字:{0}", text.TextString)); builder.AppendLine(string.Format("圆点:{0},{1},FaceStyleId:{2}", circle.Center.X, circle.Center.Y, circle.FaceStyleId)); var newText = new DBText(); newText.Position = circle.Center; newText.TextString = text.TextString; newText.Height = text.Height; dbTextList.Add(newText); btr.AppendEntity(newText); try { trans.AddNewlyCreatedDBObject(newText, true); } catch (System.Exception ex) { throw ex; } } else { builder.AppendLine(string.Format("文字:{0}", text.TextString)); builder.AppendLine("圆点:没有啊"); } } } } string path = @"C:\acadacad.text"; if (File.Exists(path)) { File.Delete(path); } StreamWriter rw = File.CreateText(path); rw.WriteLine(builder.ToString()); rw.Flush(); rw.Close(); ed.WriteMessage("搞定 收工"); trans.Commit(); } }
/// <summary> /// Aligment text is specified by objectID in ObjectIdCollection /// </summary> /// <param name="db"></param> /// <param name="txtIdColl"></param> /// <param name="aligment"></param> /// <param name="bsPoint"></param> public static void AligmentText(Database db, ObjectIdCollection txtIdColl, Enesy.EnesyCAD.Utilities.Text.Aligment aligment, Point3d bsPoint ) { using (Transaction tr = db.TransactionManager.StartTransaction()) { foreach (ObjectId objID in txtIdColl) { Entity ent = tr.GetObject(objID, OpenMode.ForRead) as Entity; // Get boundingBox of text Point3dCollection boundPoints = new Point3dCollection(); if (ent.GetType() == typeof(MText)) { MText txt = ent as MText; boundPoints.Add(txt.GetBoundingPoints()[2]); boundPoints.Add(txt.GetBoundingPoints()[1]); } else { DBText txt = ent as DBText; Point3dCollection points = new Point3dCollection(); txt.IntersectWith(txt, Intersect.OnBothOperands, points, 0, 0); Extents3d ext = txt.GeometricExtents; boundPoints.Add(points[0]); boundPoints.Add(ext.MaxPoint); } // Performing aligment ObjectIdCollection ids = new ObjectIdCollection(); ids.Add(objID); Point3d p = new Point3d(); switch (aligment) { case EnesyCAD.Utilities.Text.Aligment.Left: p = boundPoints[0]; MoveObjects(ids, p, new Point3d(bsPoint.X, p.Y, bsPoint.Z)); break; case EnesyCAD.Utilities.Text.Aligment.Center: p = MiddlePoint(boundPoints[0], boundPoints[1]); MoveObjects(ids, p, new Point3d(bsPoint.X, p.Y, bsPoint.Z)); break; case EnesyCAD.Utilities.Text.Aligment.Right: p = boundPoints[1]; MoveObjects(ids, p, new Point3d(bsPoint.X, p.Y, bsPoint.Z)); break; case EnesyCAD.Utilities.Text.Aligment.Top: p = boundPoints[1]; MoveObjects(ids, p, new Point3d(p.X, bsPoint.Y, bsPoint.Z)); break; case EnesyCAD.Utilities.Text.Aligment.Middle: p = MiddlePoint(boundPoints[0], boundPoints[1]); MoveObjects(ids, p, new Point3d(p.X, bsPoint.Y, bsPoint.Z)); break; case EnesyCAD.Utilities.Text.Aligment.Bottom: p = boundPoints[0]; MoveObjects(ids, p, new Point3d(p.X, bsPoint.Y, bsPoint.Z)); break; } } tr.Commit(); } }
public void CreateZhuangZhu() { var propDbOps = new PromptDoubleOptions("请输入半径:\n"); propDbOps.AllowNegative = false; propDbOps.AllowZero = false; propDbOps.AllowNone = false; var propDbRes = Ed.GetDouble(propDbOps); if (propDbRes.Status != PromptStatus.OK) { return; } double r = propDbRes.Value; while (true) { var propPtOps = new PromptPointOptions("请输入桩柱插入点:\n"); var propPtRes = Ed.GetPoint(propPtOps); if (propPtRes.Status != PromptStatus.OK) { return; } var centerPt = propPtRes.Value; Circle c = new Circle(centerPt, Vector3d.ZAxis, r); c.Color = Color.FromColor(System.Drawing.Color.Yellow); Point3d ptHStart = centerPt - Vector3d.XAxis * 200; Point3d ptHEnd = centerPt + Vector3d.XAxis * 200; Line hLine = new Line(ptHStart, ptHEnd); Point3d ptZStart = centerPt - Vector3d.YAxis * 200; Point3d ptZEnd = centerPt + Vector3d.YAxis * 200; Line zLine = new Line(ptZStart, ptZEnd); hLine.LineWeight = LineWeight.LineWeight030; zLine.LineWeight = LineWeight.LineWeight030; Point3d ptYx1 = centerPt + Vector3d.XAxis * (r + 800); ptYx1 = ptYx1.RotateBy(Math.PI * (70.0 / 180), Vector3d.ZAxis, centerPt); Point3d ptYx2 = ptYx1 + Vector3d.XAxis * 700; Polyline plYx = new Polyline(); plYx.Color = Color.FromColor(System.Drawing.Color.Green); plYx.AddVertexAt(plYx.NumberOfVertices, new Point2d(centerPt.X, centerPt.Y), 0, 0, 0); plYx.AddVertexAt(plYx.NumberOfVertices, new Point2d(ptYx1.X, ptYx1.Y), 0, 0, 0); plYx.AddVertexAt(plYx.NumberOfVertices, new Point2d(ptYx2.X, ptYx2.Y), 0, 0, 0); DBText dbText = new DBText(); dbText.TextString = "ZH1"; ObjectId styleId = ObjectId.Null; dbText.HorizontalMode = TextHorizontalMode.TextMid; dbText.Height = 135; dbText.Color = Color.FromColor(System.Drawing.Color.Red); //dbText.AdjustAlignment(Db); dbText.AlignmentPoint = new Point3d((ptYx2.X + ptYx1.X) / 2, (ptYx2.Y + ptYx1.Y) / 2 + 100, 0); List <Entity> listEnti = new List <Entity>(); listEnti.Add(c); listEnti.Add(hLine); listEnti.Add(zLine); listEnti.Add(plYx); listEnti.Add(dbText); ObjectId layer1 = AddLayer(Db, "ECD桩柱01", System.Drawing.Color.White); ObjectId layer2 = AddLayer(Db, "ECD桩柱02", System.Drawing.Color.Yellow); ObjectId layer3 = AddLayer(Db, "ECD桩柱03", System.Drawing.Color.White); hLine.LayerId = layer1; zLine.LayerId = layer1; c.LayerId = layer2; plYx.LayerId = layer3; dbText.LayerId = layer3; AddBlock(Db, listEnti); } }
public static IEnumerable <Entity> DrawProfileFrame(Database db, Point3d basePt, double startCh, double startLevel, double endCh, double endLevel, double chStep, double levelStep, double levelScale, double textHeight, int precision, ObjectId textStyleId) { List <Entity> entities = new List <Entity>(); ObjectId lineLayerId = AcadUtility.AcadEntity.GetOrCreateLayer(db, "Profil_Cizgi", Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByAci, 200)); ObjectId textLayerId = AcadUtility.AcadEntity.GetOrCreateLayer(db, "Profil_Yazi", Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByAci, 230)); ObjectId gridLayerId = AcadUtility.AcadEntity.GetOrCreateLayer(db, "Profil_Grid", Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByAci, 254)); ObjectId tickLayerId = AcadUtility.AcadEntity.GetOrCreateLayer(db, "Profil_Tick", Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByAci, 0)); // Draw lines // Horizontal SortedDictionary <double, bool> levels = new SortedDictionary <double, bool>(); for (double z = Math.Ceiling(startLevel / levelStep) * levelStep; z <= Math.Floor(endLevel / levelStep) * levelStep; z += levelStep) { levels[z] = true; } levels[startLevel] = false; levels[endLevel] = false; foreach (double z in levels.Keys) { Point3d pt1 = new Point3d(basePt.X, basePt.Y + (z - startLevel) * levelScale, basePt.Z); Point3d pt2 = new Point3d(basePt.X + (endCh - startCh), basePt.Y + (z - startLevel) * levelScale, basePt.Z); Line line = AcadUtility.AcadEntity.CreateLine(db, pt1, pt2, (levels[z] ? gridLayerId : lineLayerId)); entities.Add(line); // Tick marks pt1 = new Point3d(basePt.X, basePt.Y + (z - startLevel) * levelScale, basePt.Z); pt2 = new Point3d(basePt.X - textHeight / 2.0, basePt.Y + (z - startLevel) * levelScale, basePt.Z); line = AcadUtility.AcadEntity.CreateLine(db, pt1, pt2, tickLayerId); entities.Add(line); // Level text pt1 = new Point3d(basePt.X - textHeight, basePt.Y + (z - startLevel) * levelScale, basePt.Z); DBText text = AcadUtility.AcadEntity.CreateText(db, pt1, AcadUtility.AcadText.LevelToString(z, precision), textHeight, 0, 0.8, TextHorizontalMode.TextRight, TextVerticalMode.TextVerticalMid, textStyleId, textLayerId); entities.Add(text); } // Vertical SortedDictionary <double, bool> chainages = new SortedDictionary <double, bool>(); for (double ch = Math.Ceiling(startCh / chStep) * chStep; ch <= Math.Floor(endCh / chStep) * chStep; ch += chStep) { chainages[ch] = true; } chainages[startCh] = false; chainages[endCh] = false; foreach (double ch in chainages.Keys) { Point3d pt1 = new Point3d(basePt.X + (ch - startCh), basePt.Y, basePt.Z); Point3d pt2 = new Point3d(basePt.X + (ch - startCh), basePt.Y + (endLevel - startLevel) * levelScale, basePt.Z); Line line = AcadUtility.AcadEntity.CreateLine(db, pt1, pt2, (chainages[ch] ? gridLayerId : lineLayerId)); entities.Add(line); // Tick marks pt1 = new Point3d(basePt.X + (ch - startCh), basePt.Y, basePt.Z); pt2 = new Point3d(basePt.X + (ch - startCh), basePt.Y - textHeight / 2, basePt.Z); line = AcadUtility.AcadEntity.CreateLine(db, pt1, pt2, tickLayerId); entities.Add(line); // Chainage text pt1 = new Point3d(basePt.X + (ch - startCh), basePt.Y - textHeight, basePt.Z); DBText text = AcadUtility.AcadEntity.CreateText(db, pt1, AcadUtility.AcadText.ChainageToString(ch, precision), textHeight, Math.PI / 2, 0.8, TextHorizontalMode.TextRight, TextVerticalMode.TextVerticalMid, textStyleId, textLayerId); entities.Add(text); } return(entities); }
public static void PrintTable(Database db, Point3d PaperOrigenPoint, Dalot curDatlotObj, DMT curDMT, System.Data.DataTable curParas, double [] AreaOfSection, MOExcel.Worksheet worksheet, int LineIdx) { double x0 = 284; double y_anchor = 267; double y0 = 0; double x1 = x0 + 106; double t1 = x0 + 24; double t2 = t1 + 38; double t3 = t2 + 17; double t4 = t3 + 16; int[] num23 = curDatlotObj.GetSegNum(); var results = from myRow in curParas.AsEnumerable() where Dalot.PkString2Double(myRow.Field <string>("pk")) == curDatlotObj.Pk select myRow; var theData = results.First(); using (Transaction tr = db.TransactionManager.StartTransaction()) { TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable; BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable; BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.PaperSpace], OpenMode.ForWrite) as BlockTableRecord; DBText theTitle = new DBText(); theTitle.TextString = "TABLEAU QUANTITATIF DES DALOT " + curDatlotObj.Pk_string(); theTitle.Height = 3.5; theTitle.Position = PaperOrigenPoint.Convert3D((x0 + x1) * 0.5, y_anchor); theTitle.HorizontalMode = TextHorizontalMode.TextCenter; theTitle.VerticalMode = TextVerticalMode.TextBottom; theTitle.AlignmentPoint = theTitle.Position; theTitle.Layer = "标注"; theTitle.TextStyleId = st["En"]; theTitle.WidthFactor = 0.85; recorder.AppendEntity(theTitle); tr.AddNewlyCreatedDBObject(theTitle, true); DBText theTitleZh = new DBText(); theTitleZh.TextString = "涵洞材料数量表"; theTitleZh.Height = 5; theTitleZh.Position = PaperOrigenPoint.Convert3D((x0 + x1) * 0.5, y_anchor + 6); theTitleZh.HorizontalMode = TextHorizontalMode.TextCenter; theTitleZh.VerticalMode = TextVerticalMode.TextBottom; theTitleZh.AlignmentPoint = theTitleZh.Position; theTitleZh.Layer = "标注"; theTitleZh.TextStyleId = st["fsdb"]; theTitleZh.WidthFactor = 0.85; // 取消中文 //recorder.AppendEntity(theTitleZh); //tr.AddNewlyCreatedDBObject(theTitleZh, true); Dictionary <int, string[]> table = new Dictionary <int, string[]>(); double Conc = 0; double Steel = 0; int totalSegNum = 0; double bzqL = 0, jsjL = 0; double SectA = 0; double YiGeXiaoSanJiao = 0; double BZQfangshuiceng = 0; double JSJfangshuiceng = 0; if (curDatlotObj.DalotType == DType.A) { Conc = 2.0 * num23[0] * 1.18915 + 3.0 * num23[1] * 1.18915; Steel = num23[0] * (double)theData["2m钢筋量"] + num23[1] * (double)theData["3m钢筋量"]; totalSegNum = num23[0] + num23[1]; bzqL = 2.000; jsjL = 1.850; SectA = 1.18915; YiGeXiaoSanJiao = 2 * 2 * Math.Tan(30.0 / 180.0 * Math.PI) * 0.5; BZQfangshuiceng = 3.8; JSJfangshuiceng = 7.84; } else if (curDatlotObj.DalotType == DType.B) { Conc = curDatlotObj.Length / 1000 * 2.035; Steel = (double)theData["节段钢筋量"] * num23[0]; totalSegNum = num23[0]; bzqL = 2.825; jsjL = 1.900; SectA = 2.035; YiGeXiaoSanJiao = 2.82 * 2.82 * Math.Tan(30.0 / 180.0 * Math.PI) * 0.5; BZQfangshuiceng = 7; JSJfangshuiceng = 12.4; } else if (curDatlotObj.DalotType == DType.C) { Conc = curDatlotObj.Length / 1000 * 5.5379; Steel = (double)theData["现浇钢筋总量"]; totalSegNum = num23[0]; bzqL = 3.6; jsjL = 0; SectA = 5.5379; YiGeXiaoSanJiao = 3.6 * 3.6 * Math.Tan(30.0 / 180.0 * Math.PI) * 0.5; BZQfangshuiceng = 14.965; } else if (curDatlotObj.DalotType == DType.D) { Conc = curDatlotObj.Length / 1000 * 6.24965; Steel = (double)theData["现浇钢筋总量"]; totalSegNum = num23[0]; bzqL = 5.1; jsjL = 0; SectA = 6.24965; YiGeXiaoSanJiao = 5.1 * 5.1 * Math.Tan(30.0 / 180.0 * Math.PI) * 0.5; BZQfangshuiceng = 27.089; } string JSJConc, BZQConc; double ASteel = 0; double totalLength; string C15 = ""; string Gra = ""; string Bad = ""; if (curDatlotObj.Amont == AType.BZQ) { JSJConc = "-"; BZQConc = string.Format("{0:F1}", (double)theData["八字墙混凝土"] * 2.0); ASteel = (double)theData["八字墙钢筋"] * 2; totalLength = curDatlotObj.Length / 1000 + 2 * bzqL; C15 = string.Format("{0:F1}", (AreaOfSection[1] * totalLength + YiGeXiaoSanJiao * 4 * 0.1) * 1.05); Gra = AreaOfSection[2] == 0 ? "-" : string.Format("{0:F1}", (AreaOfSection[2] * (totalLength - curDatlotObj.MouthT / 1000 * 2) + YiGeXiaoSanJiao * 4 * curDatlotObj.LayerT / 1000) * 1.05); Bad = string.Format("{0:F1}", (AreaOfSection[3] * 2 + AreaOfSection[4]) * curDatlotObj.Length / 1000 + BZQfangshuiceng * 2.0); } else { JSJConc = string.Format("{0:F1}", (double)theData["八字墙混凝土"] * 1.0); BZQConc = string.Format("{0:F1}", (double)theData["八字墙混凝土"] * 1.0); ASteel = (double)theData["八字墙钢筋"] + (double)theData["集水井钢筋"]; totalLength = curDatlotObj.Length / 1000 + bzqL + jsjL; C15 = string.Format("{0:F1}", (AreaOfSection[1] * totalLength + YiGeXiaoSanJiao * 2 * 0.1) * 1.05); Gra = AreaOfSection[2] == 0 ? "-" : string.Format("{0:F1}", (AreaOfSection[2] * (totalLength - curDatlotObj.MouthT / 1000 * 2) + YiGeXiaoSanJiao * 2 * curDatlotObj.LayerT / 1000) * 1.05); Bad = string.Format("{0:F1}", (AreaOfSection[3] * 2 + AreaOfSection[4]) * curDatlotObj.Length / 1000 + BZQfangshuiceng * 2.0 + BZQfangshuiceng + JSJfangshuiceng); } string Mot = "-"; if (curDatlotObj.H2 - curDatlotObj.H0 - (curDatlotObj.Sect[2] - curDatlotObj.Sect[3]) / 1000 <= 0.5) { Mot = string.Format("{0:F1}", AreaOfSection[4] * curDatlotObj.Length / 1000); } string Joint = string.Format("{0:F1}", (SectA + AreaOfSection[1]) * (totalSegNum + 1)); string Rem = string.Format("{0:F1}", AreaOfSection[0] * totalLength); string Enr = string.Format("{0:F1}", (bzqL / Math.Sqrt(3) * 2 + curDatlotObj.Sect[0] / 1000) * 0.625); string Deb = string.Format("{0:F1}", (AreaOfSection[0] + AreaOfSection[5] + AreaOfSection[1] + AreaOfSection[2]) * totalLength); table.Add(1, new string[] { "Béton", "C25/30", "m3", string.Format("{0:F1}", Conc) }); table.Add(2, new string[] { "Armature", "FeE400", "kg", string.Format("{0:F1}", Steel) }); table.Add(3, new string[] { "Quantité de segment", "-", "bloc", string.Format("{0:G}", totalSegNum) }); table.Add(4, new string[] { "Puit d'eau", "C25/30", "m3", JSJConc }); table.Add(5, new string[] { "Mur en aile", "C25/30", "m3", BZQConc }); table.Add(6, new string[] { "Guide roue", "C25/30", "m3", "-" }); table.Add(7, new string[] { "Armature", "FeE400", "kg", string.Format("{0:F1}", ASteel) }); table.Add(8, new string[] { "Béton", "C12/15", "m3", C15 }); table.Add(9, new string[] { "Substitution Radier", "-", "m3", Gra }); table.Add(10, new string[] { "Badigeonnage des parements", "-", "m2", Bad }); table.Add(11, new string[] { "Motier hydro", "-", "m2", Mot }); table.Add(12, new string[] { "Joint", "-", "m2", Joint }); table.Add(13, new string[] { "Déblai", "-", "m3", Deb }); table.Add(14, new string[] { "Remblaiement au dos de dalot", "-", "m3", Rem }); table.Add(15, new string[] { "Enrochement", "-", "m3", Enr }); Dictionary <int, string> columnName = new Dictionary <int, string>(); columnName.Add(2, "Crops"); columnName.Add(5, "Entrée et sortie"); columnName.Add(8, "Foundation"); columnName.Add(11, "Etanchéité"); columnName.Add(14, "Terrassement"); // 输出表格数据 worksheet.Cells[LineIdx, 1] = " "; worksheet.Cells[LineIdx, 2] = curDatlotObj.Pk_string(); worksheet.Cells[LineIdx, 3] = "dalot"; if (curDatlotObj.DalotType == DType.A) { worksheet.Cells[LineIdx, 4] = "1-1.5*1.0"; } else if (curDatlotObj.DalotType == DType.B) { worksheet.Cells[LineIdx, 4] = "1-2.0*1.5"; } else if (curDatlotObj.DalotType == DType.C) { worksheet.Cells[LineIdx, 4] = "1-4.0*2.0"; } else if (curDatlotObj.DalotType == DType.D) { worksheet.Cells[LineIdx, 4] = "1-4.0*3.0"; } worksheet.Cells[LineIdx, 5] = 90 - curDatlotObj.Ang; worksheet.Cells[LineIdx, 6] = curDatlotObj.Length / 1000; if (curDatlotObj.Amont == AType.BZQ) { worksheet.Cells[LineIdx, 7] = "Mur en aile"; } else { worksheet.Cells[LineIdx, 7] = "Puit d'eau"; } worksheet.Cells[LineIdx, 8] = "Mur en aile"; worksheet.Cells[LineIdx, 9] = string.Format("{0:F1}", Conc); worksheet.Cells[LineIdx, 10] = string.Format("{0:F1}", Steel); worksheet.Cells[LineIdx, 11] = string.Format("{0:G}", totalSegNum); worksheet.Cells[LineIdx, 12] = JSJConc; worksheet.Cells[LineIdx, 13] = BZQConc; worksheet.Cells[LineIdx, 14] = "-"; worksheet.Cells[LineIdx, 15] = string.Format("{0:F1}", ASteel); worksheet.Cells[LineIdx, 16] = C15; worksheet.Cells[LineIdx, 17] = Gra; worksheet.Cells[LineIdx, 18] = Bad; worksheet.Cells[LineIdx, 19] = Mot; worksheet.Cells[LineIdx, 20] = Joint; worksheet.Cells[LineIdx, 21] = Deb; worksheet.Cells[LineIdx, 22] = Rem; worksheet.Cells[LineIdx, 23] = Enr; worksheet.Cells[LineIdx, 24] = curDatlotObj.H0.ToString(); for (int i = 0; i < 16; i++) { y0 = y_anchor - i * 6; if (new List <int> { 1, 4, 8, 10, 13 }.Contains(i)) { Line hengxian = new Line(PaperOrigenPoint.Convert3D(x0, y0, 0), PaperOrigenPoint.Convert3D(x1, y0, 0)); hengxian.Layer = "标注"; recorder.AppendEntity(hengxian); tr.AddNewlyCreatedDBObject(hengxian, true); } else { Line hengxian = new Line(PaperOrigenPoint.Convert3D(t1, y0, 0), PaperOrigenPoint.Convert3D(x1, y0, 0)); hengxian.Layer = "标注"; recorder.AppendEntity(hengxian); tr.AddNewlyCreatedDBObject(hengxian, true); } // 列名 if (new List <int> { 2, 5, 8, 11, 14 }.Contains(i)) { DBText txt = new DBText(); txt.TextString = columnName[i]; txt.TextStyleId = st["En"]; txt.Height = 2.5; if (i == 5 || i == 8) { txt.Position = PaperOrigenPoint.Convert3D((x0 + t1) * 0.5, y0); txt.HorizontalMode = TextHorizontalMode.TextCenter; txt.VerticalMode = TextVerticalMode.TextVerticalMid; txt.AlignmentPoint = PaperOrigenPoint.Convert3D((x0 + t1) * 0.5, y0 - 6); } else { txt.Position = PaperOrigenPoint.Convert3D((x0 + t1) * 0.5, y0); txt.HorizontalMode = TextHorizontalMode.TextCenter; txt.VerticalMode = TextVerticalMode.TextVerticalMid; txt.AlignmentPoint = PaperOrigenPoint.Convert3D((x0 + t1) * 0.5, y0 - 3); } txt.Layer = "标注"; txt.WidthFactor = 0.85; recorder.AppendEntity(txt); tr.AddNewlyCreatedDBObject(txt, true); } // 内容 if (i != 0) { for (int j = 0; j < 4; j++) { double tx = 0; if (j == 0) { tx = (t1 + t2) * 0.5; } else if (j == 1) { tx = (t3 + t2) * 0.5; } else if (j == 2) { tx = (t3 + t4) * 0.5; } else { tx = (x1 + t4) * 0.5; } DBText txt = new DBText() { TextString = table[i][j], TextStyleId = st["En"], Height = 2.5, Position = PaperOrigenPoint.Convert3D(tx, y0 - 3), HorizontalMode = TextHorizontalMode.TextCenter, VerticalMode = TextVerticalMode.TextVerticalMid, AlignmentPoint = PaperOrigenPoint.Convert3D(tx, y0 - 3), Layer = "标注", WidthFactor = 0.85, }; recorder.AppendEntity(txt); tr.AddNewlyCreatedDBObject(txt, true); } } } foreach (double x_shuxian in new List <double> { t1, t2, t3, t4 }) { Line ShuXin = new Line(); if (x_shuxian == t1) { ShuXin = new Line(PaperOrigenPoint.Convert3D(x_shuxian, y_anchor - 6), PaperOrigenPoint.Convert3D(x_shuxian, y_anchor - 96)); } else { ShuXin = new Line(PaperOrigenPoint.Convert3D(x_shuxian, y_anchor), PaperOrigenPoint.Convert3D(x_shuxian, y_anchor - 96)); } ShuXin.Layer = "标注"; recorder.AppendEntity(ShuXin); tr.AddNewlyCreatedDBObject(ShuXin, true); } DBText rowName = new DBText() { TextString = "Aspect d'ouvrage", TextStyleId = st["En"], Height = 2.5, Position = PaperOrigenPoint.Convert3D((x0 + t2) * 0.5, y_anchor - 3), HorizontalMode = TextHorizontalMode.TextCenter, VerticalMode = TextVerticalMode.TextVerticalMid, AlignmentPoint = PaperOrigenPoint.Convert3D((x0 + t2) * 0.5, y_anchor - 3), Layer = "标注", WidthFactor = 0.85, }; recorder.AppendEntity(rowName); tr.AddNewlyCreatedDBObject(rowName, true); rowName = new DBText() { TextString = "Matériaux", TextStyleId = st["En"], Height = 2.5, Position = PaperOrigenPoint.Convert3D((t2 + t3) * 0.5, y_anchor - 3), HorizontalMode = TextHorizontalMode.TextCenter, VerticalMode = TextVerticalMode.TextVerticalMid, AlignmentPoint = PaperOrigenPoint.Convert3D((t3 + t2) * 0.5, y_anchor - 3), Layer = "标注", WidthFactor = 0.85, }; recorder.AppendEntity(rowName); tr.AddNewlyCreatedDBObject(rowName, true); rowName = new DBText() { TextString = "Unité", TextStyleId = st["En"], Height = 2.5, Position = PaperOrigenPoint.Convert3D((t4 + t3) * 0.5, y_anchor - 3), HorizontalMode = TextHorizontalMode.TextCenter, VerticalMode = TextVerticalMode.TextVerticalMid, AlignmentPoint = PaperOrigenPoint.Convert3D((t3 + t4) * 0.5, y_anchor - 3), Layer = "标注", WidthFactor = 0.85, }; recorder.AppendEntity(rowName); tr.AddNewlyCreatedDBObject(rowName, true); rowName = new DBText() { TextString = "Quantité", TextStyleId = st["En"], Height = 2.5, Position = PaperOrigenPoint.Convert3D((x1 + t4) * 0.5, y_anchor - 3), HorizontalMode = TextHorizontalMode.TextCenter, VerticalMode = TextVerticalMode.TextVerticalMid, AlignmentPoint = PaperOrigenPoint.Convert3D((x1 + t4) * 0.5, y_anchor - 3), Layer = "标注", WidthFactor = 0.85, }; recorder.AppendEntity(rowName); tr.AddNewlyCreatedDBObject(rowName, true); Polyline box = new Polyline(); box.AddVertexAt(0, PaperOrigenPoint.Convert2D(x0, y0 + 15 * 6), 0, 0.3, 0.3); box.AddVertexAt(1, PaperOrigenPoint.Convert2D(x1, y0 + 15 * 6), 0, 0.3, 0.3); box.AddVertexAt(2, PaperOrigenPoint.Convert2D(x1, y0 - 6), 0, 0.3, 0.3); box.AddVertexAt(3, PaperOrigenPoint.Convert2D(x0, y0 - 6), 0, 0.3, 0.3); box.Layer = "标注"; box.Closed = true; recorder.AppendEntity(box); tr.AddNewlyCreatedDBObject(box, true); tr.Commit(); } return; }
public bool create_DIMtxt(int i) { //GET POLYLINE Polyline pline = tr.openObject(DIMline, OpenMode.ForRead) as Polyline; tr.closeObject(); ////QUOTE TEXT ObjectId tId; // TEXT ID DBText acText = new DBText(); acText.Justify = AttachmentPoint.BaseCenter; acText.Height = DIMset.Dimtxt_Height; acText.TextString = acMath.totalDistance(Points, DIMset.DimUnit_Precision).ToString(); acText.Rotation = acMath.RetriveRot(Points[Points.Count - 2], Points[Points.Count - 1]); double dist = CurrPoint.Value.DistanceTo(pline.GetPoint3dAt(0)); if (dist < 0.001) { acText.AlignmentPoint = acMath.pointOffset(pline.GetPoint3dAt(i - 1), pline.GetPoint3dAt(0), DIMset.Dimtxt_Offset)[1]; preview.endDraw_PreviewLine(); tId = tr.addObject(acText); DIMtexts.Add(tId); return false; } else { acText.AlignmentPoint = acMath.pointOffset(pline.GetPoint3dAt(i), pline.GetPoint3dAt(i - 1), -DIMset.Dimtxt_Offset)[1]; } tId = tr.addObject(acText); DIMtexts.Add(tId); return true; }
/// <summary> /// Сжатие однострочного текста /// </summary> /// <param name="dbt">Объект DBText</param> /// <param name="w">Ширина</param> /// <param name="k">Коэффициент увеличения</param> public static void DBTextSize(DBText dbt, double w, double k) { double c = dbt.TextString.Length, chw = dbt.Height * 0.65; if (c * chw * k * dbt.WidthFactor >= w * k) while (c * chw * k * dbt.WidthFactor > w * k && dbt.WidthFactor > 0.5) dbt.WidthFactor -= 0.025; }
public static void PrintNumTitle(Database db, Point3d PaperOrigenPoint, Dalot curDalot) { using (Transaction tr = db.TransactionManager.StartTransaction()) { TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable; BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable; BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.PaperSpace], OpenMode.ForWrite) as BlockTableRecord; for (int i = 0; i <= 1; i++) { DBText num = new DBText(); num.TextString = "1"; num.Height = 2.5; if (i == 0) { num.Position = PaperOrigenPoint.Convert3D(394.817, 283.25); } else { num.Position = PaperOrigenPoint.Convert3D(404.939, 283.25); } num.HorizontalMode = TextHorizontalMode.TextCenter; num.VerticalMode = TextVerticalMode.TextVerticalMid; num.AlignmentPoint = num.Position; num.Layer = "标注"; num.TextStyleId = st["En"]; num.WidthFactor = 0.85; recorder.AppendEntity(num); tr.AddNewlyCreatedDBObject(num, true); } // 标题 DBText title = new DBText(); if (curDalot.DalotType == DType.A) { title.TextString = "PLAN DE COFFRAGE DU DALOT (1-1.5×1.0m)"; } else if (curDalot.DalotType == DType.B) { title.TextString = "PLAN DE COFFRAGE DU DALOT (1-2.0×1.5m)"; } else if (curDalot.DalotType == DType.C) { title.TextString = "PLAN DE COFFRAGE DU DALOT (1-4.0×2.0m)"; } else if (curDalot.DalotType == DType.D) { title.TextString = "PLAN DE COFFRAGE DU DALOT (1-4.0×3.0m)"; } else { return; } title.Height = 3.5; title.Position = PaperOrigenPoint.Convert3D(254.5391, 21.4013); title.HorizontalMode = TextHorizontalMode.TextCenter; title.VerticalMode = TextVerticalMode.TextVerticalMid; title.AlignmentPoint = title.Position; title.Layer = "标注"; title.TextStyleId = st["En"]; title.WidthFactor = 0.8; recorder.AppendEntity(title); tr.AddNewlyCreatedDBObject(title, true); title = new DBText(); title.TextString = curDalot.Pk_string(); title.Height = 3.5; title.Position = PaperOrigenPoint.Convert3D(254.5391, 15.2987); title.HorizontalMode = TextHorizontalMode.TextCenter; title.VerticalMode = TextVerticalMode.TextVerticalMid; title.AlignmentPoint = title.Position; title.Layer = "标注"; title.TextStyleId = st["En"]; title.WidthFactor = 0.8; recorder.AppendEntity(title); tr.AddNewlyCreatedDBObject(title, true); // 图号 DBText dn = new DBText(); dn.TextString = curDalot.DesignNo; dn.Height = 2.5; dn.Position = PaperOrigenPoint.Convert3D(371, 14); dn.HorizontalMode = TextHorizontalMode.TextCenter; dn.VerticalMode = TextVerticalMode.TextVerticalMid; dn.AlignmentPoint = dn.Position; dn.Layer = "标注"; dn.TextStyleId = st["En"]; dn.WidthFactor = 0.8; recorder.AppendEntity(dn); tr.AddNewlyCreatedDBObject(dn, true); tr.Commit(); } return; }
public void beginDraw_PreviewLine(Point3d point) { //CREATE LINE drawline = true; Line line = new Line(point, point); PrevLine = tr.addObject(line); DBText acText = new DBText(); PrevText = tr.addObject(acText); _osOverrule = new OsSnappOver(PrevLine); ObjectOverrule.AddOverrule(RXObject.GetClass(typeof(Entity)), _osOverrule, false); }
/// <summary> /// Установка параметров DBText /// </summary> /// <param name="dbt">Объект DBText</param> /// <param name="pt3">Местоположение</param> /// <param name="h">Высота</param> /// <param name="ts">Текст</param> /// <param name="wf">Коэффициент сжатия</param> public static void SetDBText(DBText dbt, Point3d pt3, double h, string ts, double wf) { dbt.SetDatabaseDefaults(); dbt.Position = pt3; dbt.Height = h; dbt.TextString = ts; dbt.WidthFactor = wf; }
public static void PrintLineText(Database db, Point2d StartPoint, Point2d EndPoint, string[] textList, bool isLeft = true, double scale = 100) { int number = textList.Count(); double wdh = 2.5; double WdWidth = 1.25; double LineWidth = 0; using (Transaction tr = db.TransactionManager.StartTransaction()) { TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable; BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable; BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; Line L1 = new Line(); Line side = new Line(); DBText txt = new DBText(); foreach (string cnt in textList) { double w = WdWidth * cnt.Length * scale; if (w > LineWidth) { LineWidth = w; } } double xdir = isLeft ? -1 : 1; double ydir; if (EndPoint.Y > StartPoint.Y) { L1 = new Line(StartPoint.Convert3D(), EndPoint.Convert3D(0, +(wdh + 0.5) * scale * (number - 1))); ydir = 1; } else { L1 = new Line(StartPoint.Convert3D(), EndPoint.Convert3D(0, -(wdh + 0.5) * scale * (number - 1))); ydir = -1; } L1.Layer = "标注"; modelSpace.AppendEntity(L1); tr.AddNewlyCreatedDBObject(L1, true); int i = 0; foreach (string cnt in textList) { side = new Line(EndPoint.Convert3D(0, i * (wdh + 0.5) * scale * ydir), EndPoint.Convert3D(xdir * LineWidth, i * (wdh + 0.5) * scale * ydir)); side.Layer = "标注"; modelSpace.AppendEntity(side); tr.AddNewlyCreatedDBObject(side, true); if (cnt.StartsWith("Joint")) { break; } txt = new DBText(); txt.TextString = cnt; txt.Height = wdh * scale; txt.Position = side.StartPoint; txt.HorizontalMode = isLeft ? TextHorizontalMode.TextRight : TextHorizontalMode.TextLeft; txt.VerticalMode = TextVerticalMode.TextBottom; //txt.Justify = AttachmentPoint.BaseLeft; txt.AlignmentPoint = txt.Position; txt.Layer = "标注"; txt.TextStyleId = st["fsdb"]; txt.WidthFactor = 0.75; modelSpace.AppendEntity(txt); tr.AddNewlyCreatedDBObject(txt, true); i++; } if (textList[0].StartsWith("Joint")) { MatchCollection matches = Regex.Matches(textList[0], @"(\d+\.?\d*)"); txt = new DBText(); txt.TextString = "Joint"; txt.Height = wdh * scale; txt.Position = side.StartPoint; txt.HorizontalMode = isLeft ? TextHorizontalMode.TextRight : TextHorizontalMode.TextLeft; txt.VerticalMode = TextVerticalMode.TextBottom; //txt.Justify = AttachmentPoint.BaseLeft; txt.AlignmentPoint = txt.Position; txt.Layer = "标注"; txt.TextStyleId = st["fsdb"]; txt.WidthFactor = 0.75; modelSpace.AppendEntity(txt); tr.AddNewlyCreatedDBObject(txt, true); txt = new DBText(); txt.TextString = string.Format("e={0}cm", matches[0]); txt.Height = wdh * scale; txt.Position = side.StartPoint; txt.HorizontalMode = isLeft ? TextHorizontalMode.TextRight : TextHorizontalMode.TextLeft; txt.VerticalMode = TextVerticalMode.TextTop; //txt.Justify = AttachmentPoint.BaseLeft; txt.AlignmentPoint = txt.Position; txt.Layer = "标注"; txt.TextStyleId = st["fsdb"]; txt.WidthFactor = 0.75; modelSpace.AppendEntity(txt); tr.AddNewlyCreatedDBObject(txt, true); side.EndPoint = side.StartPoint.Convert3D(xdir * 0.7 * side.Length); } tr.Commit(); } }
//Рисуем таблицу щитка. private void b_paint_Click(object sender, EventArgs e) { this.Hide(); Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database acCurDb = acDoc.Database; using (DocumentLock doclock = acDoc.LockDocument()) { using (Transaction trans = acCurDb.TransactionManager.StartTransaction()) { PromptPointResult pPtRes; PromptPointOptions pPtOpts = new PromptPointOptions(""); pPtOpts.Message = "\nВведи точку: "; pPtRes = acDoc.Editor.GetPoint(pPtOpts); // pPtRes.Value - точка типа Point3D Data.table_x = pPtRes.Value.X; Data.table_y = pPtRes.Value.Y; BlockTableRecord btr; BlockTable bt; DBObjectCollection ObjColl = new DBObjectCollection(); //ObjColl.Add(new Line(new Point3d(Data.table_x, Data.table_y, 0), new Point3d(Data.table_x, Data.table_y, 0))); //Вставили шапку таблицы. ObjColl.Add(new Line(new Point3d(Data.table_x, Data.table_y, 0), new Point3d(Data.table_x + 285, Data.table_y, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x, Data.table_y - 50, 0), new Point3d(Data.table_x + 285, Data.table_y - 50, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 101, Data.table_y - 15, 0), new Point3d(Data.table_x + 285, Data.table_y - 15, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x, Data.table_y, 0), new Point3d(Data.table_x, Data.table_y - 50, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 25, Data.table_y, 0), new Point3d(Data.table_x + 25, Data.table_y - 50, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 58, Data.table_y, 0), new Point3d(Data.table_x + 58, Data.table_y - 50, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 63, Data.table_y, 0), new Point3d(Data.table_x + 63, Data.table_y - 50, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 96, Data.table_y, 0), new Point3d(Data.table_x + 96, Data.table_y - 50, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 101, Data.table_y, 0), new Point3d(Data.table_x + 101, Data.table_y - 50, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 106, Data.table_y - 15, 0), new Point3d(Data.table_x + 106, Data.table_y - 50, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 123, Data.table_y - 15, 0), new Point3d(Data.table_x + 123, Data.table_y - 50, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 136, Data.table_y - 15, 0), new Point3d(Data.table_x + 136, Data.table_y - 50, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 161, Data.table_y - 15, 0), new Point3d(Data.table_x + 161, Data.table_y - 50, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 174, Data.table_y, 0), new Point3d(Data.table_x + 174, Data.table_y - 50, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 197, Data.table_y - 15, 0), new Point3d(Data.table_x + 197, Data.table_y - 50, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 210, Data.table_y, 0), new Point3d(Data.table_x + 210, Data.table_y - 50, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 226, Data.table_y - 15, 0), new Point3d(Data.table_x + 226, Data.table_y - 50, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 238, Data.table_y - 15, 0), new Point3d(Data.table_x + 238, Data.table_y - 50, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 250, Data.table_y - 15, 0), new Point3d(Data.table_x + 250, Data.table_y - 50, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 285, Data.table_y, 0), new Point3d(Data.table_x + 285, Data.table_y - 50, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 239, Data.table_y - 32, 0), new Point3d(Data.table_x + 249, Data.table_y - 32, 0))); #region Текст в шапке MText objText = new MText(); objText.SetDatabaseDefaults(); objText.Location = new Point3d(Data.table_x + 2, Data.table_y - 1, 0); objText.Contents = "Распреде-\nлительное устройство"; objText.TextStyleId = acCurDb.Textstyle; objText.TextHeight = 3; objText.Height = 50; objText.Width = 25; ObjColl.Add(objText); MText objText1 = new MText(); objText1.SetDatabaseDefaults(); objText1.TextStyleId = acCurDb.Textstyle; objText1.TextHeight = 3; objText1.Location = new Point3d(Data.table_x + 27, Data.table_y - 1, 0); objText1.Contents = "Аппарат отходящей линии /ввода/, обозначение, тип, Iном, A, расцепитель или плавкая вставка, А."; objText1.Height = 50; objText1.Width = 31; ObjColl.Add(objText1); MText objText2 = new MText(); objText2.SetDatabaseDefaults(); objText2.TextStyleId = acCurDb.Textstyle; objText2.TextHeight = 3; objText2.Location = new Point3d(Data.table_x + 65, Data.table_y - 1, 0); objText2.Contents = "Пусковой аппарат, обозначение, тип, Iном, A, расцепитель или плавкая вставка А, уставка теплового реле А."; objText2.Height = 50; objText2.Width = 31; ObjColl.Add(objText2); MText objText3 = new MText(); objText3.SetDatabaseDefaults(); objText3.TextStyleId = acCurDb.Textstyle; objText3.TextHeight = 3; objText3.Location = new Point3d(Data.table_x + 108, Data.table_y - 18, 0); objText3.Contents = "Обозна-\nчение"; objText3.Height = 35; objText3.Width = 17; ObjColl.Add(objText3); MText objText4 = new MText(); objText4.SetDatabaseDefaults(); objText4.TextStyleId = acCurDb.Textstyle; objText4.TextHeight = 3; objText4.Location = new Point3d(Data.table_x + 125, Data.table_y - 18, 0); objText4.Contents = "Марка"; objText4.Height = 35; objText4.Width = 13; ObjColl.Add(objText4); MText objText5 = new MText(); objText5.SetDatabaseDefaults(); objText5.TextStyleId = acCurDb.Textstyle; objText5.TextHeight = 3; objText5.Location = new Point3d(Data.table_x + 138, Data.table_y - 18, 0); objText5.Contents = "Количество, число жил и сечение"; objText5.Height = 35; objText5.Width = 25; ObjColl.Add(objText5); MText objText6 = new MText(); objText6.SetDatabaseDefaults(); objText6.TextStyleId = acCurDb.Textstyle; objText6.TextHeight = 3; objText6.Location = new Point3d(Data.table_x + 162, Data.table_y - 18, 0); objText6.Contents = "Длина, м."; objText6.Height = 35; objText6.Width = 13; ObjColl.Add(objText6); MText objText7 = new MText(); objText7.SetDatabaseDefaults(); objText7.TextStyleId = acCurDb.Textstyle; objText7.TextHeight = 3; objText7.Location = new Point3d(Data.table_x + 175, Data.table_y - 18, 0); objText7.Contents = "Обозначение на плане"; objText7.Height = 35; objText7.Width = 23; ObjColl.Add(objText7); MText objText8 = new MText(); objText8.SetDatabaseDefaults(); objText8.TextStyleId = acCurDb.Textstyle; objText8.TextHeight = 3; objText8.Location = new Point3d(Data.table_x + 198, Data.table_y - 18, 0); objText8.Contents = "Длина, м."; objText8.Height = 35; objText8.Width = 13; ObjColl.Add(objText8); MText objText9 = new MText(); objText9.SetDatabaseDefaults(); objText9.TextStyleId = acCurDb.Textstyle; objText9.TextHeight = 3; objText9.Location = new Point3d(Data.table_x + 212, Data.table_y - 18, 0); objText9.Contents = "Обозна-\nчение"; objText9.Height = 35; objText9.Width = 16; ObjColl.Add(objText9); MText objText10 = new MText(); objText10.SetDatabaseDefaults(); objText10.TextStyleId = acCurDb.Textstyle; objText10.TextHeight = 3; objText10.Location = new Point3d(Data.table_x + 227, Data.table_y - 18, 0); objText10.Contents = "Pуст. или Pном., КВт"; objText10.Height = 35; objText10.Width = 12; ObjColl.Add(objText10); MText objText11 = new MText(); objText11.SetDatabaseDefaults(); objText11.TextStyleId = acCurDb.Textstyle; objText11.TextHeight = 3; objText11.Location = new Point3d(Data.table_x + 239, Data.table_y - 18, 0); objText11.Contents = "Iрасч. или Iном. Iпуск., А."; objText11.Height = 35; objText11.Width = 12; ObjColl.Add(objText11); MText objText12 = new MText(); objText12.SetDatabaseDefaults(); objText12.TextStyleId = acCurDb.Textstyle; objText12.TextHeight = 3; objText12.Location = new Point3d(Data.table_x + 252, Data.table_y - 18, 0); objText12.Contents = "Наименование, тип, обозначение чертежа, принципиальной схемы."; objText12.Height = 35; objText12.Width = 35; ObjColl.Add(objText12); DBText acText = new DBText(); acText.SetDatabaseDefaults(); acText.Position = new Point3d(Data.table_x + 62, Data.table_y - 48, 0); acText.Height = 3; acText.TextString = "Участок сети 1"; acText.Rotation = 1.570796; //Это 90 градусов в радианах. ObjColl.Add(acText); DBText acText1 = new DBText(); acText1.SetDatabaseDefaults(); acText1.Rotation = 1.570796; acText1.Height = 3; acText1.Position = new Point3d(Data.table_x + 100, Data.table_y - 48, 0); acText1.TextString = "Участок сети 2"; ObjColl.Add(acText1); DBText acText2 = new DBText(); acText2.SetDatabaseDefaults(); acText2.Rotation = 1.570796; acText2.Height = 3; acText2.Position = new Point3d(Data.table_x + 105, Data.table_y - 48, 0); acText2.TextString = "Участок сети"; ObjColl.Add(acText2); DBText acText3 = new DBText(); acText3.SetDatabaseDefaults(); acText3.Height = 3; acText3.Position = new Point3d(Data.table_x + 123, Data.table_y - 8, 0); acText3.TextString = "Кабель, провод"; ObjColl.Add(acText3); //acText.WidthFactor = 0.5; DBText acText4 = new DBText(); acText4.SetDatabaseDefaults(); acText4.Height = 3; acText4.Position = new Point3d(Data.table_x + 185, Data.table_y - 8, 0); acText4.TextString = "Труба"; ObjColl.Add(acText4); DBText acText5 = new DBText(); acText5.SetDatabaseDefaults(); acText5.Height = 3; acText5.Position = new Point3d(Data.table_x + 230, Data.table_y - 8, 0); acText5.TextString = "Электроприемник"; ObjColl.Add(acText5); #endregion Data.table_y = Data.table_y - 30; double table_xx = Data.table_x, table_yy = Data.table_y - 20; #region Вставляем строки таблицы for (int j = 0; j < dataGridView1.Rows.Count - 1; j++) { Data.table_y = Data.table_y - 20; if (dataGridView1.Rows[j].Cells["Ветвь"].Value.ToString() == "Главная линия") { Line l_gl = new Line(new Point3d(Data.table_x + 25, Data.table_y - 20, 0), new Point3d(Data.table_x + 210, Data.table_y - 20, 0)); l_gl.LineWeight = LineWeight.LineWeight050; l_gl.ColorIndex = 4; ObjColl.Add(l_gl); } if (dataGridView1.Rows[j].Cells["Ветвь"].Value.ToString() == "Ответвление") { Line l_gl = new Line(new Point3d(Data.table_x + 62, Data.table_y, 0), new Point3d(Data.table_x + 60, Data.table_y - 2, 0)); l_gl.LineWeight = LineWeight.LineWeight050; l_gl.ColorIndex = 4; ObjColl.Add(l_gl); Line l_gl1 = new Line(new Point3d(Data.table_x + 60, Data.table_y - 2, 0), new Point3d(Data.table_x + 60, Data.table_y - 20, 0)); l_gl1.LineWeight = LineWeight.LineWeight050; l_gl1.ColorIndex = 4; ObjColl.Add(l_gl1); Line l_gl2 = new Line(new Point3d(Data.table_x + 60, Data.table_y - 20, 0), new Point3d(Data.table_x + 210, Data.table_y - 20, 0)); l_gl2.LineWeight = LineWeight.LineWeight050; l_gl2.ColorIndex = 4; ObjColl.Add(l_gl2); } if (dataGridView1.Rows[j].Cells["Род тока"].Value.ToString() == "1") { ObjColl.Add(new Line(new Point3d(Data.table_x + 51, Data.table_y - 17.5, 0), new Point3d(Data.table_x + 49, Data.table_y - 22.5, 0))); } if (dataGridView1.Rows[j].Cells["Род тока"].Value.ToString() == "3") { ObjColl.Add(new Line(new Point3d(Data.table_x + 51, Data.table_y - 17.5, 0), new Point3d(Data.table_x + 49, Data.table_y - 22.5, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 52, Data.table_y - 17.5, 0), new Point3d(Data.table_x + 50, Data.table_y - 22.5, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 50, Data.table_y - 17.5, 0), new Point3d(Data.table_x + 48, Data.table_y - 22.5, 0))); } ObjColl.Add(new Line(new Point3d(Data.table_x + 25, Data.table_y, 0), new Point3d(Data.table_x + 25, Data.table_y - 20, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 58, Data.table_y, 0), new Point3d(Data.table_x + 58, Data.table_y - 20, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 63, Data.table_y, 0), new Point3d(Data.table_x + 63, Data.table_y - 20, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 96, Data.table_y, 0), new Point3d(Data.table_x + 96, Data.table_y - 20, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 101, Data.table_y, 0), new Point3d(Data.table_x + 101, Data.table_y - 20, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 106, Data.table_y, 0), new Point3d(Data.table_x + 106, Data.table_y - 20, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 123, Data.table_y, 0), new Point3d(Data.table_x + 123, Data.table_y - 20, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 136, Data.table_y, 0), new Point3d(Data.table_x + 136, Data.table_y - 20, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 161, Data.table_y, 0), new Point3d(Data.table_x + 161, Data.table_y - 20, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 174, Data.table_y, 0), new Point3d(Data.table_x + 174, Data.table_y - 20, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 197, Data.table_y, 0), new Point3d(Data.table_x + 197, Data.table_y - 20, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 210, Data.table_y, 0), new Point3d(Data.table_x + 210, Data.table_y - 20, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 226, Data.table_y, 0), new Point3d(Data.table_x + 226, Data.table_y - 20, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 238, Data.table_y, 0), new Point3d(Data.table_x + 238, Data.table_y - 20, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 250, Data.table_y, 0), new Point3d(Data.table_x + 250, Data.table_y - 20, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 285, Data.table_y, 0), new Point3d(Data.table_x + 285, Data.table_y - 20, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 101, Data.table_y - 10, 0), new Point3d(Data.table_x + 210, Data.table_y - 10, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x + 210, Data.table_y - 20, 0), new Point3d(Data.table_x + 285, Data.table_y - 20, 0))); DBText acText6 = new DBText(); acText6.SetDatabaseDefaults(); acText6.Height = 3; acText6.Position = new Point3d(Data.table_x + 27, Data.table_y - 14, 0); acText6.TextString = dataGridView1.Rows[j].Cells["Аппарат"].Value.ToString(); ObjColl.Add(acText6); DBText acText7 = new DBText(); acText7.SetDatabaseDefaults(); acText7.Height = 3; acText7.Position = new Point3d(Data.table_x + 27, Data.table_y - 18, 0); acText7.TextString = dataGridView1.Rows[j].Cells["Ток"].Value.ToString(); ObjColl.Add(acText7); DBText acText8 = new DBText(); acText8.SetDatabaseDefaults(); acText8.Height = 3; acText8.Position = new Point3d(Data.table_x + 60, Data.table_y - 18, 0); acText8.TextString = dataGridView1.Rows[j].Cells["Фаза"].Value.ToString(); ObjColl.Add(acText8); DBText acText9 = new DBText(); acText9.SetDatabaseDefaults(); acText9.Height = 3; acText9.Position = new Point3d(Data.table_x + 65, Data.table_y - 18, 0); acText9.TextString = dataGridView1.Rows[j].Cells["Пусковой аппарат 1"].Value.ToString(); ObjColl.Add(acText9); DBText acText10 = new DBText(); acText10.SetDatabaseDefaults(); acText10.Height = 3; acText10.Position = new Point3d(Data.table_x + 65, Data.table_y - 14, 0); acText10.TextString = dataGridView1.Rows[j].Cells["Пусковой аппарат 2"].Value.ToString(); ObjColl.Add(acText10); DBText acText11 = new DBText(); acText11.SetDatabaseDefaults(); acText11.Height = 3; acText11.Position = new Point3d(Data.table_x + 65, Data.table_y - 10, 0); acText11.TextString = dataGridView1.Rows[j].Cells["Пусковой аппарат 3"].Value.ToString(); ObjColl.Add(acText11); DBText acText12 = new DBText(); acText12.SetDatabaseDefaults(); acText12.Height = 3; acText12.Position = new Point3d(Data.table_x + 108, Data.table_y - 8, 0); acText12.TextString = dataGridView1.Rows[j].Cells["Обозначение 1"].Value.ToString(); ObjColl.Add(acText12); DBText acText13 = new DBText(); acText13.SetDatabaseDefaults(); acText13.Height = 3; acText13.Position = new Point3d(Data.table_x + 125, Data.table_y - 8, 0); acText13.TextString = dataGridView1.Rows[j].Cells["Марка 1"].Value.ToString(); ObjColl.Add(acText13); DBText acText14 = new DBText(); acText14.SetDatabaseDefaults(); acText14.Height = 3; acText14.Position = new Point3d(Data.table_x + 138, Data.table_y - 8, 0); acText14.TextString = dataGridView1.Rows[j].Cells["Жилы 1"].Value.ToString() + "x" + dataGridView1.Rows[j].Cells["Сечение 1"].Value.ToString(); ObjColl.Add(acText14); DBText acText15 = new DBText(); acText15.SetDatabaseDefaults(); acText15.Height = 3; acText15.Position = new Point3d(Data.table_x + 163, Data.table_y - 8, 0); acText15.TextString = dataGridView1.Rows[j].Cells["Длина 1"].Value.ToString(); ObjColl.Add(acText15); DBText acText16 = new DBText(); acText16.SetDatabaseDefaults(); acText16.Height = 3; acText16.Position = new Point3d(Data.table_x + 108, Data.table_y - 18, 0); acText16.TextString = dataGridView1.Rows[j].Cells["Обозначение 2"].Value.ToString(); ObjColl.Add(acText16); DBText acText17 = new DBText(); acText17.SetDatabaseDefaults(); acText17.Height = 3; acText17.Position = new Point3d(Data.table_x + 125, Data.table_y - 18, 0); acText17.TextString = dataGridView1.Rows[j].Cells["Марка 2"].Value.ToString(); ObjColl.Add(acText17); DBText acText18 = new DBText(); acText18.SetDatabaseDefaults(); acText18.Height = 3; acText18.Position = new Point3d(Data.table_x + 138, Data.table_y - 18, 0); if (dataGridView1.Rows[j].Cells["Жилы 2"].Value.ToString() + "x" + dataGridView1.Rows[j].Cells["Сечение 2"].Value.ToString() != "x") acText18.TextString = dataGridView1.Rows[j].Cells["Жилы 2"].Value.ToString() + "x" + dataGridView1.Rows[j].Cells["Сечение 2"].Value.ToString(); else acText18.TextString = ""; ObjColl.Add(acText18); DBText acText19 = new DBText(); acText19.SetDatabaseDefaults(); acText19.Height = 3; acText19.Position = new Point3d(Data.table_x + 163, Data.table_y - 18, 0); acText19.TextString = dataGridView1.Rows[j].Cells["Длина 2"].Value.ToString(); ObjColl.Add(acText19); DBText acText20 = new DBText(); acText20.SetDatabaseDefaults(); acText20.Height = 3; acText20.Position = new Point3d(Data.table_x + 212, Data.table_y - 12, 0); acText20.TextString = dataGridView1.Rows[j].Cells["Обознач. прием."].Value.ToString(); ObjColl.Add(acText20); DBText acText21 = new DBText(); acText21.SetDatabaseDefaults(); acText21.Height = 3; acText21.Position = new Point3d(Data.table_x + 228, Data.table_y - 12, 0); acText21.TextString = dataGridView1.Rows[j].Cells["P"].Value.ToString(); ObjColl.Add(acText21); DBText acText22 = new DBText(); acText22.SetDatabaseDefaults(); acText22.Height = 3; acText22.Position = new Point3d(Data.table_x + 240, Data.table_y - 12, 0); acText22.TextString = dataGridView1.Rows[j].Cells["I"].Value.ToString(); ObjColl.Add(acText22); DBText acText23 = new DBText(); acText23.SetDatabaseDefaults(); acText23.Height = 3; acText23.Position = new Point3d(Data.table_x + 252, Data.table_y - 12, 0); acText23.TextString = dataGridView1.Rows[j].Cells["Наим. прием."].Value.ToString(); ObjColl.Add(acText23); DBText acText24 = new DBText(); acText24.SetDatabaseDefaults(); acText24.Height = 3; acText24.Position = new Point3d(Data.table_x + 103, Data.table_y - 8, 0); acText24.TextString = "1"; ObjColl.Add(acText24); DBText acText25 = new DBText(); acText25.SetDatabaseDefaults(); acText25.Height = 3; acText25.Position = new Point3d(Data.table_x + 103, Data.table_y - 18, 0); acText25.TextString = "2"; ObjColl.Add(acText25); } #endregion Line l_ver = new Line(new Point3d(table_xx + 25, table_yy - 20, 0), new Point3d(table_xx + 25, Data.table_y - 26.5, 0)); l_ver.LineWeight = LineWeight.LineWeight050; l_ver.ColorIndex = 4; ObjColl.Add(l_ver); Line l_ver1 = new Line(new Point3d(Data.table_x + 22.5, Data.table_y - 26.5, 0), new Point3d(Data.table_x + 27.5, Data.table_y - 26.5, 0)); l_ver1.LineWeight = LineWeight.LineWeight100; l_ver1.ColorIndex = 4; ObjColl.Add(l_ver1); ObjColl.Add(new Line(new Point3d(Data.table_x, table_yy, 0), new Point3d(Data.table_x, Data.table_y - 20, 0))); ObjColl.Add(new Line(new Point3d(Data.table_x, Data.table_y - 20, 0), new Point3d(Data.table_x + 63, Data.table_y - 20, 0))); Database wbd = HostApplicationServices.WorkingDatabase; bt = (BlockTable)trans.GetObject(wbd.BlockTableId, OpenMode.ForRead); btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite); foreach (Entity ent in ObjColl) { btr.AppendEntity(ent); trans.AddNewlyCreatedDBObject(ent, true); } trans.Commit(); trans.Dispose(); } } this.Show(); }
public static void PrintTitle(Database db, string textstring, Point2d PositionPoint, double scale = 100) { DBText title = new DBText(), scalestring = new DBText(); Line BLine, SLine; Regex regChina = new Regex("^[^\x00-\xFF]"); Regex regEnglish = new Regex("^[a-zA-Z]"); using (Transaction tr = db.TransactionManager.StartTransaction()) { TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable; double WdWidth; if (regEnglish.IsMatch(textstring[textstring.Length - 1].ToString())) { WdWidth = 2.5; scalestring.TextString = string.Format("Ech:1/{0:G0}", scale); } else { WdWidth = 5 * 0.7; scalestring.TextString = string.Format("1:{0:G0}", scale); } double WdLeng = textstring.Length * WdWidth * scale; BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable; BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; BLine = new Line(PositionPoint.Convert3D(-0.5 * WdLeng, 0), PositionPoint.Convert3D(0.5 * WdLeng, 0)); SLine = new Line(PositionPoint.Convert3D(-0.5 * WdLeng, -1 * scale), PositionPoint.Convert3D(0.5 * WdLeng, -1 * scale)); BLine.Layer = "标注"; BLine.LineWeight = LineWeight.LineWeight050; SLine.Layer = "标注"; BLine.ColorIndex = 1; title = new DBText(); title.TextString = textstring; title.Height = 5 * scale; title.Position = PositionPoint.Convert3D(); title.HorizontalMode = TextHorizontalMode.TextCenter; title.VerticalMode = TextVerticalMode.TextBottom; title.AlignmentPoint = PositionPoint.Convert3D(0, 0.5 * scale); scalestring.Position = PositionPoint.Convert3D(); scalestring.Height = 3.5 * scale; scalestring.HorizontalMode = TextHorizontalMode.TextCenter; scalestring.VerticalMode = TextVerticalMode.TextTop; scalestring.AlignmentPoint = PositionPoint.Convert3D(0, -2 * scale); title.TextStyleId = st["fsdb"]; scalestring.TextStyleId = st["fsdb"]; title.Layer = "标注"; scalestring.Layer = "标注"; title.WidthFactor = 0.75; scalestring.WidthFactor = 0.75; modelSpace.AppendEntity(BLine); tr.AddNewlyCreatedDBObject(BLine, true); modelSpace.AppendEntity(SLine); tr.AddNewlyCreatedDBObject(SLine, true); modelSpace.AppendEntity(title); tr.AddNewlyCreatedDBObject(title, true); modelSpace.AppendEntity(scalestring); tr.AddNewlyCreatedDBObject(scalestring, true); tr.Commit(); } return; }
public static void TestDrawVertexNumbers(this Polyline pl, Color color) { var scale =ScaleHelper.GetCurrentAnnoScale(HostApplicationServices.WorkingDatabase); for (int i = 0; i < pl.NumberOfVertices; i++) { var text = new DBText(); text.TextString = i.ToString(); text.Position = pl.GetPoint2dAt(i).Convert3d(); text.Height = 2.5 * scale; text.Color = color; EntityHelper.AddEntityToCurrentSpace(text); } }
/// <summary> /// 剖面标注 /// </summary> /// <param name="db"></param> /// <param name="theName"></param> /// <param name="StartPoint"></param> /// <param name="EndPoint"></param> /// <param name="scale"></param> public static void DimSection(Database db, char theName, Point2d StartPoint, Point2d EndPoint, double scale = 100) { Line[] Lset = new Line[2]; Polyline[] PLset = new Polyline[2]; double ang = new Line2d(StartPoint, EndPoint).Direction.Angle; using (Transaction tr = db.TransactionManager.StartTransaction()) { TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable; BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable; BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; for (int i = 0; i < 2; i++) { DBText t = new DBText() { TextString = theName.ToString(), Layer = "标注", Height = 4 * scale, TextStyleId = st["fsdb"], HorizontalMode = TextHorizontalMode.TextCenter, VerticalMode = TextVerticalMode.TextBottom, WidthFactor = 0.75, Rotation = ang, }; if (i == 0) { t.AlignmentPoint = StartPoint.Convert3D(0, 0.5 * scale); } else { t.AlignmentPoint = EndPoint.Convert3D(0, 0.5 * scale); } modelSpace.AppendEntity(t); tr.AddNewlyCreatedDBObject(t, true); Line L; Polyline PL = new Polyline(); Point2d p0 = new Point2d(), p1 = new Point2d(); L = i == 0 ? new Line(StartPoint.Convert3D(-1.5 * scale, 0), StartPoint.Convert3D(1.5 * scale, 0)) : new Line(EndPoint.Convert3D(-1.5 * scale, 0), EndPoint.Convert3D(1.5 * scale, 0)); p0 = i == 0 ? StartPoint : EndPoint; p1 = i == 0 ? StartPoint.Convert2D(0, -2 * scale) : EndPoint.Convert2D(0, -2 * scale); L.Layer = "标注"; L.ColorIndex = 1; L.TransformBy(Matrix3d.Rotation(ang, Vector3d.ZAxis, p0.Convert3D())); modelSpace.AppendEntity(L); tr.AddNewlyCreatedDBObject(L, true); PL.AddVertexAt(0, p0, 0, 0, 2 * scale); PL.AddVertexAt(1, p1, 0, 0, 0); PL.TransformBy(Matrix3d.Rotation(ang, Vector3d.ZAxis, p0.Convert3D())); modelSpace.AppendEntity(PL); tr.AddNewlyCreatedDBObject(PL, true); } tr.Commit(); } }
private Dictionary<Point3d, string> defineWindows(BlockReference blRefArPlan) { var windows = new Dictionary<Point3d, string>(); var btrArPlan = blRefArPlan.BlockTableRecord.GetObject(OpenMode.ForWrite) as BlockTableRecord; Dictionary<Point3d, string> marks = getAllMarks(btrArPlan); foreach (ObjectId idEnt in btrArPlan) { var blRefWindow = idEnt.GetObject(OpenMode.ForRead, false, true) as BlockReference; if (blRefWindow == null) continue; // Если это блок окна - имя начинается с WNW, на слое A-GLAZ //if (blRefWindow.Name.StartsWith("WNW", StringComparison.OrdinalIgnoreCase) && // blRefWindow.Layer.Equals("A-GLAZ", StringComparison.OrdinalIgnoreCase)) string blNameWindow = blRefWindow.GetEffectiveName(); if (Regex.IsMatch(blNameWindow, "окно", RegexOptions.IgnoreCase)) { // Найти рядом текст марки окна - в радиусе 1000 var markNearKey = marks.GroupBy(m => m.Key.DistanceTo(blRefWindow.Position))?.MinBy(m => m.Key); if (markNearKey == null || markNearKey.Key > 1000) { Extents3d extBlRefWin = blRefWindow.GeometricExtents; extBlRefWin.TransformBy(blRefArPlan.BlockTransform); Inspector.AddError($"Архитектурный план '{blRefArPlan.Name}' - " + $"Не определена марка окна около блока окна '{blNameWindow}'.", extBlRefWin, blRefWindow.Id, icon: System.Drawing.SystemIcons.Error); continue; } var markNear = markNearKey.First(); try { windows.Add(blRefWindow.Position, markNear.Value); } catch (Exception ex) { var extWin = blRefWindow.GeometricExtents; extWin.TransformBy(blRefArPlan.BlockTransform); Inspector.AddError($"Дублирование блока окна в '{btrArPlan.Name}' - {ex.Message}", extWin, blRefWindow.Id, icon: SystemIcons.Error); } #if Test //Test Добавить точку окна и найденную марку окна в точку вставки блока окна { //DBPoint ptWin = new DBPoint(blRefWindow.Position); //btrArPlan.AppendEntity(ptWin); //btrArPlan.Database.TransactionManager.TopTransaction.AddNewlyCreatedDBObject(ptWin, true); using (DBText dbText = new DBText()) { dbText.Position = blRefWindow.Position; dbText.TextString = markNear.Value; btrArPlan.AppendEntity(dbText); //btrArPlan.Database.TransactionManager.TopTransaction.AddNewlyCreatedDBObject(dbText, true); } } #endif } } return windows; }
//这是转换操作函数 private void convertToText(PromptSelectionResult SelResult) { //初始化转换计数 int count = 0; //获取选择集所有实体的ID ObjectId[] ObIDs = SelResult.Value.GetObjectIds(); //启动事务进行实体操作 using (Transaction trans = db.TransactionManager.StartTransaction()) { //加一个try进行异常处理 try { //遍历选择集中的所有实体 foreach (ObjectId ObID in ObIDs) { //依据实体ID获取实体对象 //为加快系统处理速度,OpenMode使用ForRead,轮到需要的实体时再用UpgradeOpen()改为ForWrite DBObject ent = trans.GetObject(ObID, OpenMode.ForRead) as DBObject; //属性块的情况麻烦些,单独拎出来 if (ent != null) { if (ent.GetType().Name == "BlockReference") { BlockReference blk = ent as BlockReference; //判断是否是动态块 if (blk.IsDynamicBlock) { AttributeCollection ac = blk.AttributeCollection; foreach (ObjectId arID in ac) { AttributeReference ar = arID.GetObject(OpenMode.ForWrite) as AttributeReference; if (ar.HasFields) { ar.ConvertFieldToText(); count++; } } } } if (ent.HasFields) { //获取实体的类型进行判断 switch (ent.GetType().Name) { //单行文字 case "DBText": { DBText Dt = (DBText)ent; //改为ForWrite Dt.UpgradeOpen(); //利用DBText的ConvertFieldToText()方法转换 //注:该方法用在不含有字段的文字时会报错 Dt.ConvertFieldToText(); count++; break; } //多行文字 case "MText": { MText Dt = (MText)ent; Dt.UpgradeOpen(); Dt.ConvertFieldToText(); count++; break; } } } } } //提交事务保存 trans.Commit(); } catch (Autodesk.AutoCAD.Runtime.Exception Ex) { ed.WriteMessage("\n出错了!" + Ex.ToString()); } finally { //关闭事务 trans.Dispose(); } } ed.WriteMessage("\n完成转换" + count + "个字段"); }
private void AddText(string val, Point3d pt, double height) { try { DBText text = new DBText(); text.Position = pt; text.TextStyleId = panelBase.Service.Db.GetTextStylePIK(); text.TextString = val; text.Height = height; btrDim.AppendEntity(text); t.AddNewlyCreatedDBObject(text, true); } catch { } }
whip() { bool escape; Entity ent = Select.selectEntity("Select the text: ", out escape); if (escape) { return; } ResultBuffer rb = null; List <string> appList = new List <string>(); if (ent is DBText) { DBText txt = (DBText)ent; rb = txt.GetXDataForApplication(null); if (rb == null) { Txt.rotateText180(ent.ObjectId); } else { TypedValue[] tvs = rb.AsArray(); List <TypedValue[]> tvsList = tvs.parseXData(out appList); if (appList.Contains(apps.lnkGS)) { } } } else if (ent is MText) { MText mTxt = (MText)ent; ObjectId idMTxt = mTxt.ObjectId; rb = mTxt.GetXDataForApplication(null); if (rb == null) { Txt.rotateText180(ent.ObjectId); } else { TypedValue[] tvsMTxt = rb.AsArray(); List <TypedValue[]> tvsList = tvsMTxt.parseXData(out appList); if (appList.Contains(apps.lnkGS)) { rb = mTxt.GetXDataForApplication(apps.lnkGS); TypedValue[] tvs = rb.AsArray(); ObjectId idPnt1 = tvs[9].Value.ToString().stringToHandle().getObjectId(); ObjectId idPnt2 = tvs[10].Value.ToString().stringToHandle().getObjectId(); Point3d pnt3d1, pnt3d2; if (idPnt1.IsValid) { pnt3d1 = idPnt1.getCogoPntCoordinates(); } else { pnt3d1 = Mod.stringCoordinateListToPoint3d(tvsMTxt[11]); } if (idPnt2.IsValid) { pnt3d2 = idPnt2.getCogoPntCoordinates(); } else { pnt3d2 = Mod.stringCoordinateListToPoint3d(tvsMTxt[11]); } double station = double.Parse(tvs[5].Value.ToString()); double offset = double.Parse(tvs[6].Value.ToString()); Point3d pnt3dBase = pnt3d1.traverse(pnt3d1.getDirection(pnt3d2), station); double angle = pnt3dBase.getDirection(mTxt.Location); pnt3dBase = pnt3dBase.traverse(angle, offset); Mod.rotateEnt(ent.ObjectId, pnt3dBase, PI); } else { if (appList.Contains(apps.lnkCO)) { rb = mTxt.GetXDataForApplication(apps.lnkCO); TypedValue[] tvs = rb.AsArray(); ObjectId idldr = tvs.getObjectId(3); Point3d pnt3dBase = idldr.getEndPnt(); idMTxt.flipMTxt(pnt3dBase); ObjectId id = tvs.getObjectId(4); if (id.IsNull) { return; } } else if (appList.Contains(apps.lnkLD)) { } } } } }
copyTextContentsToTextEnt(SelectionSet SS0, SelectionSet SSX) { string strContents = string.Empty; try { using (Transaction tr = BaseObjs.startTransactionDb()) { ObjectId[] objIDs = null; ObjectId objID0 = ObjectId.Null; ObjectId objIDX = ObjectId.Null; objIDs = SS0.GetObjectIds(); if (objIDs.Length == 1) { objID0 = objIDs[0]; Autodesk.AutoCAD.DatabaseServices.DBObject dbObj0 = tr.GetObject(objID0, OpenMode.ForRead); try { DBText TXT = (DBText)dbObj0; if (TXT != null) { strContents = TXT.TextString.ToString(); } else { MText mTXT = (MText)dbObj0; if (mTXT != null) { strContents = mTXT.Text.ToString(); } } } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " Mod.cs: line: 192"); } } objIDs = SSX.GetObjectIds(); if (objIDs.Length == 1) { objIDX = objIDs[0]; Autodesk.AutoCAD.DatabaseServices.DBObject dbObjX = tr.GetObject(objIDX, OpenMode.ForWrite); try { DBText TXT = (DBText)dbObjX; if (TXT != null) { TXT.TextString = strContents; } else { MText mTXT = (MText)dbObjX; if (mTXT != null) { mTXT.Contents = strContents; } } } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " Mod.cs: line: 219"); } } else if (objIDs.Length > 1) { foreach (ObjectId objID in objIDs) { Autodesk.AutoCAD.DatabaseServices.DBObject dbObjX = tr.GetObject(objID, OpenMode.ForWrite); try { DBText TXT = (DBText)dbObjX; if (TXT != null) { TXT.TextString = strContents; } else { MText mTXT = (MText)dbObjX; if (mTXT != null) { mTXT.Contents = strContents; } } } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " Mod.cs: line: 245"); } } } tr.Commit(); } //end using } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " Mod.cs: line: 255"); } }
public void GetCutFillArea() { var sOptions = new PromptSelectionOptions() { SingleOnly = true, AllowDuplicates = false, }; var polyLine = DBDictionary.GetClass(typeof(Polyline)).DxfName; var filter = new SelectionFilter(new[] { new TypedValue((int)DxfCode.Start, polyLine), }); ED.WriteMessage("Select EG PLine"); var selection1 = ED.GetSelection(sOptions, filter); if (selection1.Status != PromptStatus.OK) { return; } var id1 = selection1.Value.GetObjectIds()[0]; ED.WriteMessage("Select Intermediate PLine"); var selection2 = ED.GetSelection(sOptions, filter); if (selection2.Status != PromptStatus.OK) { return; } var id2 = selection2.Value.GetObjectIds()[0]; ED.WriteMessage("Select Design PLine"); var selection3 = ED.GetSelection(sOptions, filter); if (selection3.Status != PromptStatus.OK) { return; } var id3 = selection3.Value.GetObjectIds()[0]; TInvoke(t => { var p1 = (Polyline)t.GetObject(id1, OpenMode.ForRead); var p2 = (Polyline)t.GetObject(id2, OpenMode.ForRead); var p3 = (Polyline)t.GetObject(id3, OpenMode.ForRead); var(cut, fill) = CalculateArea(t, p1, p2, p3); ED.WriteMessage($"Cut: {cut.ToString("N", NFormat)}, Fill: {fill.ToString("N", NFormat)}"); ED.WriteMessage("Select Point To Place Labels:"); var res = ED.GetPoint(new PromptPointOptions("Pick Point To Place Labels")); if (res.Status == PromptStatus.OK) { var point = res.Value; var label = new DBText { TextString = $"{cut.ToString("N", NFormat)}", Height = 0.4, Position = point, Color = Color.FromColor(System.Drawing.Color.Red) }; var label2 = new DBText { TextString = $"{fill.ToString("N", NFormat)}", Height = 0.4, Position = point.Add(new Vector3d(3, 0, 0)), Color = Color.FromColor(System.Drawing.Color.Green) }; var btr = (BlockTableRecord)t.GetObject(Db.CurrentSpaceId, OpenMode.ForWrite); btr.AppendEntity(label); btr.AppendEntity(label2); t.AddNewlyCreatedDBObject(label, true); t.AddNewlyCreatedDBObject(label2, true); } }); }
private Dictionary<string, PanelBase> matchingPlans(List<FacadeMounting> facadesMounting, List<FloorArchitect> floorsAr) { // Определение окон в монтажных планах по архитектурным планам var panelsBase = new Dictionary<string, PanelBase>(); // string - ключ - маркаСБ + Марки Окон по порядку. // Список монтажных планов - уникальных var floorsMount = facadesMounting.SelectMany(f => f.Floors); foreach (var floorMount in floorsMount) { // Найти соотв арх план var floorAr = floorsAr.Find(f => f.Section == floorMount.Section && f.IsEqualMountingStorey(floorMount.Storey) ); //Test Добавить текст имени плана Ар в блок монтажного плана #if Test { if (floorAr != null) { using (var btrMount = floorMount.IdBtrMounting.Open(OpenMode.ForWrite) as BlockTableRecord) { DBText textFindPlanAr = new DBText(); textFindPlanAr.TextString = floorAr.BlName; btrMount.AppendEntity(textFindPlanAr); //btrMount.Database.TransactionManager.TopTransaction.AddNewlyCreatedDBObject(textFindPlanAr, true); } } } #endif if (floorAr == null) { Inspector.AddError($"Не найден блок архитектурного плана для соответствующего монтажного плана '{floorMount.BlRefName}'", floorMount.IdBlRefMounting, icon: System.Drawing.SystemIcons.Error); } else if (floorAr.Windows.Count == 0) { Inspector.AddError($"Не найдено ни одного окна в блоке архитектурного плана '{floorMount.BlRefName}'.", floorAr.IdBlRef, icon: System.Drawing.SystemIcons.Error); } foreach (var panelMount in floorMount.PanelsSbInFront) { Panel panelXml = GetPanelXml(panelMount.MarkSb, panelMount); if (panelXml == null) continue; PanelBase panelBase = new PanelBase(panelXml, this, panelMount); // Определение окон в панели по арх плану if (panelXml.windows?.window != null) { foreach (var window in panelXml.windows.window) { if (floorAr == null || floorAr.Windows.Count==0) { break; } // Точка окна внутри панели по XML описанию Point3d ptOpeningCenter = new Point3d(window.posi.X + window.width * 0.5, 0, 0); // Точка окна внутри монтажного плана Point3d ptWindInModel = panelMount.ExtTransToModel.MinPoint.Add(ptOpeningCenter.GetAsVector()); Point3d ptWindInArPlan = ptWindInModel.TransformBy(floorMount.Transform.Inverse()); var windowKey = floorAr?.Windows.GroupBy(w => w.Key.DistanceTo(ptWindInArPlan))?.MinBy(w => w.Key); if (windowKey == null || windowKey.Key > 600) { Inspector.AddError( $"Не найдено соответствующее окно в архитектурном плане. Блок монтажной панели {panelMount.MarkSb}", panelMount.ExtTransToModel, panelMount.IdBlRef, icon: System.Drawing.SystemIcons.Error); continue; } panelBase.WindowsBaseCenters.Add(ptOpeningCenter, windowKey.First().Value); // Test Добавление точек окна в блоке монтажки #if Test { using (var btrMountPlan = floorMount.IdBtrMounting.Open(OpenMode.ForWrite) as BlockTableRecord) { using (DBPoint ptWinInPlan = new DBPoint(ptWindInArPlan)) { ptWinInPlan.ColorIndex = 2; btrMountPlan.AppendEntity(ptWinInPlan); //btrMountPlan.Database.TransactionManager.TopTransaction.AddNewlyCreatedDBObject(ptWinInPlan, true); } using (DBText dbText = new DBText()) { dbText.Position = ptWindInArPlan; dbText.TextString = windowKey.First().Value; btrMountPlan.AppendEntity(dbText); //btrMountPlan.Database.TransactionManager.TopTransaction.AddNewlyCreatedDBObject(dbText, true); } } using (var btrArPlan = floorAr.IdBtr.Open(OpenMode.ForWrite) as BlockTableRecord) { using (DBPoint ptWinInArPlan = new DBPoint(ptWindInArPlan)) { ptWinInArPlan.ColorIndex = 1; btrArPlan.AppendEntity(ptWinInArPlan); //btrArPlan.Database.TransactionManager.TopTransaction.AddNewlyCreatedDBObject(ptWinInArPlan, true); } } } #endif } } // Уникальный ключ панели - МаркаСБ + Марки окон string key = panelBase.MarkWithoutElectric; if (panelBase.WindowsBaseCenters.Count > 0) { string windowMarks = string.Join(";", panelBase.WindowsBaseCenters.Values); key += windowMarks; } PanelBase panelBaseUniq; if (!panelsBase.TryGetValue(key, out panelBaseUniq)) { panelsBase.Add(key, panelBase); panelBaseUniq = panelBase; } panelMount.PanelBase = panelBaseUniq; } } return panelsBase; }
private DBText GetDBText(string text) { DBText dBText = new DBText(); dBText.SetDatabaseDefaults(_db); dBText.TextStyleId =_idTextstylePik; dBText.Color =Color.FromColorIndex( ColorMethod.ByLayer, 256); dBText.Linetype= SymbolUtilityServices.LinetypeByLayerName; dBText.LineWeight = LineWeight.ByLayer; dBText.TextString =text; dBText.Height = Settings.Default.CaptionPanelTextHeight; dBText.Annotative = AnnotativeStates.False; dBText.Layer=_captionLayer; return dBText; }