Scripting projects by David C. Morrill

You can put the following scripts as a keyboard shortcuts. To define them, open Option dialog window, go to Shortcut keys section, push the "Add" button there which will insert a new blank shortcut key; click in the "Key" column and add the key you want to use to activate it, like "H" for example; then click in the "Command" column and paste in the script line _or_ open the moi.ini file (C:\Documents and Settings\[your user name]\Application Data\Moi\moi.ini) and edit directly the [Shortcut Keys] section. Just assign some key (e.g. K, Space) or key combinations (e.g. Ctrl+U, Alt+E) or function key (e.g. F5). The code for shortcut should be one long single line. Simple shortcuts can be found in moi_hotkey.txt file.

Note: for keyboard shortcus that have script code in them, you can put a comment in the code with a note in it. You put in a text surrounded by /* */ , just after the script: part – see MoI forum for example.

Zoom & Pan – the way this version works is it will do it on the viewport the mouse is currently over. If the mouse is not currently over a viewport, it will use the one that last had a click in it, or if there is just one single viewport maximized it will use that one.

Ctrl+LeftArrow

script:moi.ui.getActiveViewport().Pan( -1, 0 );

Ctrl+RightArrow

script:moi.ui.getActiveViewport().Pan( 1, 0 );

Ctrl+UpArrow

script:moi.ui.getActiveViewport().Pan( 0, 1 );

Ctrl+DownArrow

script:moi.ui.getActiveViewport().Pan( 0, -1 );

PageUp

script:moi.ui.getActiveViewport().Zoom( 0.9 );

PageDown

script:moi.ui.getActiveViewport().Zoom( 1.1 );

ZoomArea – trigger the area zoom on the viewport that the mouse is over.

Set View Angle – sets specific view angles by a shortcut key;Up/down angle controls the vertical angle, 0 is at the top looking straight down.Left/right angle controls horizontal angle, 0 is looking straight forward, 90 is looking from the right, etc.Tilt controls twisting to the left or right along the current view direction.

Set camera by eye and look at points – That should set the 3D view direction given an eye point and a "look at" point. Substitute your camera coordinates for the eye which above is set at 10,10,10 and also substitute your look-at coordinates which are set to 0,0,0 above.

Set top viewport zoom to 1 pixel = 1 unit – the pixel dimensions of the viewport are not currently accessible to scripts, so you'll need to find some other way of getting that info – maybe try a screen capture utility and see what size image it grabs from a viewport window or if you have Visual Studio installed use Spy++ from there to find the pixel width and height of the viewport's window.Then plug in the smaller of the width and height into this script, putting that number in place of where it says 482 currently.

Set that script up on a shortcut key and then when you trigger it, it should zoom the top viewport to be 1 pixel = 1 unit.Note that if you do anything that changes the viewport size like sizing the main window or switching from split view to a maximized top view, that it will no longer be 1 pixel = 1 unit after that.

SelectStyleV2 – The main method for selecting by style is to use the browser by clicking on the text part of the style name. But you can do it by using this script as well – it will expand the selection to include all objects of the same style as one that is currently selected. To use that, first select an object from the style you want to target, then hit the key to trigger that script and all the other objects of that same style will be added to the selection.

SelectTinyV2 – it will select all objects that are smaller than 1 unit in size (by bounding box diagonal). To adjust the size, edit the part that says size = 1.0 and change the 1.0 to whatever number that you want.

SelectLongestCurveV2 – script that just selects the longest curve; it will look through all curves that are not hidden or locked, so if you have some curves that you don't want to have considered lock or hide those before running the script.

SelectNakedEdgesV2 – it deselects all objects and highlight all edges that are not joined so that can help to show you what parts of an object are the ones stopping it from being a closed solid (watertight object).

SelectVisibleV2 – when you push the key that you assigned the shortcut to, it will select the visible objects. These are all the objects that have any part of them visibly displayed on any viewport that is showing – these are all objects that would have been accessible by a click type selection. See forum.

Shift+V

script:moi.geometryDatabase.selectVisible();

SelectParents – if you have an object selected, it switches selection to all the parents that were input into the making of that object. So for example if you select a lofted surface, after you run that script the original curves that went into the loft will be selected.

SelectChildren – if you have an object selected, it switches selection to the children that were made as a result of using of that object. So for example if you select one of the original curve of lofted surface, after you run this script the lofted surface, which was created using that curve, will be selected.

SelectLastCommandCreated – selects all the objects that were generated by the last command. So for instance after finishing Array you can hit the shortcut key with this script on it, and all the results of the array will be selected.

