3DCoatScripting  4.8.31β
You can manage 3DСoat features with help of scripting
🌀 Working with Voxels

Layers creation

3DCoat allows to create multiple layers in the scene. And each layer can contain another layers.

Here's the code:

void main() {
// prepare scene
Vox v;
// build vox-layers tree
.appendToParent( "Head" )
.appendToParent( "Body" )
.append( "Neck" )
.appendToParent( "Left arm" )
.appendToParent( "Right arm" )
.appendToParent( "Heart" )
.appendToParent( "Left leg" )
.appendToParent( "Right leg" )
// back to "Head" layer, switch it
// to "Surface mode" and attach new one
.to( "Head" ).toSurface()
.append( "Eye" )
.appendToParent( "Lamps" )
// Noticed how last one were added?
// Correct: `S`, not `V`.
// delete first (empty) layer from scene

You'll get the tree:


Check it!)

Do you see the groups of methods? append(), appendToParent(), appendToRoot(), forEach(), forRootEach(), ... - self-explanatory titles: "parent", "root", "for each". Simply compare this code with result image, and you'll get everything :)

Are you familiar with JQuery? Then you'll easily understand how 3DCoat works with trees.

Consider that class Vox interacts with 3DCoat's UI, that's why Vox-methods select layers before they do anything with them.

Layers traversal

Lets add some to the code above.

There are two ways. First:

