Yep. In my mind, when I set format, unit, and precision of model’s LengthFormatter just shown as my code segment, the units part in model info panel of the opening .skp file will be amended as the above image. However, after I execute the code with .skp file, the units part in model info panel is not changed, and the model info panel always automatically popup…
My goal:
Format: Decimal
UnitType: cm
Precision:0.000000cm
Enable length snapping: Checked 0.000001cm
Display units format: Checked
Length formatters are used to generate formatted strings (optionally with units) from length, area, and volume values. Additionally length formatters can be used to translate a formatted length/area/volume string into a value. Accessors and setters are exposed for some of the key formatting properties, facilitating customization of the formater. In cases when users want the formatter to reflect the properties of a model, SUModelGetLengthFormatter should be used to more efficiently extract/copy the relevant properties from the model to the formatter.
In order to set units, which are part of the model’s options, you’ll need to access the model’s OptionsManager and OptionsProvider collections.
The keyname for the units options provider is: "UnitsOptions".
Within SketchUp, you can paste this Ruby snippet into the Ruby Console to see the current values assigned to the "UnitsOptions" provider’s key value pairs …
That sounds strange… are you saying the Model Info dialog automatically opens without user interaction? After opening a file you created with the C API?
Sorry to resurrect an old thread but I’m having an issue with setting units to meters.
I’ve copied the “WritingToAskpFile” project and have managed to get the UnitsOptions OptionsProvider and set the values of “LengthUnit”/“LengthFormat” to meters/decimal, after creating the model with SUModelCreate. I can open the resulting SKP file and the model units window appears to have the correct settings:
However, my vertices (which are positioned in meters) are still being placed as if they are specified in inches. I would have to multiply my positions by 1/0.0254 to get the model to be the correct size. How can I ensure my vertex positions are read as meters? I’ve tried saving the SKP file after setting these options but that didn’t work. Would opening the empty file after saving it, before adding the geometry, fix the issue? Or is something else required?
// Create an empty model
model = SU_INVALID;
SUModelCreate(&model);
// set the options of the model, we need decimal meters units
// get the Options Manager
SUOptionsManagerRef omr;
SUModelGetOptionsManager(model, &omr);
// get Options Provider
SUOptionsProviderRef opr;
SUOptionsManagerGetOptionsProviderByName(omr, "UnitsOptions", &opr);
// set LengthUnit to meters
SUTypedValueRef tvr;
SUSetInvalid(tvr);
SUTypedValueCreate(&tvr);
SUTypedValueSetInt32(tvr, 4);
SUOptionsProviderSetValue(opr, "LengthUnit", tvr);
SUTypedValueRelease(&tvr);
// set LengthFormat to decimal
SUSetInvalid(tvr);
SUTypedValueCreate(&tvr);
SUTypedValueSetInt32(tvr, 0);
SUOptionsProviderSetValue(opr, "LengthFormat", tvr);
SUTypedValueRelease(&tvr);
// then add geometry as in sample project
I’m afraid, You can’t!
The UnitsOptions only about the user interface, using code you must specify your lengths in inch, since Internally, all lengths in SketchUp are stored in inches.
I do not know so much about C API but in Ruby API you can read more e.g. here:
Thanks, I’ll change my code to use the enums. I’m writing a Sketchup format exporter for Unity so I know all my incoming geometry is in meters, it’s easier for me to just multiply everything by 1/0.0254 to get the representation in inches.