3DCoatScripting  4.8.31Ξ²
Π‘ ΠΏΠΎΠΌΠΎΡ‰ΡŒΡŽ скриптинга ΠΌΠΎΠΆΠ½ΠΎ ΡƒΠΏΡ€Π°Π²Π»ΡΡ‚ΡŒ возмоТностями ΠšΠΎΡƒΡ‚Π° ΠΈ Ρ€Π°ΡΡˆΠΈΡ€ΡΡ‚ΡŒ Π΅Π³ΠΎ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΎΠ½Π°Π».
πŸŒ€ ВзаимодСйствиС с интСрфСйсом ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»Ρ

ΠœΡ‹ ΠΏΠΎΡΡ‚Π°Ρ€Π°Π»ΠΈΡΡŒ максимально ΡƒΠΏΡ€ΠΎΡΡ‚ΠΈΡ‚ΡŒ доступ ΠΊ UI (User Interface) 3DCoat ΠΈΠ· скриптинга.

Π’Ρ‹ моТСшь Π²Ρ‹Π±Ρ€Π°Ρ‚ΡŒ ΠΈΠ· скрипта любой ΠΏΡƒΠ½ΠΊΡ‚ мСню, Π½Π°ΠΆΠ°Ρ‚ΡŒ Π»ΡŽΠ±ΡƒΡŽ ΠΊΠ½ΠΎΠΏΠΊΡƒ, просто записав

UI ui;
ui( "ΠΠ°Π·Π²Π°Π½ΠΈΠ΅ΠšΠΎΡ‚ΠΎΡ€ΠΎΠ΅Π’ΠΈΠ΄ΠΈΡˆΡŒΠΠ°Π­ΠΊΡ€Π°Π½Π΅" );

Π‘ΠΏΡ€ΠΎΡΠΈΡˆΡŒ: "А ΠΊΠ°ΠΊ ΠΆΠ΅ Π±Ρ‹Ρ‚ΡŒ с полями Π΄Π°Π½Π½Ρ‹Ρ…"? К Π½ΠΈΠΌ ΠΏΠΎΠ»ΡƒΡ‡Π°ΠΉ доступ, ΠΎΠ±Ρ€Π°Ρ‰Π°ΡΡΡŒ ΠΏΠΎ Π²Π½ΡƒΡ‚Ρ€Π΅Π½Π½Π΅ΠΌΡƒ ΠΈΠΌΠ΅Π½ΠΈ.

ΠŸΡ€ΠΈΠΌΠ΅Ρ€:

// доступ ΠΊ ΠΎΡ‚Π»Π°Π΄ΠΊΠ΅
Debug dbg;
DebugLog log = dbg.log();


void main() {

    log.clear();

    // ΠΏΠΎΠ΄Π³ΠΎΡ‚Π°Π²Π»ΠΈΠ²Π°Π΅ΠΌ сцСну
    SculptRoom room;
    room.clear().toSurface();

    // построим сфСру
    UI ui;
    ui.toSculptRoom();
    // обращаСмся, ΠΏΠΎ возмоТности, ΠΊ названиям, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ Π²ΠΈΠ΄ΠΈΠΌ Π½Π° экранС
    // для получСния Π·Π½Π°Ρ‡Π΅Π½ΠΈΠΉ ΠΏΠΎΠ»Π΅ΠΉ Π² ΠΊΠ°Π²Ρ‹Ρ‡ΠΊΠ°Ρ…, ΠΎΠ±Ρ€Π°Ρ‰Π°ΠΉΡ‚Π΅ΡΡŒ ΠΊ Π½ΠΈΠΌ
    // ΠΏΠΎ Π²Π½ΡƒΡ‚Ρ€Π΅Π½Π½Π΅ΠΌΡƒ ΠΈΠΌΠ΅Π½ΠΈ; для Π΅Π³ΠΎ получСния, Π½Π°ΠΆΠΌΠΈ MClick + RClick
    // Π½Π° ΠΈΠ½Ρ‚Π΅Ρ€Π΅ΡΡƒΡŽΡ‰Π΅ΠΌ тСбя ΠΏΠΎΠ»Π΅
    // Π³ΠΎΠ²ΠΎΡ€ΠΈΠΌ `*Apply` вмСсто `Apply`, Ρ‡Ρ‚ΠΎΠ±Ρ‹ 3DCoat понял нашС Π½Π°ΠΌΠ΅Ρ€Π΅Π½ΠΈΠ΅,
    // Π° ΠΈΠΌΠ΅Π½Π½ΠΎ: *Π½Π°ΠΆΠ°Ρ‚ΡŒ* Π½Π° ΠΊΠ½ΠΎΠΏΠΊΡƒ
    ui( "Primitives" )( "Create sphere" )
      ( "$SpherePrim::%$px4[62]", 0 )
      ( "$SpherePrim::%$py5[62]", 0 )
      ( "*Apply" );

    // ΠΈ Π΅Ρ‰Ρ‘ ΠΎΠ΄Π½Ρƒ сфСру рядом
    ui( "$SpherePrim::%$px4[62]", 50 )
      ( "*Apply" );

    // ΠΈ Π΅Ρ‰Ρ‘ ΠΎΠ΄Π½Ρƒ Π²Ρ‹ΡˆΠ΅
    ui( "$SpherePrim::%$py5[62]", 50 )
      ( "*Apply" );
}

Π’. ΠΊ. интСрфСйс 3DCoat - многоязычный, Π΅ΡΡ‚ΡŒ ΠΎΠ΄ΠΈΠ½ ньюанс.

