From: Peticel
Hi!
Is there any way to automate dimensions through scripting?
I have to export a few hundred sketches. So far, I made a script that exports each part individually, but I have to add basic length, height and width annotations.
Is there any way to access this through scripting? I could not find anything online.
Thank you in advance!
From: Larry Fahnoe (FAHNOE)
Hi Peticel,
Certainly, take a peek at the examples in MoI's commands directory (assuming you're using V4 or later):
DimAligned.js
DimAngle.js
DimHorizontal.js
DimLinear.js
DimPreset.js
DimRadius.js
DimVertical.js
--Larry
From: Michael Gibson
Hi Peticel, here's an example:
code:
var factory = moi.command.createFactory( 'dimhorizontal' );
var frame = moi.vectorMath.createTopFrame();
frame.origin = moi.vectorMath.createPoint(10,0,0);
factory.setInput( 0, frame ); /* Input 0 - coordinate frame for dimension plane, frame origin at start point. */
factory.setInput( 1, moi.vectorMath.createPoint(20,0,0) ); /* Input 1 - end point */
factory.setInput( 2, moi.vectorMath.createPoint(15,10,0) ); /* Input 2 - text through point */
factory.setInput( 3, 0 ); /* Input 3 - index of Dimension properties preset to use */
factory.commit();
This will generate a dimension:
- Michael
Image Attachments:
dim.png
From: Peticel
Thank you both for the fast replies! I managed to get it working.
@Michael - is there any place where I can find all the scripting documentation?
The best I could find is
https://moi3d.com/wiki/Scripting which seems to be multiple collections of people's findings.
Thank you again!
From: Michael Gibson
Hi Peticel, yes
https://moi3d.com/wiki/Scripting is where the current info is collected.
It takes a great deal of work to make documentation and support scripting, it isn't really a primary focus area for the product but I can help out with examples or answering questions here on the forum.
- Michael
From: Peticel
Got it!
I'm trying to stylize the text a bit as it's currently too small.
Can all the properties be accessed through scripting?
Are they controlled through << factory.setInput( 3, 0 ); /* Input 3 - index of Dimension properties preset to use */>> ?
I would like to increase the size and make the text screen aligned. Also including the unit would be nice.
Thank you in advance!
From: Michael Gibson
Hi Peticel
> Are they controlled through << factory.setInput( 3, 0 ); /* Input 3 - index of Dimension properties preset to use *>> ?
They can be controlled through that or set directly on the object.
To do it by preset, go to Options dialog > "Dimensions" and set up a preset that has the properties how you want them, then pass the index of that preset as the 2nd parameter to setInput, like this: factory.setInput( 3, preset_index );
Accessing the dimension object and setting properties on it directly can be done like this:
code:
var factory = moi.command.createFactory( 'dimhorizontal' );
var frame = moi.vectorMath.createTopFrame();
frame.origin = moi.vectorMath.createPoint(10,0,0);
factory.setInput( 0, frame ); /* Input 0 - coordinate frame for dimension plane, frame origin at start point. */
factory.setInput( 1, moi.vectorMath.createPoint(20,0,0) ); /* Input 1 - end point */
factory.setInput( 2, moi.vectorMath.createPoint(15,10,0) ); /* Input 2 - text through point */
factory.setInput( 3, 0 ); /* Input 3 - index of Dimension properties preset to use */
factory.update();
var dim = factory.getCreatedObjects().item(0);
dim.text = '<> units';
factory.commit();
Probably it would be easiest to set up a preset for the size and alignment properties since there's a UI for those under Options > Dimensions but you can't control the text to include units in a preset yet so for that part set the text directly on the dimension object as above.
- Michael
From: Peticel
Hi Michael!
Thank you for the info. I'm still having some issues.
To do it by preset, go to Options dialog > "Dimensions" and set up a preset that has the properties how you want them, then pass the index of that preset as the 2nd parameter to setInput, like this: factory.setInput( 3, preset_index );
This works perfectly but the preset does not save. Every time I re-open MoI, I only have the default preset and I can't find any way to save it. Maybe I could change the default preset? where is it stored?
Probably it would be easiest to set up a preset for the size and alignment properties since there's a UI for those under Options > Dimensions but you can't control the text to include units in a preset yet so for that part set the text directly on the dimension object as above. - Thanks, it worked.
From: Michael Gibson
Hi Peticel, the default dimension preset is stored in moi.ini and that one will reload just when you start up MOI. The other dimension presets are saved when you save to a .3dm file and will be loaded when you open that .3dm file. They won't be loaded just on program startup except if you set up a template file under Options > General > "Template file".
When you set a template file that will load stuff stored in .3dm files like the dimension presets and styles list on program startup or File > New.
- Michael
From: Peticel
Thank you so much for your help! I got everything working!
Could you please also include how to change "Decimal display" and "Show trailing zeros"?
I would need your help with one last thing, if you have the time.
On a few panels, I seem to have some broken / invisible geometry. Is there any way to identify it?

