Anotation Style Creation in Version 7

I am trying to create an annotation style. From looking at the examples I came up with this:

        //Create the style and return the index. Don't save with the file.
        int dsi = doc.DimStyles.Add("ToolingList",false);
        DimensionStyle ds = doc.DimStyles[dsi];
        ds.Font = new Font("Arial Black", FontWeight.Bold, Font.FontStyle.Upright, false, false);
        ds.DimensionScale = 5.0;
        ds.LengthResolution = (int)1.1;
        ds.AngleResolution = (int)1.1;
        ds.TextHeight = 5;
        ds.TextGap = .25;
        ds.ExtensionLineExtension = 3.5;
        ds.ExtensionLineOffset = 1.9;
        ds.LeaderArrowLength = 3.1;
        ds.ArrowLength = 2.2;
        ds.TextHorizontalAlignment = TextHorizontalAlignment.Auto;
        **ds.CommitChanges();**   

There is no method “CommitChanges” in the DimensionStyle class and changes are not stored without some action i think. If I run the code without the CommitChanges it will create the style but does not change any of the attributes.

Should there be something here to commit the changes to the new style?

Is there a class that allows you to create the style in code then assign it to doc.DimStyles? This looks like it is setup to be a fail save when you have to create the style then change attributes from the default.

Please let me know if I am looking in the wrong spot in the documentation for the API.

Best;

Steve

Hi @slyon,

After modifying a dimension style’s properties. use DimStyleTable.Modify to commit the modification to the document.

– Dale

Dale:

Thanks for the reply, need just a bit more help:

        int dsi = doc.DimStyles.Add("ToolingList",false);
        DimensionStyle ds = doc.DimStyles[dsi];
        ds.Name = "ToolingList";
        ds.Font = new Font("Arial Black", FontWeight.Bold, Font.FontStyle.Upright, false, false);
        ds.DimensionScale = 5.0;
        DimStyleTable st = new DimStyleTable(doc);
        st.Modify(ds,dsi,true);

This does not compile due to the internal constructor for the DimStyleTable class. This must be due to my limited understanding of the API. I did not think that i would need to do any sort of reflection to grab the DimensionStyle table and make the change so if you can give me an example of how you would do it I would appreciate it.

Best;

Steve

Hi @slyonm

doc.DimStyles is the document’s DimStyleTable.

– Dale

Dale:

Thanks for all the help on this! I list the final code below so if others want to see what worked for me:

        //Create new Dimension style and return the index.
        int newDimensionStyleIndex = doc.DimStyles.Add("ToolingList",false);

        //Create a DimensionStyle object with the changes you want to make.
        DimensionStyle dimensionStyleChanges = new DimensionStyle();
        dimensionStyleChanges.DimTextLocation = DimensionStyle.TextLocation.InDimLine;
        dimensionStyleChanges.Font = new Font("Arial Rounded MT", FontWeight.Unset, Font.FontStyle.Upright, false, false);
        dimensionStyleChanges.DimensionScale = 19.0;

        //Modify the new Dimension style with the changes.
        doc.DimStyles.Modify(dimensionStyleChanges, newDimensionStyleIndex, true);

        //Be care full about the Font Family name. For instance "Arial Black"
        //is on the font pull down but it is not in the list of font family names I looked at.
        //This may be a question that can be answered by the Forum.
        //Font[] f = Font.InstalledFonts();
        //foreach (Font i in f)
        //{
        //    if (i.FamilyName.Contains("Arial"))
        //    {
        //        RhinoApp.WriteLine("{0}, {1}",  i.FamilyName,  i.EnglishFamilyName);
        //    }
        //}

Thanks again Dale

Best;

Steve

ps: Facade: RhinoDoc.DimStyles -> Rhino.DocObjects.Tables.Add & Modify