Adding a New Dimension Style

Unable to add new dimension style to document (File3dm). I create a new instance of the Rhino.DocObjects.DimensionStyle() class and set some properties there. However, when I later save the Document, there is no new style in it. Of all my attempts to add a new style, only one has worked: when I copy an existing style via dimStyle.Duplicate() and change its name. But I need to create a new style without copying the existing ones.

using (var file = File3dm.Read("D:\\Template.3dm"))
{
    var dimStyle = new Rhino.DocObjects.DimensionStyle()
        {
            Name = "NewStyle",
            Id = Guid.NewGuid(),
            DimensionScale = 25,
            LengthResolution = 0,
            ArrowLength = 2.5,
            TextGap = 1,
            TextHeight = 2.5,
            FixedExtensionOn = true,
            FixedExtensionLength = 5
        };

        file.AllDimStyles.Add(dimStyle);

        file.Write("D:\\NewFile.3dm", 7);
}

This works inside a gh c# script:

    Rhino.DocObjects.DimensionStyle dimStyle = new Rhino.DocObjects.DimensionStyle(){
        Name = "NewStyle",
        Id = Guid.NewGuid(),
        DimensionScale = 25,
        LengthResolution = 0,
        ArrowLength = 2.5,
        TextGap = 1,
        TextHeight = 2.5,
        FixedExtensionOn = true,
        FixedExtensionLength = 5
        };
    this.RhinoDocument.DimStyles.Add(dimStyle, false);

this adds a new style into the current RhinoDoc.

Are you trying to add your style to unopened documents?

2 Likes

That’s right. The script I provided above is the script for the Grasshopper component. I send geometry to it and the Component should write this geometry to a new file (or an already existing template file on disk). As far as I know this can only be done with Rhino.FileIO.File3dm