private static void AddRegDescrDimLine(Complex c1, Complex c2, double k, string dimstyle) { var db = Application.DocumentManager.MdiActiveDocument.Database; using (var acTrans = db.TransactionManager.StartTransaction()) { // Open the Block table for read var acBlkTbl = (BlockTable)acTrans.GetObject(db.BlockTableId, OpenMode.ForRead); // Open the Block table record Model space for write var acBlkTblRec = (BlockTableRecord)acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite); // Create the dimension var qq = new Complex((c2 - c1) * Complex.polar(1.0, Math.PI / 2.0)); qq /= qq.abs(); qq *= k; qq += (c2 + c1) / 2.0; var acRotDim = new AlignedDimension(); acRotDim.SetDatabaseDefaults(); acRotDim.XLine1Point = new Point3d(c1.real(), c1.imag(), 0); acRotDim.XLine2Point = new Point3d(c2.real(), c2.imag(), 0); acRotDim.DimLinePoint = new Point3d(qq.real(), qq.imag(), 0); try { // Open the DimStyle table for read var acDimStyleTbl = (DimStyleTable)acTrans.GetObject(db.DimStyleTableId, OpenMode.ForRead); var acDimStyleTblRec1 = (DimStyleTableRecord)acTrans.GetObject(acDimStyleTbl[dimstyle], OpenMode.ForWrite); acRotDim.SetDimstyleData(acDimStyleTblRec1); acRotDim.DimensionStyle = acDimStyleTbl[dimstyle]; } catch { acRotDim.DimensionStyle = db.Dimstyle; } acRotDim.LayerId = DrawingHelper.LayerManipulator.CreateLayer("DIM", System.Drawing.Color.Red); // Add the new object to Model space and the transaction acBlkTblRec.AppendEntity(acRotDim); acTrans.AddNewlyCreatedDBObject(acRotDim, true); // Commit the changes and dispose of the transaction acTrans.Commit(); } }
private static AlignedDimension AddDim(Complex c1, Complex c2, double k, string layer, System.Drawing.Color color, string dimstyle, Transaction acTrans) { var db = Application.DocumentManager.MdiActiveDocument.Database; // Open the Block table for read var acBlkTbl = (BlockTable)acTrans.GetObject(db.BlockTableId, OpenMode.ForRead); // Open the Block table record Model space for write var acBlkTblRec = (BlockTableRecord)acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite); var acLyrTbl = (LayerTable)acTrans.GetObject(db.LayerTableId, OpenMode.ForRead); // Create the dimension var qq = new Complex((c2 - c1) * Complex.polar(1.0, Math.PI / 2.0)); qq /= qq.abs(); qq *= k; qq += (c2 + c1) / 2.0; var acRotDim = new AlignedDimension(); acRotDim.SetDatabaseDefaults(); acRotDim.XLine1Point = new Point3d(c1.real(), c1.imag(), 0); acRotDim.XLine2Point = new Point3d(c2.real(), c2.imag(), 0); acRotDim.DimLinePoint = new Point3d(qq.real(), qq.imag(), 0); try { if (layer.Contains("Current") && layer.Contains("Layer")) { throw new ArgumentNullException(); } acRotDim.Layer = layer; } catch { var acLyrTblRec = (LayerTableRecord)acTrans.GetObject(db.Clayer, OpenMode.ForWrite); acRotDim.Layer = acLyrTblRec.Name; } try { //MessageBox.Show("U2d Dim color =" + color.Name); if (color.Name.Contains("ByL")) { throw new ArgumentNullException(); } acRotDim.Color = Color.FromColor(color); } catch { try { if (layer.Contains("Current") && layer.Contains("Layer")) { throw new ArgumentNullException(); } var acLyrTblRec = (LayerTableRecord)acTrans.GetObject(acLyrTbl[layer], OpenMode.ForWrite); acRotDim.Color = acLyrTblRec.Color; } catch { var acLyrTblRec = (LayerTableRecord)acTrans.GetObject(db.Clayer, OpenMode.ForWrite); acRotDim.Color = acLyrTblRec.Color; } } try { // Open the DimStyle table for read var acDimStyleTbl = (DimStyleTable)acTrans.GetObject(db.DimStyleTableId, OpenMode.ForRead); var acDimStyleTblRec1 = (DimStyleTableRecord)acTrans.GetObject(acDimStyleTbl[dimstyle], OpenMode.ForWrite); acRotDim.SetDimstyleData(acDimStyleTblRec1); } catch { acRotDim.DimensionStyle = db.Dimstyle; } // Add the new object to Model space and the transaction acBlkTblRec.AppendEntity(acRotDim); acTrans.AddNewlyCreatedDBObject(acRotDim, true); return(acRotDim); }