Programatically change all existing dimensions styles

I have a particularly annoying client that sends us rhino 5 files using a custom dimension style which is enormous (in font terms) and rounds to closest 1mm. none of the rhino commands work to change the style or load another as the default, mm etc are all missing from the document, this requires us to load styles from another rhino file into the currently open one and redimension everything… major PITA…

Other than picking up a phone and whinging at the client… Whats would be the programtic way to find all dimensions in a document, and change them to read XX.XXmm with actual 0.001 accuracy vs the current 1mm accuracy.

found this, but it relies on the other dim styles already being available in the document… I need to to actually change the existing ones parameters.

(I’ll also send command to them , aptly named “FixYourShittyDimStyles.rhp”)

many thanks !

(edit: found this… Ill see how I go… )

ok. no. im lost, looks like it should work to me, but must be missing something, I purposefully put out bad dim styles like architectural, and my understanding is this should change them to accuracy 2 decimals and append mm after?

the two debug lines don’t trigger so its finding them, just not changing them?

also the new dim style “FixedDim” is not added to the document.

    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
        var FixedDim = new DimensionStyle();
        FixedDim.Name = "FixedDim";
        FixedDim.Suffix = "mm.";
        FixedDim.LengthResolution = 2;
        FixedDim.AngleResolution = 2;            
        FixedDim.CommitChanges();


        foreach (var rhino_object in doc.Objects.GetObjectList(ObjectType.Annotation))
        {
            var BadDimStyleObjects = rhino_object as AnnotationObjectBase;
            if (BadDimStyleObjects == null)
            {
                RhinoApp.WriteLine("Nothing found 1");//debug
                continue;
            }

            var annotation = BadDimStyleObjects.Geometry as AnnotationBase;
            if (annotation == null)
            {
                RhinoApp.WriteLine("Nothing found 2");//debug
                continue;
            }
            annotation.Index = FixedDim.Index;
            BadDimStyleObjects.CommitChanges();
            doc.Views.Redraw();
        }
        return Result.Success;
    }
}

}

Looks like all you need to do is to explicitly call add/replace on the doc objects (doc.objects.add / doc.objects.replace). Remember that you always have to use those to create or modify doc objects.

HTH,
Tom

close thanks, needs to be added as a “blank” then defined, wierd, but ok, it works.

int NewStyleIndex = doc.DimStyles.Add(“FixedDim”, false);
var FixedDim = doc.DimStyles[NewStyleIndex];

after that same code. https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/8/2/82f65ca8a2ad41d76ef2a0b53def9c0641fe9f16.mp4