You can visit Cyclone 3DR Scripts to have access to a list of scripts samples.
For example, have a look at MyFirstScript, it will help you learn how to get started on scripting with Cyclone 3DR.
Basic sample: Inspection Cloud vs Mesh
Additionally, here is a small sample that creates a mesh from a selected point cloud (using SPoly.Direct3DMesh) and then performs an inspection analysis (using SPoly.Compare)
// Utility function to output an error and stop the script execution
static Object Direct3DMesh(SCloud cloudToMesh, number deviationError, number minAverageDist, HoleOptionEnum optionHole, number sizeTriHole, boolean isScanDirIgnored=false)
Make a direct 3D mesh of a SCloud according to different strategies (regular, deviation,...
How can I retrieve an element from the current document?
There are 4 ways to request elements from the current document:
All: To retrieve all elements from a given type.
FromSel: To retrieve the current selected elements.
FromName: To query elements from their names.
FromClick: To query an element clicked by the user.
These functions are static and accessible in SComp or any derived SComp class (such as SPoly.All for example). The usage will depend on the type of object you want to query.
All()
To find all elements of a given type.
The function will return a table with all elements of a defined type depending on a visibility criterion.
var allNotVisiblePolys = SPoly.All(0); // Will contains all non visible SPolys in the document.
var allVisibleClouds = SCloud.All(1); // Will contains all visible SClouds in the document.
var allPoints = SPoint.All(2); // Will contains all SPoints, visible or not, in the document.
To find all selected elements of a defined type.
Selection can be used before running script or during script execution.
The function will return a table with all selected elements of a defined type.
And more, selection can be done during SDialog execution.
var tblPlane = SPlane.FromSel(); // Will contains all selected planes. Can be empty if no plane has been selected.
if(tblPlane.length > 0)
var firstPlane = tblPlane[0]; // Get the first plane
Unlike previous function, this command will pause the script and wait until you click a point in the document.
If the clicked point corresponds to an element of the defined type, the element is returned, else an error is returned.
A specific case exists for SPoint function which can return the clicked entity or a projection of the clicked point.
var result = SCloud.FromClick(); // Click to select a point cloud in the scene
if (result.ErrorCode != 0)
{
print("An error occurred. No cloud has been selected."); // print an error message if no success
}
else
{
print("Point Cloud " + result.Cloud.GetName() + " has been selected for meshing."); // print the name of the cloud
Launch an interaction to select a SCloud in the scene.
How can I insert elements in my document?
By default, imported objects are not inserted inside the current document.
Use SComp.AddToDoc() to insert an element in the current document.
How can I import files?
FromFile()
This static function is available for most classes. For example, SPoly.FromFile, SCloud.FromFile, etc.
The function will return elements loaded, it means that the elements are not inserted in the current document.
var load = SPoly.FromFile( 'C:/Poly.stl' ); // will load file Poly.stl in the script but not in the current document.
if (load.ErrorCode == 0)
{
var mesh = load.PolyTbl[0];
print("The import of the object " + mesh.GetName() + " succeeded.");
// Add the mesh in the document
mesh.AddToDoc();
}
else
{
thrownew Error("The import of the object failed.");
This static function is available for most of classes. For example, SPoly.Save, SMultiline.Save and SCloud.Save
Elements are not added in the current document.
In script, you can create new object through the use of static methods nammed New.
Depending on the object, several constructors may exist with different input parameters.
To copy a script object, you cannot use the = operator, indeed the = operator merely copies the object reference and does not create a copy.
To copy a SObject instance, you must use the New( objectToCopy ) constructor available for most classes.