If you would always like to have the created objects be the exclusively selected objects (with everything else deselected) instead of being added to the current selection, then use this script instead:

SelectUnnamedObjectsV2 – when you hit that key you should end up with only all the unnamed objects selected. One note – this version will not select any hidden or locked objects, those will remain hidden or locked.

DeselectRandomObjectsV2 – Select objects first then trigger shortcut. You can change the value for the percent = 30 part in the script to adjust keeping more or fewer objects selected when it is triggered. It won't give you exactly 30% of objects to remain selected, because it goes just object by object and gives each object by itself a 30% chance of remaining selected. But it should give a result somewhere close to 30% of the objects remaining selected.

SwitchSelectionFromFaceToEdges – this script switches selection from a selected face to its edges.So for example, after you have your faces selected (either from their intiail selection or by using the Scene browser Style section to select them), trigger that script and then the edges that belong to those faces will get selected and you can then apply the style to them.

IsolateV2 – to isolate the current selection (hide everything else other than what is selected), right-click on Edit/Hide or use this script. This will remember the state of objects right before the isolate, and when you right-click on the button a second time the previous state will be restored.

I

script: /* Isolate selection */ moi.geometryDatabase.isolate();

HideWithMemoryV2 – this shortcut key works like a kind of "hide with memory" (Invert selection + Isolate method together in just one keyboard shortcut, actually). Select an object and use the shortcut key to hide it, and then later on trigger the shortcut key a second time to restore the object to visible again.

SetObjectNameV2 – it sets object name as style name (each object will get assigned a name of its associated style name, plus a unique increasing number, like BlueLayer_2, BlueLayer_3, etc… The number is appended to make the names unique to avoid combination of mesh objects with identical names). See forum

MatchObjectNameV2 – the script works purely off of selection – to use it you must make a combined selection that includes at least one of the objects that already has the name assigned to it, along with other unnamed objects that you want to have assigned to that same name.When you have a selection set up like that, then push the shortcut key and it will assign the unnamed objects to have that same name.You can use the Scene browser to help you make the selection – right click on the object name in the scene browser to make it the "isolated selection" – everything else will get deselected and only those named objects will be selected. Then select the unnamed objects and then push the shortcut key.

SeparateObjectNameV2 – it will add numbers to the names of any duplicate objects no matter how you duplicated the objects, whether it was by array, copy/paste, importing another file, transform/copy, rotate with copy option, Ctrl+drag, whatever…For example if you have 5 objects all named "Blah", after you run the script you will instead have Blah_1, Blah_2, Blah_3, Blah_4, Blah_5

SortStylesAlphabeticallyV2 – then when you hit shortcut key, the styles should get sorted alphabetically.Oh also you probably shouldn't run this script while while the style editor dialog is also open, because it won't know how to deal with the styles changing out from underneath it like this script will do. So trigger the script when you are not in that dialog.Also the script is not tremendously efficient, if you have something like more than 100 styles it may take a few seconds or something for it to complete.

OpenSnapMenu – you can set up the following on a keyboard shortcut to make that snap menu open up with a keystroke instead of going to the button to launch it <or> which shows it in the center of the screen:

UntrimSelectedSurface – to use it, select some individual surfaces (that are not joined to any other surfaces), and hit that keyboard shortcut. It's the equivalent of selecting all the edges of those surfaces and doing delete.

CurveLengthV2 – It is possible to measure a length of curve in v2 by setting up a keyboard shortcut with this as the command. Then when you push that shortcut key it will calculate the length of the selected curves and copy it to the clipboard as text, and you can paste it into a text editor to see it.

CurveLengthBeingDrawnV2 – Here's a script Michael put together that you can run while in any of the curve,arc or line commands that will show the length in realtime.Start any of the commands, like arc or freeform or line, and pick your first point. Then hit the script and a label displaying the length will appear in the active command window.

LockedToEditControlPoints – this script will show control points for selected objects and then turn on selection lock for every object that does not have points turned on. When in this mode, other objects won't be selectable, so you can select and drag different points while in this mode without other objects getting in the way. Press Esc key twice to exit this mode (actually, it works like if nothing is selected when you push Escape, it will look to see if there is any locked selection and if there is it will clear the locked selection).

DuplicateBorders – this script macro might be useful for some data transfer stuff – this will duplicate every edge of every surface or solid in the scene as a regular independent curve object. Those curve objects can then be processed into DXF using 3dmCurves2DXF utility.