А ΠΈΠΌΠ΅Π½Π½ΠΎ, Ρ‡Ρ‚ΠΎΠ±Ρ‹ Ρ‚Π²ΠΎΠΉ скрипт Ρ€Π°Π±ΠΎΡ‚Π°Π» ΠΈ для 3DCoat, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ Π·Π°ΠΏΡƒΡ‰Π΅Π½ Π½Π° Π΄Ρ€ΡƒΠ³ΠΎΠΌ языкС, ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉ ΠΎΠ±Ρ€Π°Ρ‰Π΅Π½ΠΈΠ΅ ΠΏΠΎ ΠΊΠΎΠ΄Ρƒ (начинаСтся с символа $) ΠΈΠ»ΠΈ ΠΏΡ€ΠΈ запускС скрипта ΠΏΠ΅Ρ€Π΅ΠΊΠ»ΡŽΡ‡Π°ΠΉ язык интСрфСйса. Π₯ΠΎΡ€ΠΎΡˆΠΈΠΌ Ρ‚ΠΎΠ½ΠΎΠΌ Π±ΡƒΠ΄Π΅Ρ‚ Π²Π΅Ρ€Π½ΡƒΡ‚ΡŒ язык ΠΏΠΎ Π·Π°Π²Π΅Ρ€ΡˆΠ΅Π½ΠΈΡŽ скрипта.

string currentLang = ui.lang();
// Ссли Ρ‚Π²ΠΎΠΉ скрипт создавался для английского интСрфСйса
ui.lang( "english" );

// Ρ‚Π²ΠΎΠΉ скрипт

// Π²ΠΎΠ·Π²Ρ€Π°Ρ‰Π°ΠΉ язык интСрфСйса, ΠΊ ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠΌΡƒ ΠΏΡ€ΠΈΠ²Ρ‹ΠΊ Ρ…ΡƒΠ΄ΠΎΠΆΠ½ΠΈΠΊ
ui.lang( currentLang );

Π•ΡΡ‚ΡŒ Π΅Ρ‰Ρ‘ нСсколько Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΉ, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ ΠΌΠΎΠ³ΡƒΡ‚ Π±Ρ‹Ρ‚ΡŒ Ρ‚Π΅Π±Π΅ ΠΏΠΎΠ»Π΅Π·Π½Ρ‹ ΠΏΡ€ΠΈ созданиии скрипта для 3DCoat:

// Π’ΠΎ ΠΆΠ΅, Ρ‡Ρ‚ΠΎ `ui( string )`, Π½ΠΎ здСсь ΠΎΠ±Ρ€Π°Ρ‰Π°Ρ‚ΡŒΡΡ ΠΊ UI ΠΌΠΎΠΆΠ½ΠΎ
// Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΏΠΎ Π²Π½ΡƒΡ‚Ρ€Π΅Π½Π½Π΅ΠΌΡƒ ΠΈΠΌΠ΅Π½ΠΈ.
DEPRECATED bool cmd( string );

// ΠŸΡ€ΠΎΠΏΡƒΡΡ‚ΠΈΡ‚ΡŒ `n` прорисовок интСрфСйса 3DCoat.
void Step( int n );

// ΠŸΠΎΠ΄ΠΎΠΆΠ΄Π°Ρ‚ΡŒ ΡƒΠΊΠ°Π·Π°Π½Π½Ρ‹ΠΉ Π² миллисСкундах ΠΈΠ½Ρ‚Π΅Ρ€Π²Π°Π» ΠΈ ΠΏΡ€ΠΎΠ΄ΠΎΠ»ΠΆΠΈΡ‚ΡŒ
// Π²Ρ‹ΠΏΠΎΠ»Π½Π΅Π½ΠΈΠ΅ скрипта.
void Wait( int ms );

// Π‘ΠΎΠ·Π΄Π°Ρ‚ΡŒ мСню, ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠ΅ Π±ΡƒΠ΄Π΅Ρ‚ Π·Π°ΠΏΡƒΡΠΊΠ°Ρ‚ΡŒ скрипт.
// Π‘ΠΊΡ€ΠΈΠΏΡ‚ Π±ΡƒΠ΄Π΅Ρ‚ скопирован Π² ΠΏΠ°ΠΏΠΊΡƒ `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 successfuly.
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 successfuly.
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 scane object
// twice along Y-axis:
    SubstituteInputText(200.0);
    cmd("$CubPrim::ScaleY");
    Step(1);    

Π’Π°ΠΊΠΆΠ΅ Ρ‚Π΅Π±Π΅ ΠΌΠΎΠ³ΡƒΡ‚ пригодится ΠΈ эти Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈΠΈ:

// 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();

ΠŸΠΎΡΠΌΠΎΡ‚Ρ€ΠΈ Ρ‚Π°ΠΊΠΆΠ΅ этот Π½Π°Π±ΠΎΡ€ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΉ для ΠΏΠΎΠ»Π½ΠΎΠΉ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½Ρ‹ возмоТностСй:

// 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
// ... if you will find name of tool between
// ... 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);
Π‘ΠΌ. Ρ‚Π°ΠΊΠΆΠ΅
πŸŒ€ Π‘ΠΎΠ·Π΄Π°Π½ΠΈΠ΅ своих Π΄ΠΈΠ°Π»ΠΎΠ³ΠΎΠ²
πŸŒ€ Π”ΠΈΠ°Π»ΠΎΠ³ΠΎΠ²Ρ‹Π΅ ΠΎΠΊΠ½Π°