Skip to content
On this page

The models created in MxCAD3D can have their colors set using various methods. MxCAD3D provides built-in colors such as red, blue, green, and more, which can be used directly. Alternatively, you can construct a color object using RGB values or sRGB format.

Color

typescript
// Create a BOX shape
const boxMaker = new Mx3dMkBox(50, 30, 20);
const boxShape1 = boxMaker.Shape();
const boxShape2 = boxShape1.TranslatedByVec(60, 0, 0);

// Red color - Construct a color object using the built-in named color "Color_NOC_RED" from the "MdGe.MxNameOfColor" enumeration
const redColor = new Mx3dGeColor(MdGe.MxNameOfColor.Color_NOC_RED);

// Any color - Construct a color object using RGB format. The color values for R, G, and B are in the range [0, 1]
const anyColor = new Mx3dGeColor(0.3, 1, 1, MdGe.MxTypeOfColor.Color_TOC_RGB);

// Get the document
const doc = mxcad3d.getDocument();

// Add shape labels
const boxLabel1 = doc.addShapeLabel();
const boxLabel2 = doc.addShapeLabel();

// Set the shape and color for each label
boxLabel1.setShape(boxShape1);
boxLabel1.setColor(redColor);

boxLabel2.setShape(boxShape2);
boxLabel2.setColor(anyColor);

// Update the display
mxcad3d.update();

The colors of the models will be saved in the document.