3DCoatScripting  4.8.31Ξ²
You can manage 3DΠ‘oat features with help of scripting
πŸŒ€ Interacting with user interface (UI)

We tried to simplified access to 3DCoat's UI from scripts.

You can select any menu item, press any button by writing a correspondent code.

UI ui;
ui( "TitleThatYouSeeOnScreen" );

You may ask: "What about data fields"? You can get access to them by using internal name.

Example:

// access to debugging
Debug dbg;
DebugLog log = dbg.log();
void main() {
log.clear();
// prepare scene
SculptRoom room;
room.clear().toSurface();
// build a sphere
UI ui;
ui.toSculptRoom();
// call UI elements on screen
// MClick + RClick to get desired element's ID
// use `*Apply` instead of `Apply`, that 3DCoat may know
// that we want to *press* the button
ui( "Primitives" )( "Create sphere" )
( "$SpherePrim::%$px4[62]", 0 )
( "$SpherePrim::%$py5[62]", 0 )
( "*Apply" );
// one more beside
ui( "$SpherePrim::%$px4[62]", 50 )
( "*Apply" );
// and one more above
ui( "$SpherePrim::%$py5[62]", 50 )
( "*Apply" );
}

Because 3DCoat is multilingual, there is nuance.

In order for your script to work properly in 3DCoat instance that uses different UI language use code (starts with $) or switch the UI language in the script. It is, of course, good to switch it back when you finish.

string currentLang = ui.lang();
// if your script were written for English interface
ui.lang( "english" );
// your script
// switch back to the default language used by an artist
ui.lang( currentLang );

Some other useful functions:

// same as `ui( string )`, but addressing to UI
// only through internal name
DEPRECATED bool cmd( string );
// skip `n` 3DCoat's UI redrawing
void Step( int n );
// wait for set interval (in milliseconds) and continue
// running script
void Wait( int ms );
// create menu that will run the script
// scrip will be copied to `Scripts/ExtraMenuItems`
// \param path Path to script which will run
void InstallToMenu( string path, string itemName );
// Check if element exists in UI. ID has same meaning as in cmd
DEPRECATED bool FieldExists(string &in ID);
// Example – how to get to know amount of lights in Render room?
void main(){
int n=0;
do{
string s="$ExtraLight::Color["+formatInt(n,"l")+"]";
if(FieldExists(s)){
n++;
}else break;
}while(true);
string s="Amount of lights = "+formatInt(n,"l");
ModalDialog(s,"");
}
// Get bool field from UI. ID has same meaning as in cmd
DEPRECATED bool GetBoolField(string &in ID);
// Set value of the boolean field in UI. ID has same meaning as in cmd
// Returns true if set value successfully
DEPRECATED bool SetBoolField(string &in ID,bool val);
// Get color field from UI as integer value. ID has same meaning as in cmd
DEPRECATED int GetColorField(string &in ID);
// Set value of the color field in UI. ID has same meaning as in cmd
// Returns true if set value successfully.
// Example of colors – 0xFF0000 – red, 0x00FF00 – green, 0x0000FF - blue
DEPRECATED bool SetColorField(string &in ID,bool val);
// Get value of slider in UI. ID has same meaning as in cmd
DEPRECATED float GetSliderValue(string &in ID);
// Set value of slider in UI. ID has same meaning as in cmd
// Returns true if set value successfully
DEPRECATED bool SetSliderValue(string &in ID,float val);
// Get value of edit box in UI. ID has same meaning as in cmd
// Returns 0 if field not found
DEPRECATED float GetEditBoxValue(string &in ID);
// Get value of edit box in UI. ID has same meaning as in cmd
// Returns true if field found
DEPRECATED bool GetEditBoxValue(string &out ID,string &out value);
// Set value of edit box in UI. ID has same meaning as in cmd
// Returns true if field found
DEPRECATED bool SetEditBoxValue(string &in ID,string &out val);
DEPRECATED bool SetEditBoxValue(string &in ID,float val);
DEPRECATED void SubstituteInputText(const string & val);
// Substitute string or value to the next input text dialog
// You need this command if there is button that triggers input
// dialog to enter some text or value
DEPRECATED void SubstituteInputText(float val);
// Example - transform tool, ScaleY button. Code to scale object
// twice along Y-axis:
SubstituteInputText(200.0);
cmd("$CubPrim::ScaleY");
Step(1);

You may need these functions:

// Get current mouse coordinate X.
DEPRECATED float GetMouseX()
// Get current mouse coordinate Y.
DEPRECATED float GetMouseY()
// Get pen pressure.
DEPRECATED float GetPressure()
// Check if LMB pressed.
DEPRECATED bool LMBPressed()
// Check if RMB pressed.
DEPRECATED bool RMBPressed()
// Check if MMB pressed.
DEPRECATED bool MMBPressed();
// Get visible (in screen projection) radius of the brush.
DEPRECATED float GetVisiblePenRadius();
// Start drawing stroke at point (x,y) with some pressure.
// \param Pressure In diapason [ 0.0 (without pressure); 1.0 (maximum pressure) ].
DEPRECATED void StartStroke(float x,float y,float Pressure)
// Draw stroke to point (x,y) with some pressure.
// \param Pressure In diapason [ 0.0 (without pressure); 1.0 (maximum pressure) ].
DEPRECATED void DrawStrokeTo(float x,float y,float Pressure)
// After that command stroke will be actually drawn.
// Set of commands StartStroke. DrawStrokeTo should be
// terminated by EndStroke.
DEPRECATED void EndStroke()
// True when object presents by ray (x,y).
DEPRECATED bool ScreenRayPicksObject(float x,float y)
// Was widget with identifier ID recently (within last Time sec) pressed?
DEPRECATED bool WasRecentlyPressed(string &in ID,float Time);
// Was widget with identifier ID recently (within last Time sec)
// pressed via RMB?
DEPRECATED bool WasRecentlyRMBPressed(string &in ID,float Time);
// Is user in tool identified as ID? To get current tool
// identifier press RMB + MMB over empty field.
DEPRECATED bool IsInTool(string &in ToolID);
// Get active tool ID.
DEPRECATED string GetCurrentToolID ();
// Get time (sec) since script started.
DEPRECATED float GetTimeSinceStart();

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);
See Also
πŸŒ€ Creating custom dialog windows
πŸŒ€ Dialogs windows