SnapGrid – it does allow you to set up a quick 10.0 or 100.0 unit snap by using one keypress which you can turn on or off in the middle of drawing things.

Typing "G" (not holding it down, just push and release it) will enable a grid snap of 10.0 units. Typing "H" will enable a grid snap of 100.0 units. You can type "G" or "H" a second time to turn the snapping off.

This script allow you to hide the UI so only the viewports are visible.

First, create a new scripts directory underneath the main MoI program directory (on an equal level as \commands and \ui).

Unzip the file FullScreen.zip (for V1 use the old one – FullScreen-V1.zip) and put it in there. So the path for this file should be something like: C:\Program Files\MoI beta Dec-1-2006\scripts\FullScreen.js

This script allow checking the clock, although MoI is covering up the taskbar. You know that the little arrow button next to the Help button controls whether MoI displays as full screen or not… or not? hehe…

Unzip the file Clock.zip into the \ui folder. (The MainWindowLayout.xml file must be overwritten – actually, there is only one extra line of text added in this file (<UIPanel dock="bottom" src="moi://ui/CommandBarClock.htm" />) – so needn't worry about it.

This command draws a circle of a particular radius, placing the circle just with a single click for its center point. The circle will align itself to surfaces if the point you picked is on a surface.

To install, unzip the QuickCircle.zip to get 2 files (one .htm and one .js file) – copy these to the \commands subfolder inside of MoI's main installation folder, and then go to Options / Shortcut keys and set up a new shortcut key with QuickCircle as the command. You can then run the new command by pushing that shortcut key.

I left the default at 1.0, if you want to change the default to 0.1, you can edit the default="1.0" in the QuickCircle.htm file. But you can change the radius in the edit box.

Also after you pick a point, this command will keep running so that you can click down several points to place additional circles while inside the same command.

Nudge script lets you move selected objects, points or control points by small increments.

Unzip the file Nudge.zip (or for V2 CPlaneNudge.zip) into the \commands subfolder under your MoI main program files folder. Then go to Options / Shortcut keys, and add some new entries. For the command, put a space after Nudge, so it's 2 words like "Nudge Left". The Nudge command will look at those parameters when it runs.

LeftArrow

Nudge Left

RightArrow

Nudge Right

UpArrow

Nudge Up

DownArrow

Nudge Down

It's also possible to set, for example, PageUp and PageDown for 'z' nudging, like:

PageUp

Nudge zup

PageDown

Nudge zdown

and you can also add some more for doing a larger or smaller step, like:

Ctrl+LeftArrow

Nudge Left Large

Alt+LeftArrow

Nudge Left Small

There is Paul's variation of nudge script – NudgeViewAxis.zip – this one uses imaginary viewport XY axis instead of world axis to nudge the objects in a given direction. A syntax for command part of shortcut is the same as above except it doesn't make sense to define 'z' nudging.

This script allow you to create the cross-section curves through profile curves similar to Rhino's CSec.

Unzip the file CSec.zip into the \commands subfolder under your MoI main program files folder. That installs the new CSec command, but you need a way to trigger it – you can do this by adding a new keyboard shortcut under Options, for example:

Add a keyboard shortcut, for example:

Alt+C

CSec

To use the CSec command, you pick your CSec curves one by one in order from first to last in a circular order, and then push Alt+C, to do your CSec-ing right inside of MoI. See for more info.

Unzip the file ScaleArray.zip into the \commands folder, then add a keyboard shortcut for ScaleArray; go to your moi.ini and add a keyboard shortcut, for example:

Add a keyboard shortcut, for example:

Alt+S

ScaleArray

To use the ScaleArray command, you use any array command, but make sure to include a single point object with the objects you are arraying. The point object will become the center of the scale for each array instance.

After you do an array, select the arrayed objects (and only the arrayed objects, so for example if you do an array curve make sure the path curve is not selected), then do Alt+S (or whatever your shortcut key is) and follow a prompt.

Now pushing Alt+P will launch the ConstraintPolyline command. After calling this new command you can choose from three constraint mode for drawing a polyline – distance constraint, angle constraint or both of them. If you don't want to use one of them, you just type 0 (zero) or delete a value.

Now pushing Alt+P will launch the CopyToPoints command. There is only one difference in comparison with regular Copy command. You must select a target points instead of picking the ones. If you check the "Delete points" option, the target points will be deleted. For selecting a target points, you can set a keyboard shortcut to select all points in the scene:

Unzip the file ImportPointFile.zip into the \commands folder (e.g. C:\Program Files\MoI beta Apr-26-2007\commands) and add a keyboard shortcut for this new command.

Some issues in using script above: The particular method that script uses to show the "get filename to open" dialog is apparently not available on Windows Vista or higher – use ImportPointFile_Update2.zip second updated version instead (you can use it along Win XP as well). It won't work with MoI v1, though.

Note: You can download updated version of the script which works on the OSX version.

This script allow for saving a coordinates of point objects to the plain text file in format X,Y,Z.

To save a point, run a command and select the point objects. Choose the delimiter character and number of significant digits of precision in the command prompt options and push done button. In the dialog box, type a name for the file including some extension like .txt, .csv, .xyz; e.g. outline.txt

To install it, unzip the file SavePointFile.zip into the \commands folder (e.g. C:\Program Files\MoI beta Apr-26-2007\commands) and add a keyboard shortcut for this new command.

Note: You can download updated version of the script which works on the OSX version.

This custom command helps you select all visible objects of a given type. The command doesn't deselect the selected objects, it means the command adds to the current selection only.

You can select the object which will define the object type to select before the command starts. In this case, when one and only one object is selected, command will run without any user intervention and in accordance with the state of a subtype checkbox the objects of the given type will become selected. The object you can pre-select:

point

curve (with subtype button checked either open or closed curves will be selected )

surface (with subtype button checked either open or closed surfaces will be selected )

edge

face

Without pre-selected object the command prompt will stay accessible in order to enable user to check/uncheck the subtype button and pick the object. If you pick the curve or point, command will do its work and finishes. If you pick a surface, the "Done" button appears – then you will be able to finish command by pushing it (or clicking the right mouse button in the viewport) immediately to select all closed or open surfaces _or_ select edge or face in drill-in mode first to select all edges or faces.

If there is more than one object selected before command starts, it will work as described above except the pre-selected objects become deselected temporarily.

It sounds somewhat complicated, but I believe it's quite intuitive.

Unzip the file SelectByType.zip into the \commands subfolder under your MoI main program files folder. Then go to Options / Shortcut keys, and add some new entries, like:

This custom command creates an involute spur gear profile. It is as simple as possible – just for fun. You can specify the gear by number of teeth and its module or diametral pitch (it depends on current unit settings). Then you can use that curve to make a meshing gear.

Some vague definitions:

Module: amount of pitch diameter per tooth, in millimeters

Diametral Pitch: number of teeth per inch of pitch diameter

Pitch Diameter: Diameter of the circle you can see after finishing the command

Equation: Diametral Pitch * Module = 25.4

Unzip the file SpurGearProfile.zip into the \commands subfolder under your MoI main program files folder. Then go to Options / Shortcut keys, and add some new entries, like:

! I have decided to rename this RebuildCurve custom command to avoid confusion with regular Rebuild command !

This custom command allow you to reconstruct a curve/curves using sample points evenly distributed along the original curve. You can choose from three different mode which alter the way how a new curve is built – this is possible only if there is no selected curve when triggering command, though.

Unzip the file ReconstructCurve.zip into the \commands subfolder under your MoI main program files folder. Then go to Options / Shortcut keys, and add some new entries, like:

This command closes curves by adding line segment between curve's start and end point.

To install the new command, unzip the attached CloseCurve.zip file to get 2 files: CloseCurve.js and CloseCurve.htm . Copy these files to the \commands subfolder inside of MoI's main installation folder.

Then inside of MoI either assign a shortcut key to have a command of CloseCurve, or you can also type CloseCurve to launch it by using the mini-command line entry.

This is a command for importing all the IGES files inside of a folder that you pick. (Note that it can be modified easily to do importing all the AI or 3DM files.)

To install the new command, unzip the attached ImportFolder.zip file, then copy ImportFolder.js into the \commands sub-folder inside of MoI's main installation folder.

This will give you a new command named "ImportFolder".

To trigger the command you have to set up a keyboard shortcut – go to Options / Shortcut keys, and add a new entry. Put whatever you like for the Key, for example Ctrl+I , then for the Command put in ImportFolder.

The first step is that you can pass the name of a script file as a command-line parameter to MoI.exe. If there are any spaces in the script file name, the entire file name should be enclosed in double quotes, like:

MoI.exe "c:\path with spaces\script.js"

The script will execute immediately before the main window is displayed, so if your script decides to exit MoI the actual MoI UI will never show up on the screen.

Michael made an example to get you started. This BatchConvert.zip script shows how to convert IGES to OBJ files.

BatchConvert.js is the file that you would overwrite with your own script, before launching MoI.exe. You just add in one line for a call to Convert() for each IGES (extension .igs or .iges) file you want to convert to an OBJ.

TheConvert() function is defined in the Convert.js library file which is included into BatchConvert.js.

Convert() handles the basic calls into MoI to open and save the files. There are some comments in there about how to control the meshing parameters, this is done by an option string you can pass to the saveAs() function. If you pass NoUI=true, the mesh dialog will not be displayed.

This command makes it quicker to create hollow pipes around many curves in one shot. (Note that there is the "auto place" mode for sweeping which makes it easy to create a pipe with different shape of profile even without using this custom command. Also, Michael is going to improve regular Sweep command to handle additional stuff for V2!)

However, this will only work properly on a smooth curve, you will have to wait until MoI version 2.0 before this will handle sharp corners properly.

To install this new command, download the Pipe.zip file. Copy the 2 included files (Pipe.htm, Pipe.js – updated version for V3 which should work in V2 as well) to the \commands subfolder under MoI's main installation folder in C:\Program Files.

That will install the new command, but you also need to add a new shortcut key to trigger it. To do that, go to Options / Shortcut keys, and push the "Add" button, and put whatever you wish for the key (for example P), and then for the command put in Pipe.

Now when you push that key the new Pipe command will be launched.

Select your rail curves first, then run the command. Then you will have the options for Outer and Inner radius which you can set in the command options area in the upper right corner of the MoI window.

You can also download a modified version (Pipe2.zip) which allows you to specify different outer and inner radius values which get applied to the end of the sweep. The command for this one is Pipe2, you can rename the files if you want it to replace the previous Pipe command instead.

Note this version doesn't automatically update the pipes when you enter values in, you need to push the Update button to see your changes take effect for this version. This is so you can more easily input multiple values, because Pipe does not have the same kind of interruptability that regular commands have.

Michael was kind enough to build a tool for MoI jewelry designers to draw specific ring sizes and Jesse filled in the measurements for each country system, referencing a number of ring size charts he found online.

To install, unzip this file RingCircle.zip, placing both RingCircle files (html and jscript) in the "commands" folder of MoI – C:\Program Files\MoI 1.0\commands.

The RingCircle tool won't show up in MoI unless you turn it on with a keyboard shortcut. To make the shortcut, click the "Options" icon at the bottom right area of MoI (it looks like a yellow gear) and under "Shortcut Keys", add a key and a command. You can choose whatever key you prefer and typed in the command RingCircle.

This is a polygon wireframe to 3dm converter. It enables bringing polygon data (OBJ) into MoI to use as construction guides. Download the file Obj23dmWireframe.zip. Unzip it to some folder, and then you can run the Obj23dmWireframe.exe program. It will prompt you for the name of an OBJ file, and after that the name of a 3DM file. It will read all the polygon data from the OBJ file and convert the edges of polygons into line segments, and save those line segments to the 3DM file that you specified. You can then load that 3DM file into MoI and use those line segments to snap on to.

Download the files 3dmCurves2DXF.zip, unzip this to some folder, then run the 3dmCurves2DXF.exe program. It will ask you for the name of an input .3dm file, and then the name of an output .dxf file. It will read through the input .3dm file and convert any curve objects it finds to Spline entities in the DXF file.

If you run the RelabelOBJ.exe (see MoI forum) program, it will ask you for a file name, and then it will go through and replace all the object names to be based off the file's own name instead of just "object".

So for instance if you have a file named my_file.obj, if you run the RelabelOBJ.exe program on it, all the object names will be turned from just "object1", "object2", etc... into "my_file1", "my_file2", etc...

Well, you could do something like search & replace in your favorite text editor to change the names as well.

Anthony wrote a custom blender import script that handles true normals and real-time UV coords. It also adds some pretty cool vertex colors that simulates the global-illumination from a hemisphere. The light value is calculated from the true vertex normal not the average of the face normals that surround a vertex.

The animated GIF on this MoI forum page shows the difference between Anthony's importer and the standard one that ignores MoI's true normals.

3dm2sculpt converter

You can get a 3dm2sculpt converter from here – that will enable converting from a .3dm file that MoI saves into a .tga sculpt map texture file. See the page in the "How to use ?" section for some instructions: http://wiki.secondlife.com/wiki/3dm2sculpt

iges2step converter Note that V2 is able to handle STEP I/O directly!

MoI can import/export IGES files … to translate STEP file to IGES or vice versa you can use iges2step converter/viewer; see http://iges2step.narod.ru/. After finishing an installation process you must reboot your computer before first launching this converter!