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

Рассмотрим нСсколько простых Π΄ΠΈΠ°Π»ΠΎΠ³ΠΎΠ²Ρ‹Ρ… ΠΎΠΊΠΎΠ½, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ Ρ‚Ρ‹ моТСшь ΡΠΎΠ·Π΄Π°Ρ‚ΡŒ ΠΈΠ· своСго скрипта. Π‘ΠΎΠ»Π΅Π΅ слоТныС ΠΏΡ€ΠΈΠΌΠ΅Ρ€Ρ‹ ΠΎΠΊΠΎΠ½ с ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€Π°ΠΌΠΈ смотри здСсь.

ΠŸΡ€ΠΎΡΡ‚ΠΎΠΉ ΠΏΡ€ΠΈΠΌΠ΅Ρ€ Π΄ΠΈΠ°Π»ΠΎΠ³ΠΎΠ²ΠΎΠ³ΠΎ ΠΎΠΊΠ½Π°:

// простой счётчик Π²Ρ€Π΅ΠΌΠ΅Π½ΠΈ
int t;
void main() {
t = 0;
// ΠΏΠΎΠ΄Π³ΠΎΡ‚Π°Π²Π»ΠΈΠ²Π°Π΅ΠΌ сцСну
SculptRoom room;
room.clear().toSurface();
// эта функция Π±ΡƒΠ΄Π΅Ρ‚ Π²Ρ‹Π·Π²Π°Π½Π° ΠΏΡ€ΠΈ появлСнии ΠΎΠΊΠ½Π°
SetModalDialogCallback( "dialogCallback" );
// ΠΎΡ‚ΠΎΠ±Ρ€Π°ΠΆΠ°Π΅ΠΌ ΠΎΠΊΠ½ΠΎ с простым сообщСниСм
ModalDialog( "Some message", "Title" );
}
void dialogCallback() {
// Π½Π°ΠΆΠΌΡ‘ΠΌ Π½Π° ΠΊΠ½ΠΎΠΏΠΊΡƒ Π² ΠΎΠΊΠ½Π΅ Ρ‡Π΅Ρ€Π΅Π· нСсколько сСкунд послС Π΅Π³ΠΎ открытия
if (t++ > 400) {
UI ui;
ui( "$DialogButton#1" );
}
}

Π—Π΄Π΅ΡΡŒ появляСтся тСкст Π² ΠΎΠΊΠ½Π΅, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ исчСзнСт Ρ‡Π΅Ρ€Π΅Π· нСсколько сСкунд.

ΠŸΡ€ΠΈΠΌΠ΅Ρ€ послоТнСС. НапСчатаСм список всСх Ρ„Π°ΠΉΠ»ΠΎΠ² ΠΈΠ· ΠΏΠ°ΠΏΠΊΠΈ.

// счётчик Ρ„Π°ΠΉΠ»ΠΎΠ²
int n;
// список Ρ„Π°ΠΉΠ»ΠΎΠ²
string files;
void main() {
n = 0;
files = "";
// спросим Ρƒ Ρ…ΡƒΠ΄ΠΎΠΆΠ½ΠΈΠΊΠ°, Ρ…ΠΎΡ‡Π΅Ρ‚ Π»ΠΈ ΠΎΠ½ Π·Π°ΠΏΡƒΡΡ‚ΠΈΡ‚ΡŒ Π½Π°ΡˆΡƒ ΠΎΠ±Ρ€Π°Π±ΠΎΡ‚ΠΊΡƒ
bool ok = ModalDialogOkCancel( "Start processing files?", "" );
if ( !ok ) {
// ΠΏΡ€Π΅ΠΊΡ€Π°Ρ‚ΠΈΠΌ Π²Ρ‹ΠΏΠΎΠ»Π½Π΅Π½ΠΈΠ΅ скрипта, Ссли Π²Ρ‹Π±Ρ€Π°Π½ `Cancel`
return;
}
// Π²Ρ‹Π·ΠΎΠ²Π΅ΠΌ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΡŽ `fileProcessing()` для ΠΊΠ°ΠΆΠ΄ΠΎΠ³ΠΎ Ρ„Π°ΠΉΠ»Π°
// ΠΏΠΎ маскС `mask` ΠΈΠ· Π²Ρ‹Π±Ρ€Π°Π½Π½ΠΎΠΉ ΠΏΠ°ΠΏΠΊΠΈ
// Ρ„ΠΈΠ»ΡŒΡ‚Ρ€ для Π²Ρ‹Π±ΠΎΡ€ΠΊΠΈ Ρ„Π°ΠΉΠ»ΠΎΠ²
// Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€, для ΠΏΠ΅Ρ€Π΅Π΄Π°Ρ‡ΠΈ Π² Ρ„ΡƒΠ½ΠΊΡ†ΠΈΡŽ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ PNG ΠΈ JPG,
// ΡΡ‚Π°Π²ΡŒ маску Π² `*.png;*.jpg`
string mask = "*.png;*.jpg";
ForEachFileInFolder( "", mask, "fileProcessing" );
// ΠΏΠΎ Π·Π°Π²Π΅Ρ€ΡˆΠ΅Π½ΠΈΡŽ ΠΏΠΎΠΊΠ°ΠΆΠ΅ΠΌ Ρ‡Ρ‚ΠΎ ΠΎΠ±Ρ€Π°Π±ΠΎΡ‚Π°Π»ΠΈ
ModalDialog( "Files processed:\n" + files, "" );
}
void fileProcessing( string &in fileName ) {
++n;
files += n + ". " + fileName + "\n";
}

