Model Operations
Interface List
| Interface Name | Description |
|---|---|
| Get Models | Get model objects |
| Hide Model | Set a model to the hidden state |
| Display Only | Set a model to the display-only state |
| Set Color | Set the color of a model |
| Reset | Reset the position of a model |
| Center | Display a model centered |
| Properties | Get model properties |
| Toggle Visibility | Hide the displayed models and show the models that are not displayed |
| Show All | Show all models |
Getting Models
//Get the top-level model
let topModel = scene.getTopModel();
//Get the child model array; the optional parameter specifies whether to sort by the assembly path.
let modelList = topModel.getChildren();
//Get all children of the assembly, including all lower-level nodes and grandchild nodes
let modelList = [];
topModel.getAllSubModels(modelList);
//Get a model by ID
let model = shapes.getShape(id,M3D.Shapes.ShapeType.MODEL);
//Get a model by assembly structure, e.g.: M3D|MAIN|PATH|0|c|24
let model = shapes.getModelBySVLPath(svlPath);
//Get a Model array by prototype ID
let modelList = shapes.getModelByProtoId(protoId);
Hiding a Model
model.setVisible(false);
Displaying Only a Model
When models are already selected, directly call the display-only command
executeRightClickCommand('rightMenu_single_display')
When nothing is selected but the model to display alone has been obtained
//First hide all models
let topModel = scene.getTopModel();
if (topModel != null) {
let tModels= shapes.getShapes(M3D.Shapes.ShapeType.MODEL);
scene.setModelIsVisible(tModels, false);
}
//Show the obtained model
model.setVisible(true);
Setting the Color
//The parameter is M3D.M3DMath.Color
//The Color constructor takes four number parameters: r, g, b, and a, each ranging from 0 to 1.
model.setColor(new M3D.M3DMath.Color(1,0,0,1));
Resetting a Model
//Reset only the initial position
model.resetMovement();
//Reset the color
model.resetColor();
//Reset the visibility
model.setVisible(model.isVisible(true));
Centering a Model
//First get the current viewport
let viewport = scene.getCurrentViewPort();
//Center everything
viewport.displayInCenter();
//Center part of it; the parameter is an array of model objects
viewport.displayInCenter(modelList);
Getting Model Properties
//Getting model properties is an asynchronous interface and must be done in the then callback
model.getModelProperties().then((properties) => {
//properties is the model property Map, Map<string,any>
})
Toggling Visibility
executeRightClickCommand('showOrHidden')
Showing All
executeRightClickCommand('showAll')