Jump to content
3DCoat Forums

Core, Python API & Scripting


Recommended Posts

Quickstart


You can manage 3DСoat features with help of scripting.
The start is quite easy. Just use:

Scripts Menu >

  • Create your Script.
  • Create new Core API script.
  • Create new Python API script.


- Scripting is a series of commands that are able to be executed without the need for compiling.
When we select a tool or execute a function we are executing a command already included in the program. Creating a script allows us to combine these commands to automatically execute a series of steps that speed up our work.

- Core API (Application Programming Interface) is not just the scripting, the code you write runs at full speed of compiled C++. 
It is the powerful method to extend the 3DCoat's functionality. You may automate the job or add principally new tools.

- The 3DCoat Python API is intended to trigger UI commands, operate over the scene, and create new tools.
It is very similar to the C++ Core API, but has its own advantages and drawbacks.

-----------------------------------------------------------------
Scripting


3DCoat Scripting Manual

3DCoat uses AngelScript, which is a C++ like language. The script is a text file with commands* that are executed in personal order.

That command can be known by recording it in memory by pressing over the function RMB+MMB at the same time. Opening a notepad and pasting it we will obtain the text of the corresponding command. It is helpful to view and edit it in Notepad++ (choose “C” syntax). Then run script via file menu “Scripts / Run Script.

-----------------------------------------------------------------

Core API

Core API introduction

The Core API is the powerful method to extend the 3DCoat's functionality. You may automate the job or add principally new tools. This is not just the scripting, the code you write runs at full speed of compiled C++. 

Core API script is a compliable C++17 program, so it works on the full native C++ speed. This is far more than just a script; you may make even time-critical and multithreaded tasks and customize the 3DCoat in-depth, creating principally new functionality and tools.

But the whole process is completely transparent for you. You don't need to configure anything or manage complex project configurations.

3DCoat will lead you through the whole process with a simple wizard.

Quote

Some changes were added after version 3DCoat-2022-28:

- Core API works correctly for users with non-english user names, all the installing process is now super easy and straightforward.

- The CoreAPI compiling process changed essentially. Now only Visual Studio used, no need clang-cl. It simplifies usage because you need install only one additional software, not two as before. The download and install process completely automated.

Core API supports colored voxels as well.

-----------------------------------------------------------------

Python API

Python API introduction

The 3DCoat Python API is intended to trigger UI commands, operate over the scene, and create new tools. It is very similar to the C++ Core API, but has its own advantages and drawbacks.

  1. No need for any additional setup to make your scripts; Python is embedded into the 3DCoat distributive.
  2. Python is like a Swiss-knife, allowing you to bring the whole power of Python libraries into 3DCoat.
  3. Python is much slower than C++, so it may be used only for general management, not for deep and complex algorithms.
  4. If you are already familiar with the C++ Core API, the Python API is very similar, almost 1:1, with the same logic and function names.

-----------------------------------------------------------------

The start is quite easy. Just use Scripts->Create new script.
Then choose the template, choose path for your project.

If the Visual studio (or Visual Studio Code) installed it will start with your new file. Each example is well documented, used relatively simple syntax, so it is easy to understand from easy to complex.

You don't need to set any standard syntax in Visual Studio.
Just type code and execute in 3DCoat, not in Visual Studio.
VStudio is just like a text editor there that may show hints and help while coding.
Write your code on VStudio and save the *.cpp, open it in 3DC and it automatically runs.

-----------------------------------------------------------------------

Examples

Looking the Examples is the best way to understand the API.

Use Scripts->Create new Core/Python API script to experiment with that examples.

Link to comment
Share on other sites

  • Carlosan changed the title to Scripting and Core API
  • 3 weeks later...
  • Member

Hello! I am fairly unfamiliar with the syntax of C++ but I can mostly read it, however many of the example core scripts are a bit beyond my comprehension on first look. I wonder if it would be possible to have some more scripting examples that do simpler things but act as frameworks for extension so that me (and others like me just picking up the API) can make useful tools out of the examples while learning?

 

A few example templates that could be useful, just brainstorming:

- A script that performs an action on the current voxlayer
- a script that performs an action on all selected voxlayers
- a script that iterates over the child voxlayers, from parents to children or children to parents and does an action
- a script that matches voxlayers with a particular name pattern and performs an action if their name matches
- A script that batch renames stuff

 

The many template scripts and simple five-liners one can get for free off the internet and adapt is a great way to get familiar with an API! For non-coders starting from scratch can be a struggle

  • Like 1
Link to comment
Share on other sites

  • Member

Oh, and a big one is multiple parenting. So far with the angelscript stuff and also the 3DC GUI I haven't found a way to parent multiple selected objects at the same time, I have always had to go one by one. if I can use shift-H to select many voxlayers and then parent multiple of them to another voxlayer at the same time that would be amazing!

Link to comment
Share on other sites

... I wonder if it would be possible to have some more scripting examples...

Hi!

Yes, I will add a lot of samples.

Andrew

--------------------------

Could you please drop a line to andrewshpagin@gmail.com asking for this support

it is more effective to ask him directly.

Thanks !

Link to comment
Share on other sites

On version .28 Andrew saw:

3DCoat-2022-28 
Wed May 25 23:37:17 2022

- Core API works correctly for users with non-english user names, all the installing process is now super easy and straightforward.

- The CoreAPI compiling process changed essentially. Now only Visual Studio used, no need clang-cl. It simplifies usage because you need install only one additional software, not two as before. The download and install process completely automated.

  • Thanks 1
Link to comment
Share on other sites

  • 2 weeks later...

3DCoat-2022-32 
Mon Jun 20 00:10:35 2022

- Primitives in Core API, it allows to perform a non-destructive programmatic CSG modeling, a lot of new examples, much better documentation with a lot of images!

- RMB over the script in the Script menu allows to create the 3dcpack to distribute your script.

- Core API compiling process improved, now it uses precompiled headers, it speeds up the compiling a lot (except the first time).

Link to comment
Share on other sites

  • Carlosan changed the title to Core, Python API & Scripting
Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...