In the image, the panel itself is 1160 x 2320, but it gets measured as 1216x2320. The geometry is Solid, I can't find any broken edges/faces/curves floating around. I even tried to un-join, reselect only the faces and re-join. I always get the same result. The panel was made with a boolean operation, but the cutters did not exceed the size of the panel. Any suggestions?
Image Attachments:
Screenshot 2025-01-31 110033.png
From: bemfarmer
Can you post .3dm?
What is result of bounding box? Shrink?
Snap settings?
-B
From: Peticel
I'm not sure where the problem is coming from.
The model was created face up, as part of a larger array. If I run the script in that position, everything is fine.
When I move or rotate the object so that the 'face' faces the front view, one of the sizes breaks.
I have attached the file and the script.
Attachments:
AUTO_DIM.js
TEST_PATTERN.3dm
From: bemfarmer
A mere guess, without computer access:
3d view acts like top view?
Awaiting Michael's expertise:-)
-B
From: WN
Hi Peticel.
Image Attachments:
dim.png
From: Michael Gibson
Hi Peticel,
For this part:
> Could you please also include how to change "Decimal display" and "Show trailing zeros"?
These can be set in the preset UI under "Formatting" :
If you want to set it on an object using script code:
dim.distanceDisplay = 'Decimal';
or
dim.distanceDisplay = 'Feet & Inches';
dim.numDecimalPlaces = 3;
dim.showTrailingZeros = true;
- Michael
Image Attachments:
PeticelFormatting.png
From: Michael Gibson
Hi Peticel, for the size not being what you expected, on line #18 of your script that currently has this:
code:
var bbox = obj.getBoundingBox();
Change it to this:
code:
var bbox = obj.getBoundingBox( true /* Calculate tight bounding box */ );
When you call obj.getBoundingBox() you'll get bounds that are quickly calculated by the bounding box of all surface control points.
There are just a couple of surfaces in your object that have have been trimmed by the boolean where the underlying surface's control points are a little bit larger than the active trim boundary:
If you want a "tight" bounding box that uses the trimming boundaries you need to pass in a function argument of true to the .getBoundingBox() function. There is quite a bit more calculation involved for getting the tight bounding box.
- Michael
Image Attachments:
PeticelBounds.png
From: Peticel
Thanks a lot for the support! I got everything working.
There are just a couple of surfaces in your object that have have been trimmed by the boolean where the underlying surface's control points are a little bit larger than the active trim boundary - how can I fix this? I tried unjoining all surfaces and running ShrinkTrimmedSrf but nothing happens. Thanks!
I'm having one more issue with the export. Some parts are 12mm thick (same issue with 24mm) and the back side lines can be seen through the geometry (they are not hidden lines). Is the any .ini tweak that can fix this?
Front
Back
Front orthographic
The selected lines can be seen through the model
PDF export Back view

Image Attachments:
1.png
2.png
3.png
4.png
PDF.png
From: Michael Gibson
Hi Peticel,
> > There are just a couple of surfaces in your object that have have been trimmed by the
> > boolean where the underlying surface's control points are a little bit larger than the active trim boundary -
> how can I fix this? I tried unjoining all surfaces and running ShrinkTrimmedSrf but nothing happens. Thanks!
Well it's not an error, so it's not something that you would normally need to do anything about.
Why are you concerned about it?
In order to avoid it you would need to construct surfaces in a very restricted way so that the surface's control point layout is aligned to the cut.
But doing that would be difficult and not gain anything, it's just a normal part of how CAD models work that you can have a underlying surface that is larger than the trim boundary.
Basically you have a surface like this:
If you then trim off an area with a trim curve not aligned to the surface's UV grid directions like this:
That will result in a trim curve like this where the surface can't be shrunken down any further in the surface's own UV direction:
It's just a normal thing to have this.
To fix it you would have to make all untrimmed surfaces without any arbitrary trim boundaries. That would be a big limit and make model construction a lot more difficult for no gain.
Like for this case shown above you would need to model it like this so that the surface's control point structure goes along the trim boundary:
But don't do that, the lighter surface that doesn't shrink down completely is better quality geometery.
> I'm having one more issue with the export. Some parts are 12mm thick (same issue with 24mm)
> and the back side lines can be seen through the geometry (they are not hidden lines). Is the
> any .ini tweak that can fix this?
That's a display glitch called "bleed through", you can find some more info here:
http://moi3d.com/forum/index.php?webtag=MOI&msg=4987.2
When it happens in the viewport it's just something to ignore. But it's a lot less likely to happen in PDF export, can you post or e-mail me (
moi@moi3d.com) the 3dm model where you are getting it in the generated PDF?
Some things that I would check if I had the file to examine - are the objects solids? Are there any additional construction curves still hanging around? What is the "Canvas megapixel resolution" value set to? Try increasing that value to 50 or 60 if it's lower than that.
- Michael
Image Attachments:
PeticelShrink1.png
PeticelShrink2.png
PeticelShrink3.png
PeticelShrink4.png
From: Peticel
Hi Michael,
As always, thank you for the detailed explanation.
>>Why are you concerned about it? - I thought it was an issue since out of 48 models, only 3 had this problem. I also made the mistake of thinking that the BoundingBox command that I use in the app is the same as the one in the scripting doc. I was confused because if I selected the model in the scene and ran BoundingBox, I got good results (a bounding box perfectly encasing my model with the right values), but through the script, I got different values. Adding "true" to the command inside the script fixed that. So all good. (full disclaimer, I have almost no experience scripting but with what you provided, chatGPT was able to make a fully working script)
I will send you the models per mail.
>>Some things that I would check if I had the file to examine - are the objects solids? - yes
Are there any additional construction curves still hanging around? - no
What is the "Canvas megapixel resolution" value set to? - 50
Try increasing that value to 50 or 60 if it's lower than that. - same result at 10, 50 and 100