Π’ΠΎΡ‚ список всСх ΠΌΠ΅Ρ‚ΠΎΠ΄ΠΎΠ², ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ моТСшь ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ Π² скриптах для Ρ€Π°Π±ΠΎΡ‚Ρ‹ с Π΄ΠΈΠ°Π»ΠΎΠ³ΠΎΠ²Ρ‹ΠΌΠΈ ΠΎΠΊΠ½Π°ΠΌΠΈ:

// Show model dialog with text identified ID. The ID is used to take
// translation from language .xml or just may be shown directly
// if translation is not found.
void ModalDialog(string &in ID,string &in Caption);
// Show dialog with text identified ID and two buttons - Ok and Cancel.
// Returns true if OK pressed, false if Cancel pressed.
// The ID is used to take translation from language .xml or just may be
// shown directly if translation is not found.
bool ModalDialogOkCancel(string &in ID,string &in Caption);
// Show dialog with text identified ID and two buttons - Yes and No.
// Returns true if OK pressed, false if Cancel pressed.
// ID used to take translation from language xml or just may be shown
// directly if translation not found.
// Important! All dialogs may expose list of parameters and you are
// able to change value of any local or global variable via dialogs.
// See below a set of functions that allows to control additional parameters.
bool ModalDialogYesNo(string &in ID,string &in Caption);
// Each function that adds control passes variable name or other ID.
// Of course names of variables are are not always obvious to end-user.
// So you may translate in on normal language and make correspondence
// between ID (name of variable or any other ID in UI) and displayed text.
void AddTranslation(string& ID, string& Text);
// Add slider for floating variable. Most of functions have
// VariableName parameter. It is the name of variable (local or global)
// you want to edit in the dialog. Look example a bit later.
// Min, Max – range if the value. Variable should be declared as
// float VariableName; in global or local scope.
void AddFloatSlider(string &in VariableName,float Min,float Max);
// Add slider for integer variable. Variable should be declared as
// int VariableName; in global or local scope.
void AddIntSlider(string &in VariableName,int Min,int Max);
// Add input box for floating variable.
void AddFloatInput(string &in VariableName,bool EmptyName);
// Add input box for integer variable.
void AddIntInput(string &in VariableName,bool EmptyName);
// Add input box for string variable.
void AddStringInput(string &in VariableName,bool EmptyName);
// Insert the text among the list of variables.
void AddTextField(string &in TextID,int Align);//1-center,0-left
// Insert delimiter.
void AddDelimiter();
// Insert button that will call function
void AddButton(string &in FuncName);
// Place next controls in `nc` columns.
void Columns(int nc);
// Example:
Columns(2);
AddButton("Function1");
AddButton("Function2");
// In this case 2 buttons will be aligned horizontally in the dialog.
// Add checkbox. BoolVarRef shoud refer existing boolean variable
// declared as bool VariableName;
void AddCheckBox(string &in BoolVarRef);
// Add droplist with several cases. Case index will be stored
// in `IntVarRef` variable. CaseList is list of possible values
// for droplist, delimiters are `,;|`.
void AddDroplist(string &in IntVarRef,string &in CaseList);
// Example
Int Case=0;
...
AddDroplist("Case","Case1,Case2,Case3");
// \see StopUICondition()
void UICondition(string& fn);
// That functions allow to control appearance of UI elements.
void StopUICondition();
// Example explains all:
bool ShowSlider1and2;
float Slider1;
float Slider2;
float Slider3;
bool CheckUI(){
return ShowSlider1and2;
}
void main(){
AddCheckBox("ShowSlider1and2");
UICondition("CheckUI"); // function CheckUI should return true if elements below should be visible
AddFloatSlider("Slider1",0,123);
AddFloatSlider("Slider2",0,123);
StopUICondition(); // This function ends scope of previous UICondition
AddFloatSlider("Slider3",0,123); // This slider is always visible
ModalDialogOkCancel("","");
}
// This function should be called before you call any of modal dialogs
// function if you want to press button number ButtonIndex
// (first button is 1, second is 2).
void PressInNextModalDialogs(int ButtonIndex);
// For example, if you have Yes and No buttons and you call
// PressInNextDialogs(1) before showing dialog then Yes will be
// pressed automatically.
// You should call PressInNextDialogs(-1) to stop automatical
// pressing of buttons.
// When you call any modal dialog the execution of the script will be
// stopped until user press Ok or other button in the dialog.
// Thus you are loosing control over dialog execution. If you want to do
// some action in the dialog, change some field you need to setup routine.
// That will be called constantly when dialog will be active.
// The routine may change fields in dialog, press buttons, and do
// other things.
// You may get the name of a current dialog name using next function.
void SetModalDialogCallback(string &in name);
// Remove all dialog callbacks.
void RemoveModalDialogCallbacks();
// Show non-modal message on screen that will be hidden after some
// period of time will pass (Time, sec).
void ShowFloatingMessage(string &in ID,float Time);
// Returns true if you are in dialog now, also it retuns text and
// caption in a current dialog to identify it.
bool GetCurrentDialog(string &out ID,string &out Caption);
// Get index of button pressed in last dialog. Usually OK=1, Cancel=2.
int GetLastButtonIndex();

