Customizing a "DimensionStyle"

Customizing a "DimensionStyle"

youssefGC
Advocate Advocate
279 Views
2 Replies
Message 1 of 3

Customizing a "DimensionStyle"

youssefGC
Advocate
Advocate

Hello Forums,

 

I am currently working with "AlignedDimension", and I am facing a problem. Every time I create an instance of "AlignedDimension". 

For example when I create an instance of "AlignedDimension," I need to modify the style of the arrowheads at the instance. The following code excerpt demonstrates this operation :

 

 

AlignedDimension dim = new AlignedDimension(
                new Point3d(0,0,0),new Point3d(3, 5, 0),
                new Point3d(1.5, 1.5, 0),
                "Title",
                _doc.Database.DimStyleTableId);

            dim.Dimblk1 = _ArrowStyleID1;
            dim.Dimblk2 = _ArrowStyleID2;

 

 

 

_ArrowStyleID1 and _ArrowStyleID2 are Object IDs pointing to the values of DIMBLK1 and DIMBLK2 (retrieved using GetSystemVariable)

 

My question : Is it possible to modify these properties once at the "DimensionStyle" instead of making changes at the instance repeatedly ?

 

Thank You.

 

 

 

0 Likes
280 Views
2 Replies
Replies (2)
Message 2 of 3

kerry_w_brown
Advisor
Advisor

Sounds like you need this :

[quote]

A new dimension style is created by creating an instance of a DimStyleTableRecord object and then adding it to the DimStyleTable with the Add method. Before the dimension style is added to the table, set the name of the new style with the Name property.

[/quote]

Create, Modify, and Copy Dimension Styles (.NET)

https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-F8176D55-ED39-4FAA-93F7-D6E023C1DAD1

 

Regards,

 

 


// Called Kerry or kdub in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect. ~ kdub
Sometimes the question is more important than the answer. ~ kdub

NZST UTC+12 : class keyThumper<T> : Lazy<T>;      another  Swamper
Message 3 of 3

youssefGC
Advocate
Advocate

Thank you for your reply,

 

I attempted to customize the code for my specific situation, but it isn't functioning as expected; it continues to maintain the arrow styles.

 

 

 

// Open the Block table for read
                BlockTable acBlkTbl = tr.GetObject(db.BlockTableId,
                                                OpenMode.ForRead) as BlockTable;

                // Open the Block table record Model space for read
                BlockTableRecord acBlkTblRec = tr.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
                                                OpenMode.ForRead) as BlockTableRecord;

                // Open the DimStyle table for read
                DimStyleTable acDimStyleTbl = tr.GetObject(db.DimStyleTableId,
                                                    OpenMode.ForRead) as DimStyleTable;

                // Keep a reference of the first dimension style for later
                DimStyleTableRecord acDimStyleTblRec;

                // Check to see if the dimension style exists or not
                if (acDimStyleTbl.Has("newStyle") == false)
                {
                    if (acDimStyleTbl.IsWriteEnabled == false) tr.GetObject(db.DimStyleTableId, OpenMode.ForWrite);

                    acDimStyleTblRec = new DimStyleTableRecord();
                    acDimStyleTblRec.Name = "newStyle";
                    acDimStyleTblRec.Dimsah = true;
                    acDimStyleTblRec.Dimblk1 =_ArrowStyleID1;
                    acDimStyleTblRec.Dimblk1 =_ArrowStyleID2;

                    acDimStyleTbl.Add(acDimStyleTblRec);
                    tr.AddNewlyCreatedDBObject(acDimStyleTblRec, true);
                }

                _DimStyle = acDimStyleTbl["newStyle"];

 

 

 

To clarify my situation, here is the function I used to access _ArrowStyleID1 and _ArrowStyleID2:

 

 

static ObjectId GetArrowObjectId(string arrow, string newArrName)
        {
            ObjectId arrObjId = ObjectId.Null;
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;

            string oldArrName = Application.GetSystemVariable(arrow) as string;
            Application.SetSystemVariable(arrow, newArrName);

            if (oldArrName.Length != 0)
                Application.SetSystemVariable(arrow, oldArrName);

            Transaction tr = db.TransactionManager.StartTransaction();

            using (tr)
            {
                BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
                arrObjId = bt[newArrName];
               
                tr.Commit();
            }


            return arrObjId;
        }

 

 

 

And how do I implement it in the main program :

ObjectId ArrowStyleID1 = GetArrowObjectId("DIMBLK1", "_DOT");
ObjectId ArrowStyleID2 = GetArrowObjectId("DIMBLK2", "_CLOSED");

 

 

 

 

0 Likes