Skip to content

[mxcad_2d API documentation] (../README. md)/[2d] (../modules/2d. md)/MxProperties Window Custom

Class: MxPropertiesWindowCustom

2d.MxPropertiesWindowCustom

MxProperties Window Custom provides a custom property window interface for registering and reading properties.

Description

This class is used for plugins to register custom property callbacks with the property window, set the support state for custom properties of objects, and read and write custom property values of entities. It is an important bridge for extending object properties, customizing display and editing of property panels. Summary of usage:

  1. Call the 'onEvent_getProperties' registration property reading function;
  2. Call 'onEvent_stProperties' to register and modify the function;
  3. Use 'setElementSupportCustom', 'getElementProperties', and' setElementProperties' to interact with entities.

Example

ts
import { MxCpp, MxPropertiesWindowCustomValueType, McObjectId } from "mxcad";

MxCpp.PropertiesWindow.onEvent_getProperties((id: McObjectId) => {
  const ent = id.getMcDbEntity();
  if (!ent) return [];
  return [{
    sVarName: "DN",
    iVarType: MxPropertiesWindowCustomValueType.kDouble,
    val: ent.getxDataDouble("DN").val,
    isOnlyRead: false
  }];
});

Table of contents

Constructors

Methods

Constructors

constructor

new MxPropertiesWindowCustom()

Methods

getEntityProperties

getEntityProperties(id): MxPropertiesWindowCustomValue[]

Attribute UI program call to obtain custom attributes of a given entity

Parameters

NameType
idMcObjectId

Returns

MxPropertiesWindowCustomValue[]


onEvent_getProperties

onEvent_getProperties(call): void

Plugin program call, register and return object custom property functions.

Parameters

NameType
call(id: McObjectId) => MxPropertiesWindowCustomValue[]

Returns

void

Example

ts
import { MxCpp, MxPropertiesWindowCustomValueType, McObjectId} from "mxcad";

//On the property interface, obtain the object property event.
   MxCpp.PropertiesWindow.onEvent_getProperties((id: McObjectId) => {
       let ent = id.getMcDbEntity();
       if (!ent) return [];
       let dn = ent.getxDataDouble("DN");
       let len = ent.getxDataDouble("LEN");
       let ret = [];

       if (dn.ret) {
           ret.push({
               sVarName: "DN",
               iVarType: MxPropertiesWindowCustomValueType.kDouble,
               val: dn.val,
               isOnlyRead: false
           });
       }

       if (len.ret) {
           ret.push({
               sVarName: "LEN",
               iVarType: MxPropertiesWindowCustomValueType.kDouble,
               val: len.val,
               isOnlyRead: false
           });
       }
       return ret;
   })

onEvent_setProperties

onEvent_setProperties(call): void

Plugin program call, register and set object custom property functions.

Parameters

NameType
call(id: McObjectId, prop: MxPropertiesWindowCustomValue) => void

Returns

void

Example

ts
//On the property interface, the event of object property being modified.
   MxCpp.PropertiesWindow.onEvent_setProperties((id: McObjectId, prop: any) => {
       let ent = id.getMcDbEntity();
       if (!ent) return;
       if (prop.sVarName == "DN") {
           ent.setxDataDouble("DN", prop.val);
       }
       else if (prop.sVarName == "LEN") {
           ent.setxDataDouble("LEN", prop.val);
       }
   });

setEntityProperties

setEntityProperties(id, prop): void

Attribute UI program call, set custom attributes for a given entity

Parameters

NameType
idMcObjectId
propMxPropertiesWindowCustomValue

Returns

void


setEntitySupportCustom

setEntitySupportCustom(id, isCustomProperties?): void

The plugin program is called to set the state of the object to support custom properties displayed in the property window.

Parameters

NameTypeDefault value
idMcObjectIdundefined
isCustomPropertiesbooleantrue

Returns

void

Example

ts
  import { MxCADUiPrEntity, MxCpp } from "mxcad";

//Set object extension property values.
  async function Mx_TestExProp() {
    let selEntity1 = new MxCADUiPrEntity();

SelElement1.setMessage ("Select the object to enable custom properties");
    let idText = await selEntity1.go();
    if (!idText.isValid()) return;

    let ent = idText.getMcDbEntity();
    MxCpp.PropertiesWindow.setEntitySupportCustom(idText);

//Set object extension property values.
    ent.setxDataDouble("DN", 100);
    ent.setxDataDouble("LEN", 2000);
  }