Π§Ρ‚ΠΎΠ±Ρ‹ ΠΎΡ‚ΠΊΡ€Ρ‹Π²Π°Ρ‚ΡŒ ΠΎΠΊΠ½Π° для Π²Ρ‹Π±ΠΎΡ€Π° Ρ„Π°ΠΉΠ»ΠΎΠ², Π²ΠΎΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡΡ этим функциями:

// Show open file dialog. List extensions like in example - *.tga;*.jpg;
// The resulting file name will be placed in result.
// Function returns true if file is successfully chosen.
DEPRECATED bool OpenDialog(string &in extensions,string &out result);
// Show save file dialog. List extensions like in example - *.tga;*.jpg;
// The resulting file name will be placed in result.
// Function returns true if file is successfully chosen.
DEPRECATED bool SaveDialog(string &in extensions,string &out result);
// Show selecting folder dialog. The resulting file name
// will be placed in result.
// Function returns true if file is successfully chosen.
DEPRECATED bool FolderDialog(string &out result);
// Some functions in 3DCoat may engage file dialog that
// will wait user's input.
// You may skip that dialogs and provide file name
// automatically so that file dialog will return specified
// file name without waiting for user's input.
// Use empty name "" to stop automatic file dialogs skipping
// othervice all next file dialogs will be skipped and it may
// lead to loosing data.
DEPRECATED void SetFileForFileDialogs(string &in name);
// Returns true if Cancel pressed in the last file dialog.
DEPRECATED bool FileDialogCancelPressed();
Π‘ΠΌ. Ρ‚Π°ΠΊΠΆΠ΅
πŸŒ€ Π‘ΠΎΠ·Π΄Π°Π½ΠΈΠ΅ своих Π΄ΠΈΠ°Π»ΠΎΠ³ΠΎΠ²