3DCoatScripting  4.8.31Ξ²
You can manage 3DΠ‘oat features with help of scripting
πŸŒ€ Making meshes out of primitives

Primitives in 3DCoat are shapes (figures) in 3D, which can be complex in a certain way. For instance, the Gear primitive looks more complex that a sphere or cube. But still it is called a "primitive".

Lets start with a sphere.

Sphere

Copy this script to your local drive and run it from 3DCoat: "Script / Run Script". Don't know how to do that, check here.

void main() {
// prepare scene
SculptRoom room;
// clear the Sculpt room a switch it to Surface mode
room.clear().toSurface();
// build a sphere
Builder builder;
Mesh mesh = builder.sphere()
.radius( 70 )
// details (wireframe density), 0 < d <= 1.0
.details( 0.1 )
.build();
// put sphere into scene
room += mesh;
}

Lets run through this code.

SculptRoom room;

Get access to sculpt room. Now use `room` for scene making.

Builder builder;

With help of `builder` we'll make various meshes.

Mesh mesh = builder.sphere()

Tell builder-script that we'd like to create sphere...

.radius( 70 )

With radius 70 px...

.details( 0.1 )

and low density wireframe.

.build();

Tell 3DCoat to create a sphere with set parameters.

It is allowed to write

();
Warning
Pay attention that () is written without leading dot, but .build() with.

Round brackets will build a sphere just like build().

Lets create a cube.

Cube or cuboid.

void main() {
// prepare scene
SculptRoom room;
room.clear().toSurface();
// build cuboid
Builder builder;
Mesh mesh = builder.cuboid()
.side( Vec3( 100, 80, 60 ) )
// details (wireframe density), 0 < d <= 1.0
.details( 0.1 )
.build();
// put cuboid into scene
room += mesh;
}

We won't analyze code below. Everything is explained on sphere.

All parameters related to Cube check here.

Cylinder

All parameters related to Cylinder check here.

Ellipsoid

void main() {
// prepare scene
SculptRoom room;
room.clear().toSurface();
// build an ellipsoid
Builder builder;
Mesh mesh = builder.ellipsoid()
.radius( Vec3( 80, 60, 40 ) )
// details (wireframe density), 0 < d <= 1.0
.details( 0.1 )
.build();
// put ellipsoid into scene
room += mesh;
}
end of script

All parameters related to Ellipsoid check here.

Cone

void main() {
// prepare scene
SculptRoom room;
room.clear().toSurface();
// build a cone
Builder builder;
Mesh mesh = builder.cone()
.radius( 50 )
.height( 120 )
// details (wireframe density), 0 < d <= 1.0
.details( 0.1 )
.build();
// put a cone into scene
room += mesh;
}

All parameters related to Cone check here.

Tube

void main() {
// prepare scene
SculptRoom room;
room.clear().toSurface();
// build a tube
Builder builder;
Mesh mesh = builder.tube()
.startPoint( Vec3( 0, 0, 0 ) )
.endPoint( Vec3( 30, 50, 70 ) )
// outer radius of the top of the tube
.topRadius( 30 )
// outer radius of the bottom of the tube
// yep, it can look like a cone
.bottomRadius( 40 )
// hole inside tube
// here - 80% of average outer tube radius
// tube thickness will be constant:
// average radius = (top radius + bottom radius) / 2
.relativeHoleRadius( 0.8 )
// details (wireframe density), 0 < d <= 1.0
.details( 0.1 )
.build();
// put a tube into scene
room += mesh;
}

All parameters related to Tube check here.

Capsule

void main() {
// prepare scene
SculptRoom room;
room.clear().toSurface();
// build a capsule
Builder builder;
Mesh mesh = builder.capsule()
.startPosition( Vec3( 0 ) )
.endPosition( Vec3( 40, 50, 60 ) )
.startRadius( 30 )
.endRadius( 50 )
// details (wireframe density), 0 < d <= 1.0
.details( 0.1 )
.build();
// put a capsule into scene
room += mesh;
}

All parameters related to Capsule check here.

NGon

void main() {
// prepare scene
SculptRoom room;
room.clear().toSurface();
// build a nGon
Builder builder;
Mesh mesh = builder.ngon()
.startPoint( Vec3( 0, 0, 0 ) )
.endPoint( Vec3( 90, 90, 90 ) )
.topRadius( 30 )
.bottomRadius( 40 )
.relativeHoleRadius( 0.3 )
// number of sides (polygons)
.teeth( 3 )
// details (wireframe density), 0 < d <= 1.0
.details( 0.1 )
.build();
// put nGon into scene
room += mesh;
}

All parameters related to NGone check here.

Gear

void main() {
// prepare scene
SculptRoom room;
room.clear().toSurface();
// build a gear
Builder builder;
Mesh mesh = builder.gear()
.startPoint( Vec3( 0, 0, 0 ) )
.endPoint( Vec3( 90, 90, 90 ) )
.topRadius( 30 )
.bottomRadius( 50 )
.relativeHoleRadius( 0.3 )
// how close teeth are to the inner radius
.depth( 0.5 )
// teeth sharpness, 0 - the sharpest
.sharpness( 0.2 )
// teeth number
.teeth( 3 )
// details (wireframe density), 0 < d <= 1.0
.details( 0.1 )
.build();
// put a gear into scene
room += mesh;
}

