The scripting interface is mainly a bunch of Tcl procedures and Tcl commands that a big part of The Mops uses internally.
Using Tcl, you could directly modify the code The Mops consists of. This is, however, not recommended for good reasons. So watch out for already existing procedures and commands when implementing your own!
Using procedures and commands not listed in this documentation is dangerous too. Implementation and interfaces of that commands may change in future versions.
The scripting interface may be used directly from the console
of The Mops. You can, of course, also write procedures in your own
Tcl script files, that may be loaded at any time into The Mops using
the console and the command "source"
.
Note, that most of the listed commands work in background, without changing anything to the Mops GUI and Mops view windows, for execution speed. If you want your changes to become visible you have to update the various parts of the GUI explicitly.
From scripts it may be necessary to check wether an error occured
during the execution of a command. All commands return
TCL_OK in any case so checking their return value avails to nothing,
but they set the global Tcl variable mops_error
to 1 if an
error occured. You need to set it to zero before and check it after the
operation in question to see whether the operation performed successfully.
To create new objects the "crtOb"
command can be used.
"crtOb type [args]"
"crtOb"
,
type must be one of "ncurve"
, "npatch"
, "light"
,
"level"
, "quadric"
, "custom"
, "box"
, "nsphere"
,
"ncircle"
, "revolve"
, "extrude"
, "sweep"
,
"cbsp"
, "concatnc"
, "instance"
, "trimrect"
.
Depending on the type, further arguments may (or have to) be given, other types expect objects to be selected:
"ncurve"
: NURB curves accept a single integer as length of
the new curve, the length defaults to 4."npatch"
: NURB patches accept two integers as width and
height of the new patch, width and height both default to 4."level"
: Levels must be given an additional argument
determining the type of the new level, this argument may be one of:
"union"
(union), "int"
(intersection), "diff"
(difference),
"prim"
(primitive), "tloop"
(trim loop) and
"level"
(simple level)."quadric"
: Quadrics must be given an additional
argument determining the type of the new quadric, this argument
may be one of: "sphere"
, "disk"
, "cone"
, "cylinder"
,
"torus"
, "hyperboloid"
and "paraboloid"
."custom"
: Custom objects must be given an additional
argument determining the type of the new custom object.
The available types depend on what custom objects are currently loaded;
"getCustomObjects"
tells you what objects are loaded."ncircle"
: NURB circles can be given an additional
argument, that determines the sweeping angle of the circular arc.
The default angle is 360."revolve"
creates a NURBPatch that results
from revolving the selected NURBCurve."extrude"
creates a NURBPatch that results
from extruding the selected NURBCurve."sweep"
creates a NURBPatch that results
from sweeping the first selected NURBCurve along the second.
Two additional arguments are expected, the number of sections
and a boolean (1 true, or 0 false) that determines, whether
the sections should be rotated to be perpendicular to the trajectory."concatnc"
creates a NURBCurve that results from
concatenating the two selected NURBCurves."instance"
creates an instance of the selected object."trimrect"
creates a rectangular NURBCurve to use
as trim curve for the NURBPatch that must be the parent object
of the current level."cbsp"
: Closed B-Splines accept a single argument,
that determines the number of points in the closed curve
(without the first three double control points that are necessary
to close a cubic B-Spline). "crtOb cbsp 4"
creates a closed B-Spline
with 4 points but the created NURBCurve has 7 control points!"crtOb ncurve 5"
, creates a NURBCurve of length 5"crtOb level level"
, creates a level of type level"crtOb ncircle 45"
, creates a NURB-circle-arc of 45 degrees
These functions are probably the most important ones, because a lot of the other commands operate on selected objects only.
setSelect:
"setSelect [index]"
selectNext:
"selectNext"
copOb - copy object:
"copOb"
cutOb - cut object:
"cutOb"
pasOb - paste object:
"pasOb"
delOb - delete object:
"delOb"
goDown:
"goDown index"
goUp:
"goUp"
goTop:
"goTop"
swapOb:
"swapOb"
reverseOrder:
"reverseOrder"
movOb - move objects:
"movOb dx dy dz"
rotOb - rotate objects:
"rotOb dx dy dz"
scalOb - scale objects:
"scalOb dx dy dz"
movSel - move selected points:
"movSel dx dy dz"
rotSel - rotate selected points:
"rotSel dx dy dz"
scalSel - scale selected points:
"scalSel dx dy dz"
delegateTran - delegate transformations:
"delegateTran"
delShader:
"delShader shadertype"
"surface"
, "displacement"
,
"light"
, "imager"
, "atmosphere"
, "exterior"
or "interior"
.scanAllShaders:
"scanAllShaders"
"Set new Shader"
buttons of the
shader property GUI's.
clampNC:
"clampNC"
elevateNC:
"elevateNC n"
getNCPoint:
"getNCPoint index varx vary varz varw"
setNCPoint:
"setNCPoint index x y z w"
getNPPoint:
"getNPPoint indexu indexv varx vary varz varw"
setNPPoint:
"setNPPoint indexu indexv x y z w"
insKn - insert knot:
"insKn u r"
U[p] <= u <= U[n]
, where
p is the degree (order-1) of the curve and n is the length of the curve.
The knot type of the curves will always be changed to custom but
the shape of the curves will not change!refineNC:
"refineNC [{u1 u2 un}]"
revertNC:
"revertNC"
rpNC - reparam NURB curve:
"rpNC mode"
"-rs"
- rescale the
knot vector to the range 0.0, 1.0 without changing the shape
of the curves.
splitNPatch:
"splitNPatch u|v"
buildNPatch:
"buildNPatch"
redrawAllViews:
"redrawAllViews"
updateMopsSelect:
"updateMopsSelect"
updateMopsPList:
"updateMopsPList"
lc - load custom:
"lc filename"
getCustomObjects:
"getCustomObjects varname"
All properties need to be copied from the Tcl context (the GUI)
to the C context (the scene storage) and vice versa while
The Mops is running. There is a pair of two commands for each property
that manages this. The commands are e.g. named "setSProp"
(set shader property) and "getSProp"
(get shader property),
set denotes transport from Tcl to C and get denotes transport
from C to Tcl.
They always need a selected object (C context), and a global arrray that holds the data of the property in the Tcl context. Each property uses it's own global array, an example for the aforementioned shader properties is e.g. surfaceShaderData.
Example:
You are welcome to apply a surface shader (try matte) to an object, keep object and SurfShader property selected, then type in the console:
"parray surfaceShaderData"
to see how this special array is organized.
See how the entry of Ka changes (in the property GUI!), while you type:
"set surfaceShaderData(Ka) 5"
To apply the changed Ka value back to the C context type:
"setSProp surface surfaceShaderData"
.
Check whether the property has really been updated by clicking on SurfShader in the properties listbox.
Always call the get property procedure before the set property procedure to initialize the array with correct values!
For more details (exact names of commands and arrays) please see the documentation of the properties in section Mops Objects and Properties.
There are two commands that help to apply arbitrary commands to a number of objects, forAll and forAllT.
forAll:
"forAll recursive command"
"uplevel #0 command"
forAllT:
"forAllT type recursive command"
Note, that the recursive form of forAll does not descent into the Scene object (selected or not) and mess with view objects; to do this you have to enter the Scene object explicitly.
As with forAll, special precautions are needed if command shall be able to access global arrays.
newScene:
"newScene"
replaceScene:
"replaceScene filename"
insertScene:
"insertScene filename"
saveScene:
"saveScene filename"
getType:
"getType varname"
getTmpFile:
"getTmpFile tmpdir varname"
hasChild:
"hasChild"
setON:
"setON [newname]"
saveUndo:
"saveUndo"
undo:
"undo"
convOb:
"convOb"
forceNot:
"forceNot"