public void LevelLabel() { if (!CheckLicense.Check()) { return; } if (!init) { if (!ShowSettings()) { return; } } while (true) { PromptPointOptions ptOpts = new PromptPointOptions("\nKot noktası: [Reset/Güncelle]", "Reset Update"); PromptPointResult ptRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetPoint(ptOpts); if (ptRes.Status == PromptStatus.Cancel) { return; } else if (ptRes.Status == PromptStatus.Keyword && ptRes.StringResult == "Reset") { Reset(); return; } else if (ptRes.Status == PromptStatus.Keyword && ptRes.StringResult == "Update") { PromptSelectionResult selRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetSelection(); if (selRes.Status != PromptStatus.OK) { return; } UpdateLevelBlocks(selRes.Value.GetObjectIds()); return; } else { Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Autodesk.AutoCAD.DatabaseServices.Database db = doc.Database; ObjectId blockId = ObjectId.Null; using (Transaction tr = db.TransactionManager.StartTransaction()) using (BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead)) { if (bt.Has(BlockName)) { blockId = bt[BlockName]; } tr.Commit(); } if (blockId.IsNull) { MessageBox.Show("Kot bloğu '" + BlockName + "' bulunamadı.", "Level", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string level = GetLevel(ptRes.Value); Matrix3d ucs2wcs = AcadUtility.AcadGraphics.UcsToWcs; Point3d ptWorld = ptRes.Value.TransformBy(ucs2wcs); double rotation = Math.Atan2(ucs2wcs.CoordinateSystem3d.Xaxis.Y, ucs2wcs.CoordinateSystem3d.Xaxis.X); using (Transaction tr = db.TransactionManager.StartTransaction()) using (BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)) { BlockReference bref = new BlockReference(ptWorld, blockId); bref.Rotation = rotation; bref.ScaleFactors = new Scale3d(BlockScale); btr.AppendEntity(bref); tr.AddNewlyCreatedDBObject(bref, true); Dictionary <AttributeReference, AttributeDefinition> dict = new Dictionary <AttributeReference, AttributeDefinition>(); BlockTableRecord blockDef = tr.GetObject(blockId, OpenMode.ForRead) as BlockTableRecord; foreach (ObjectId id in blockDef) { AttributeDefinition attDef = tr.GetObject(id, OpenMode.ForRead) as AttributeDefinition; if ((attDef != null) && (!attDef.Constant)) { // Create a new AttributeReference AttributeReference attRef = new AttributeReference(); dict.Add(attRef, attDef); attRef.SetAttributeFromBlock(attDef, bref.BlockTransform); attRef.TextString = level; bref.AttributeCollection.AppendAttribute(attRef); tr.AddNewlyCreatedDBObject(attRef, true); } } if (LevelJig.Jig(ptRes.Value, bref, dict)) { Line line = new Line(); line.StartPoint = ptWorld; line.EndPoint = bref.Position; btr.AppendEntity(line); tr.AddNewlyCreatedDBObject(line, true); tr.Commit(); } else { bref.Dispose(); tr.Abort(); return; } } } } }