// access to a Vox tree
Vox v;
void main() {
// build a tree
// look `CreateVoxelTree.as`
// ...
// walk through all layers and for each layer call invert() function
// look below `void invert()`
v.forRootEach( "invert" );
// move to "Body" layer and call `invert()` for it and its children
v.to( "Body" ).call( "invert" ).forEach( "invert" );
// function for `forEach()`, look above
void invert() {
v.isSurface() ? v.toVoxel() : v.toSurface();
// pause, to see movement in the UI
Wait( 50 );


// access to voxTree
Vox v;
void main() {
// build a voxel layers tree
// look `CreateVoxelTree.as`
// ...
// access by index for all children of "Head" layer
v.to( "Body" ).call( "invert" );
for ( int i = 0; i < v.count(); ++i ) {
v.at( i ).call( "invert" ).parent();
Wait( 100 );
// look above for function `forEach()`
void invert() {
v.isSurface() ? v.toVoxel() : v.toSurface();

Which way to choose? You decide.


If you prefer a functional programming, take a look at this list of available functions:

// Returns true if current volume is in surface mode.
DEPRECATED bool IsSurface();
// Check if volume cached.
DEPRECATED bool IsInCache();
// Move current volume to cache.
DEPRECATED void ToCache();
// Restore current volume from cache.
DEPRECATED void FromCache();
// Get current volume name.
DEPRECATED string GetCurVolume();
// Rename current volume.
DEPRECATED void RenameCurVolume(string &name);
// Set surface/voxel mode for volume Surf=true - set surface mode,
// false - volume. It is same as click on S/V icon.
// If silent=true then no dialogs will be shown, all will be
// done by default.
DEPRECATED void SetCurVolumeMode(bool Surf,bool Silent);
// Set current volume by name, returns true if succeed.
DEPRECATED bool SetCurVolume(string &name);
// Select first volume in scene, if OnlyVisible==true then first
// visible volume will be selected.
DEPRECATED void SelectFirstVolume(bool OnlyVisible);
// Select next volume after current in tree, if OnlyVisible==true
// then next visible volume will be selected. Returns false if
// current volume is last in list.
DEPRECATED bool SelectNextVolume(bool OnlyVisible);
// Example of walking through all volumes:
void main() {
string s=GetCurVolume(); //keep current selection
do {
//insert your action
} while( SelectNextVolume(true));
SetCurVolume(s); //restore initial selection
// Checks if volume is empty.
DEPRECATED bool CurVolumeIsEmpty();
// Get current volume polycount.
DEPRECATED int GetCurVolumePolycount();
// Get polycount of whole voxel scene.
DEPRECATED int GetVoxSceneVisiblePolycount();
// Get polycount of visible volumes.
DEPRECATED int GetVoxScenePolycount ();
// Get current volume shader name.
DEPRECATED string GetCurVolumeShader();
// Set volume visibility (like with eye icon).
DEPRECATED void SetVolumeVisibility(bool vis)
// Returns current volume visibility.
DEPRECATED bool GetVolumeVisibility()
// Sets Ghost property to volume.
DEPRECATED void SetVolumeGhosting(bool Ghosting)
DEPRECATED void SetCurVolumeTransform(Mat4& transform)
// Set/get current volume transform as 4-dimentional matrix.
// See the Mat4 class description.
DEPRECATED Mat4 SetCurVolumeTransform()
DEPRECATED bool GetVolumeSquare()
// Get square and volume of the current volume.
DEPRECATED bool GetVolumeVolume()
// Get Ghost property from the volume.
DEPRECATED bool GetVolumeGhosting()
// Set opacity of the current volume if the shader
// has corresponding property.
DEPRECATED void SetVolumeOpacity(float Opacity)
// Set current volume color if this property of shader is available.
DEPRECATED void SetVolumeColor(int Color)
// Assign val to current object shader property field.
DEPRECATED void SetShaderProperty(string &id, string &val)

Also check this full list of functions:

// Returns whole command line.
string getCommandLine();
// Stores some string as global value that may be read later in
// the session. The value will be stored in 3B file and you will
// be able to read in further work with this scene.
DEPRECATED void SetGlobalVar(string& Name,string& Value)
// Returns value previously stored using SetGlobalVar.
DEPRECATED string GetGlobalVar (string& Name)
// Returns scene filename (last saved or opened as 3B file).
DEPRECATED string GetSceneFileName()
// Sets scene filename for further saving.
DEPRECATED void SetSceneFileName(string& Name)
// Highlight element with red rectangle.
// Pass the `time` in seconds.
void HighlightUIElement(string &ID, float time);
// Goes to one of previous dialogs in call stack.
DEPRECATED void back(int steps=1);
// Opens window described by xml-file pointed by Path.
// If Path contains .3b file will be opened as 3B file.
DEPRECATED void open(string &Path);
// Opens model for PPP, if path is empty, shows open dialog.
DEPRECATED void ppp(string &path);
// Opens model for MV painting, if path is empty, shows open dialog.
DEPRECATED void mv(string &path);
// Opens model for Ptex, if path is empty, shows open dialog.
DEPRECATED void ptex(string &path);
// Import image as mesh, dialog will be shown.
DEPRECATED void imagemesh();
// Import mesh as reference, if path is empty dialog will be shown.
DEPRECATED void refmesh(string &path);
// Import mesh for vertex painting, if path is empty dialog will be shown.
DEPRECATED void vertexpaint(string &path);
// Perform autopo over the mesh chosen in dialog.
DEPRECATED void autopo(string &path);
// Opens mesh for repairing. If id contains "vox" then model will be
// voxelized, if there is substring "shell" then mesh will be imported
// as thin shell. Mesh Opening dialog will be shown.
DEPRECATED void repair(string &id);
// Activate bas-relief tool.
DEPRECATED void bass();
// Activale remove undercuts mode.
DEPRECATED void undercut();
// Activate special voxel tool. id may be found in English.xml between
// <ID>...</ID> if you will find name of tool between
// <Text>...</Text> tags.
DEPRECATED void activate(string &id);
// Activate retopo tool.
DEPRECATED void retopo();
// Open mesh using dialog and merge as retopo mesh.
DEPRECATED void retopopen();
// Activate any room - name is one of "Paint", "Tweak", "UV",
// "Voxels", "Retopo", "Render".
DEPRECATED void ToRoom(string &name);
// Check if you are in specified room - name is one of "Paint",
// "Tweak", "UV", "Voxels", "Retopo", "Render".
DEPRECATED bool IsInRoom(string &name);
// Add new volume in voxel room. If name is empty name will be
// assigned automatically.
DEPRECATED void AddNewVolume(string &name);
// Activate UV room.
DEPRECATED void uv();
// Activate voxel room and add new volume.
DEPRECATED void vox();
// Create sphere of radius R in voxel room in current object.
// \param mode 0 - add, 1 - subtract, 2 - intersect with scene.
DEPRECATED void sphere(float x,float y,float z,float r,int mode);
// Create cube in voxel room in current object.
// \param mode 0 - add, 1 - subtract, 2 - intersect with scene.
// \param sizex Size by X-axis.
// \param sizey Size by Y-axis.
// \param sizez Size by Z-axis.
DEPRECATED void cube(float x,float y,float z,float sizex,float sizey,float sizez,int mode);
// Turn all volumes to surface mode.
DEPRECATED void surf();
// Turn current volume to the surface mode.
DEPRECATED void cursurf();
// Turn current volume to voxel mode, voxelize if need.
DEPRECATED void voxelize();
// Sets merging options in voxel room. opt is just set of substrings
// with different options. Possible values are:
// [voxelize=true]
// [voxelize=false]
// [separate=true]
// [separate=false]
// [respectneg=true]
// [respectneg=false]
// [as_skin=true]
// [as_skin=false]
// [skin=....] - to set skin thickness.
DEPRECATED void mergeopt(string &opt);
// Example:
mergeopt( "[voxelize=true][as_skin=true][skin=4.5]" );
// Merge model in voxel room. Empty string means that dialog will be shown.
DEPRECATED void merge(string &model);
// Activate voxel primitives tool. Possible primitives:
// cube, cylinder, sphere, tube, cone, ellipse, n-gon, gear.
DEPRECATED void prim(string &id);
// Apply in current tool (same as press enter).
DEPRECATED void apply();
// Apply in Merge tool without asking "Keep scale?".
// Scale will not be kept and scene scale will not be changed.
DEPRECATED void ApplyAndKeepScale();
// Apply in current tool (same as press enter) wint one difference -
// in Merge tool scale of merged object sill be automatically kept and
// scene scale changed if this merge is first.
DEPRECATED void mapply();
// Open recent 3B-file.
DEPRECATED void recent3b();
// Print text to MyDocuments/3D-CoatV4/log.txt.
DEPRECATED void Log(string &line);
// Generate integer random number min..max.
int rand(int min,int max);
// Generate floating random number min..max.
float randF(float min,float max);
// Set random generator seed.
void seed(int val);
// Show progress bar pos = 0..100.
DEPRECATED void ProgressBar(const string& message,int pos);
// Set orthogonal (true) or perspective (false) view mode.
DEPRECATED void SetOrthoMode(bool value);