Property Operations
Property Operations
Set and retrieve entity properties, including color, layer, linetype, lineweight, transparency, and more.
Online Examples
| Example | Description | Link |
|---|---|---|
| Color Settings | color, color index, and RGB true color | Online Demo{target="_blank"} |
| Layer Settings | Usage of the layer property | Online Demo{target="_blank"} |
| Linetype Settings | Usage of lineType and lineTypeScale | Online Demo{target="_blank"} |
| Lineweight Settings | lineWeight, standard lineweight values, layer lineweight, and LWDISPLAY | Online Demo{target="_blank"} |
| Transparency Settings | Usage of transpMgr | Online Demo{target="_blank"} |
| Apply Defaults | Usage of setDefaults | Online Demo{target="_blank"} |
| Extended Data | Attach custom data to entities and export / reload with DWG | Online Demo{target="_blank"} |
| Visibility | visible property (DXF 60) to show / hide a single entity | Online Demo{target="_blank"} |
Core API
Color Settings
WebCAD supports two color representations:
// Indexed colors (1-255)
entity.color = 1; // Red
entity.color = 2; // Yellow
entity.color = 3; // Green
// RGB true color
entity.color = 0x1000000 + 0xFF8000; // Orange (RGB: 255, 128, 0)Lineweight Settings
Lineweight values use 0.01 mm as the unit. For example, 25 means 0.25 mm.
Standard lineweight values
| Value | Width | Value | Width | Value | Width |
|---|---|---|---|---|---|
0 | 0.00 mm (thin) | 50 | 0.50 mm | 140 | 1.40 mm |
5 | 0.05 mm | 53 | 0.53 mm | 158 | 1.58 mm |
9 | 0.09 mm | 60 | 0.60 mm | 200 | 2.00 mm |
13 | 0.13 mm | 70 | 0.70 mm | 211 | 2.11 mm |
15 | 0.15 mm | 80 | 0.80 mm | -1 | ByLayer |
18 | 0.18 mm | 90 | 0.90 mm | -2 | ByBlock |
20 | 0.20 mm | 100 | 1.00 mm | -3 | Default (0.25 mm) |
25 | 0.25 mm | 106 | 1.06 mm | ||
30 | 0.30 mm | 120 | 1.20 mm | ||
35 | 0.35 mm | ||||
40 | 0.40 mm |
Set entity lineweight
const line = new LineEnt([0, 0], [100, 0]);
line.setDefaults();
line.lineWeight = 50; // 0.50 mm
Engine.addEntities(line);
// Special values
line.lineWeight = -1; // ByLayer
line.lineWeight = -2; // ByBlock
line.lineWeight = -3; // Default, uses LWDEFAULT (0.25 mm)Set layer lineweight
doc.layers.add("ThickLineLayer", {
color: 1,
lineWeight: 100 // 1.00 mm
});
// Set entity to ByLayer to inherit layer lineweight
line.lineWeight = -1;
line.layer = "ThickLineLayer";Lineweight display switches
LWDISPLAY and SHOW_LINEWEIGHT must both be enabled for lineweight to be rendered.
// LWDISPLAY: document-level switch, saved to DWG
Engine.currentDoc.docEnv.LWDISPLAY = true;
Engine.currentDoc.docEnv.LWDISPLAY = false;
// SHOW_LINEWEIGHT: frontend global switch, not exported to DWG
SystemConstants.SHOW_LINEWEIGHT = true;
SystemConstants.SHOW_LINEWEIGHT = false;
// Regenerate after switching
Engine.regen(true);Command-line toggle
Enter LWDISPLAY (alias LW) in the command line to toggle lineweight display interactively:
Command: LW
Current lineweight display LWDISPLAY = OFF
Lineweight display [ON/OFF] <ON>:
LWDISPLAY set to ONThis command sets both LWDISPLAY and SHOW_LINEWEIGHT and refreshes the view automatically.
LWDISPLAY vs SHOW_LINEWEIGHT
LWDISPLAYis the standard DWG system variable. It is saved with the document and matches AutoCAD's lineweight buttonSHOW_LINEWEIGHTis a frontend rendering switch and is not saved to the file- The
LWDISPLAYcommand (aliasLW) controls both and is the easiest way to switch lineweight display
Apply Default Properties
After creating an entity, call setDefaults() to apply current system defaults:
const line = new LineEnt([0, 0], [100, 100]);
line.setDefaults(); // Apply current layer, color, linetype, and other defaults
// Custom properties should be set after setDefaults()
line.color = 1;
line.layer = "AnnotationLayer";
Engine.addEntities(line);Visibility
Control entity-level show / hide, corresponding to DXF Group Code 60:
// Hide entity
entity.visible = false;
// Show entity
entity.visible = true;
// Read visibility
console.log(entity.visible); // true or falseDifference from Layer Visibility
- Layer visibility (
layer.layerOn) controls the display of the whole layer and affects all entities on that layer - Entity visibility (
entity.visible) controls only one entity and does not affect others on the same layer
Extended Data (XData)
Attach custom data to an entity:
// Set extended data
entity.xdata = {
appName: "MyApp",
data: { key: "value" }
};
// Get extended data
const xdata = entity.xdata;