addBlockRef(string strName, string strTop, string strMid, string strBot, Point3d pnt3dIns, double dblRotation) { Database DB = BaseObjs._db; Editor ED = BaseObjs._editor; BlockTableRecord Btrx = null; BlockReference BR = null; try { using (Transaction tr = BaseObjs.startTransactionDb()) { BlockTable BT = (BlockTable)DB.BlockTableId.GetObject(OpenMode.ForRead); if (!BT.Has(strName)) { Btrx = addBtr(strName); Blocks.addAttributesToBlock(strName); } else { Btrx = (BlockTableRecord)BT[strName].GetObject(OpenMode.ForRead); } //---> debug only foreach (ObjectId objID in Btrx) { Entity ENT = (Entity)objID.GetObject(OpenMode.ForRead); AttributeDefinition AD = ENT as AttributeDefinition; if (AD != null) { ED.WriteMessage(string.Format("\n{0}", AD.Tag)); } }//<--- debug only //BlockTableRecord Btr = (BlockTableRecord)DB.CurrentSpaceId.GetObject(OpenMode.ForWrite); Btrx.UpgradeOpen(); using (Btrx) { BR = new BlockReference(pnt3dIns, Btrx.ObjectId); using (BR) { Matrix3d UCSMatrix = ED.CurrentUserCoordinateSystem; CoordinateSystem3d UCS = UCSMatrix.CoordinateSystem3d; Matrix3d MAT3d = new Matrix3d(); MAT3d = Matrix3d.Rotation(dblRotation, UCS.Zaxis, pnt3dIns); BR.TransformBy(MAT3d); BR.ScaleFactors = new Scale3d(1, 1, 1); Btrx.AppendEntity(BR); tr.AddNewlyCreatedDBObject(BR, true); BlockTableRecord Btratt = (BlockTableRecord)BR.BlockTableRecord.GetObject(OpenMode.ForRead); using (Btratt) { Autodesk.AutoCAD.DatabaseServices.AttributeCollection ATTcol = BR.AttributeCollection; foreach (ObjectId subID in Btratt) { Entity ENT = (Entity)subID.GetObject(OpenMode.ForRead); AttributeDefinition AD = ENT as AttributeDefinition; if (AD != null) { AttributeReference AR = new AttributeReference(); AR.SetPropertiesFrom(AD); AR.SetAttributeFromBlock(AD, BR.BlockTransform); AR.Visible = AD.Visible; AR.HorizontalMode = AD.HorizontalMode; AR.VerticalMode = AD.VerticalMode; AR.Rotation = AD.Rotation; AR.TextStyleId = AD.TextStyleId; AR.Position = AD.Position + pnt3dIns.GetAsVector(); AR.Tag = AD.Tag; AR.FieldLength = AD.FieldLength; AR.AdjustAlignment(DB); if (AR.Tag == "TOPTXT") { AR.TextString = strTop; } if (AR.Tag == "MIDTXT") { AR.TextString = strMid; } if (AR.Tag == "BOTTXT") { AR.TextString = strBot; } AR.Position = AD.Position.TransformBy(BR.BlockTransform); ATTcol.AppendAttribute(AR); tr.AddNewlyCreatedDBObject(AR, true); } } } BR.DowngradeOpen(); } Btrx.DowngradeOpen(); } tr.Commit(); } } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " Blocks.cs: line: 305"); } return(BR); }