Skip to content
On this page

Temporary hiding

Below we will show you how to use the mxcad plug-in to implement temporary hiding in CAD drawings. In this function, the user can choose three operations: 1. Hide the selected entity, 2. Hide the unselected entity, 3. Displays all entities on the drawing. Skilled use of temporary hiding function can help users more efficient editing operation drawings, improve work efficiency.

Function implementation

  1. Set operation options

We can call MxCADUiPrKeyWord Keywords are obtained based on user input. Then, invoke MxCADUiPrKeyWord.setKeyWords() Method sets the three operations as three options, each corresponding to a keyword.

ts
// Set keyword options
const getKey = new MxCADUiPrKeyWord();
getKey.setMessage("\n Input options")
getKey.setKeyWords("[Hide(A)/HideUnselected(B)/ShowAll(C)]");
const keyVal = await getKey.go();
if(!keyVal) return;
  1. Perform different operations based on the options

In the above steps, we set three options: hide, hide not selected, and show all. In these three options to hide, hide the unselected two action items we call through MxCADUtility.userSelect() Method to get the user selection and do the corresponding hiding operation on the selected entity according to the option. And finally, All display option passed MxCADSelectionSet.allSelect() Method displays all hidden entities in the drawing.

ts
let mxcad = MxCpp.getCurrentMxCAD();
// Set the corresponding action according to the option
if (keyVal === 'A' || keyVal === 'B') {
    // Selection objective function
    let aryId = await MxCADUtility.userSelect("Select the target object");
    if (aryId.length == 0) {
        return;
    }
    let arr: number[] = [];
    aryId.forEach((obj_id: McObjectId) => arr.push(obj_id.id))
    if (keyVal === 'A') {
        // Hides the selected entity
        aryId.forEach(async (id) => {
            let event = await id.getMcDbEntity() as McDbEntity;
            let event_clone = event.clone() as McDbEntity;
            event_clone.visible = false;
            mxcad.drawEntity(event_clone);
            event.erase()
        })
    } else if ( keyVal === 'B') {
        // Invert selection
        // Get all the object ids of the drawing and iterate to remove the id of the selected object
        let selectArr = new MxCADSelectionSet();
        selectArr.allSelect();
        selectArr.forEach(async obj_id => {
            if (!arr.includes(obj_id.id)) {
                let event = await obj_id.getMcDbEntity();
                let event_clone = event.clone() as McDbEntity;
                event_clone.visible = false;
                mxcad.drawEntity(event_clone);
                event.erase()
            }
        })
    }
} else if (keyVal === 'C') {
    // Show all
    let selectArr = new MxCADSelectionSet();
    selectArr.allSelect();
    selectArr.forEach(async id => {
        let event: any = await id.getMcDbEntity();
        let event_clone = event.clone()
        if (event_clone.visible === false) {
            event_clone.visible = true;
            mxcad.drawEntity(event_clone);
            event.erase()
        }
    })
} else {
    return;
}

Functional practice

Practical effects are as follows:

  • Click the Temporary Hide button to perform the temporary hide method
  • Follow the command line prompts to select keywords and enter the target keywords in the input box
  • Selecting Hide or Hide unselected options requires you to select the entity object in the drawing that you want to hide, or you want to unselect. Left click to start the box selection, or tap and right click to end the selection
  • The operation is performed successfully