Creating a new dimension style and make it as current

By Virupaksha Aithal

Below code create a new dimension style and make the newly created dimension style as current.

[CommandMethod("NewDimStyle")]
 public void NewDimStyle()
 {
     Database db = 
         Application.DocumentManager.MdiActiveDocument.Database;
     using (Transaction trans = 
         db.TransactionManager.StartTransaction())
     {
         DimStyleTable DimTabb = 
             (DimStyleTable)trans.GetObject(db.DimStyleTableId, 
                            OpenMode.ForRead);
         ObjectId dimId = ObjectId.Null;
 
         if (!DimTabb.Has("Test"))
         {
             DimTabb.UpgradeOpen();
             DimStyleTableRecord newRecord = 
                            new DimStyleTableRecord();
             newRecord.Name = "Test";
             dimId = DimTabb.Add(newRecord);
             trans.AddNewlyCreatedDBObject(newRecord, true);
         }
         else
         {
             dimId = DimTabb["Test"];
         }
         DimStyleTableRecord DimTabbRecaord = 
             (DimStyleTableRecord)trans.GetObject(dimId, 
                                            OpenMode.ForRead);
 
         if (DimTabbRecaord.ObjectId != db.Dimstyle)
         {
             db.Dimstyle = DimTabbRecaord.ObjectId;
             db.SetDimstyleData(DimTabbRecaord);
         }
         trans.Commit();
     }
 
 }

Comments

6 responses to “Creating a new dimension style and make it as current”

  1. Matus Brlit Avatar
    Matus Brlit

    When I create a new dimension style, it looks like override of the previously current one. In the description, it says ISO-25 + ‘all the overriden properties’
    It then causes problem when changing arrow type. Is there a way to create new dimension style without any relation to an existing one?

  2. Hi,
    above code should create a new dimension style without any relation to exiting one. So, not sure about steps you are following to create the new dim style
    regards
    Viru

  3. owen gayo Avatar
    owen gayo

    how can i use dimension style from another drawing to the current drawing

  4. Nathan R Avatar
    Nathan R

    I know this is quite old but for future searchers like me: I ran into the same issue (existing drawing, adding a new style and changing some of the dims to use the new style).
    I commented out the db.SetDimstyleData line and it stopped overriding the existing style.

  5. For anyone finding this like 13 years later. without the “db.SetDimstyleData(DimTabbRecaord);”
    It wont make the style current when drawing the command. Its creates the dimension, says its on the right style, but doesnt display the style correctly..

  6. Daniel Avatar
    Daniel

    What about the text style associated with the dimension style? I couldn’t seem to find how to do it.

Leave a Reply to DanielCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading