In your commands you can use SelectionCommandInput objects and they work fine. However, if you do certain modifications on the model, e.g. create a new sketch, then the Selection object of the last used SelectionCommandInput will become invalid:
var onCommandExecuted = function(args) {
try {
var command = adsk.core.Command(args.firingEvent.sender);
var inputs = command.commandInputs;
// both are filtered for vertex selection
var selection1 = inputs.itemById('selection1').selection(0);
var selection2 = inputs.itemById('selection2').selection(0);
var design = app.activeProduct;
var root = design.rootComponent;
var sketches = root.sketches;
var xyPlane = root.xYConstructionPlane;
// Monitor selection1 and selection2 in the object
// window. As soon as we create a new sketch the
// variable to the last selected entity will become
// unavailable >> <not available>
sketches.add(xyPlane);
ui.messageBox("selection1 >> " + selection1.entity.edges.count.toString()); // this succeeds
ui.messageBox("selection2 >> " + selection2.entity.edges.count.toString()); // this does not
}
catch (e) {
ui.messageBox('Failed to run command : ' + (e.description ? e.description : e));
}
};
This should not really affect you though, since you can get all the information out of the Selection objects before doing any manipulation on the model:
var onCommandExecuted = function(args) {
try {
var command = adsk.core.Command(args.firingEvent.sender);
var inputs = command.commandInputs;
// both are filtered for vertex selection
var selectedEntity1 = inputs.itemById('selection1').selection(0).entity;
var selectedEntity2 = inputs.itemById('selection2').selection(0).entity;
var design = app.activeProduct;
var root = design.rootComponent;
var sketches = root.sketches;
var xyPlane = root.xYConstructionPlane;
sketches.add(xyPlane);
ui.messageBox("selection1 >> " + selectedEntity1.edges.count.toString());
ui.messageBox("selection2 >> " + selectedEntity2.edges.count.toString());
}
catch (e) {
ui.messageBox('Failed to run command : ' + (e.description ? e.description : e));
}
};
-Adam


Leave a Reply