All parameters related to Gear check here.

Click the links to know more about class's capabilities:

Functions for making Primitives

You may also use functions for making primitives:

// Reset additional transformation for low-level primitives.
DEPRECATED void ResetPrimTransform();
// Translate all further low-level primitives.
DEPRECATED void PrimTranslate(float dx,float dy,float dz);
// Scale all further low-level primitives using pivot point x,y,z.
DEPRECATED void PrimScaleAt(float x,float y,float z,float scalex,float scaley,float scalez);
// Rotate further primitives at xyz point around X-axis.
DEPRECATED void PrimRotateX(float x,float y,float z,float Angle);
// Rotate further primitives at xyz point around Y-axis.
DEPRECATED void PrimRotateY(float x,float y,float z,float Angle);
// Rotate further primitives at xyz point around Z-axis.
DEPRECATED void PrimRotateZ(float x,float y,float z,float Angle);
// Rotate further primitives around rode (x,y,z)->(xend,yend,zend)
// on given Angle.
DEPRECATED void PrimRotateAroundRode(float x,float y,float z,float xend,float yend,float zend,float Angle);
// Set special transform for further primitives.
// If you will apply primitive that is placed between points
// (0,-1,0) and (0,1,0) it will be actually applied as primitive
// stretched between points (x,y,z) and (xend,yend,zend).
DEPRECATED void PrimStretchBetweenPoints(float x,float y,float z,float xend,float yend,float zend);
// Example:
void main(){
ResetPrimTransform();
// stretch between (10,20,30) and (40,50,60)
PrimStretchBetweenPoints(10,20,30,40,50,60);
// starts from point (0,-1,0), radius=10, height=2
cylinder(0,-1,0,10,10,2,0);
}
// This code will create cylinder of radius 10 between
// points (10,20,30) and (40,50,60).
// Set additional density factor for low-level primitives.
// 1 means default density.
DEPRECATED void PrimDensity(float density);
// Store current transform for primitives as string to be kept
// for future usage.
DEPRECATED string GetPrimTransform();
// Restore current primitives transform from string that was
// previously kept using `GetPrimTransform()`.
DEPRECATED void SetPrimTransform(string& in M);
// Example:
SetPrimTransform(
"1.0 2.0 3.0 1.0\n"
"4.0 5.0 6.0 1.0\n"
"7.0 8.0 9.0 1.0\n"
"1.1 2.2 3.3 1.0" );
// Create sphere with radius `r`.
// `x`, `y`, `z` means a center of figure.
// \param mode 0 - add, 1 - subtract, 2 - intersect with scene.
DEPRECATED void sphere(float x,float y,float z,float r,int mode);
// Create ellipse.
// `x`, `y`, `z` means a center of figure.
// \param mode 0 - add, 1 - subtract, 2 - intersect with scene.
DEPRECATED void ellipse(float x,float y,float z,float rx,float ry,float rz,int mode);
// Create parallelepiped.
// `x`, `y`, `z` means a center of figure.
// \param mode 0 - add, 1 - subtract, 2 - intersect with scene.
DEPRECATED void cube(float x,float y,float z,float sizex,float sizey,float sizez,int mode);
// Create cylinder.
// `x`, `y`, `z` means a center of figure.
// \param mode 0 - add, 1 - subtract, 2 - intersect with scene.
DEPRECATED void cylinder(float x,float y,float z,float topradius,float bottomradius,float height,int mode);
// Create cone.
// `x`, `y`, `z` means a center of figure.
// \param mode 0 - add, 1 - subtract, 2 - intersect with scene.
DEPRECATED void cone(float x,float y,float z,float radius,float height,int mode);
// Create N-gon.
// `x`, `y`, `z` means a center of figure.
// \param mode 0 - add, 1 - subtract, 2 - intersect with scene.
DEPRECATED void ngon(float x,float y,float z,int sides,float topradius,float bottomradius,float height,int mode);
// Create tube.
// `x`, `y`, `z` means a center of figure.
// \param mode 0 - add, 1 - subtract, 2 - intersect with scene.
DEPRECATED void tube(float x,float y,float z,float topradius,float bottomradius,float height,float wallthickness,int mode);
// Create n-gonal tube.
// `x`, `y`, `z` means a center of figure.
// \param mode 0 - add, 1 - subtract, 2 - intersect with scene.
DEPRECATED void ngontube(float x,float y,float z,int sides,float topradius,float bottomradius,float height,float wallthickness,int mode);
// Creates capsule between points.
// Where `xstart`, `ystart`, `zstart` means coords of first half-sphere;
// `xend`, `yend`, `zend` means coords of second half-sphere.
// \param mode 0 - add, 1 - subtract, 2 - intersect with scene.
DEPRECATED void capsule(float xstart,float ystart,float zstart,float xend,float yend,float zend,float startradius,float endradius,int mode);

Also check out this list of available 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
πŸŒ€ Math for 3D graphics
πŸŒ€ Mesh Transform
πŸŒ€ Boolean operations for meshes