Notifications
Clear all

[Closed] commmand execution on object selection?

Is it possible to execute a command or function when an object is selected in the viewport? The command is triggered by the selection?

1 Reply

What you want to do is create a callback on the #selectionSetChanged event. See below:

-- This is needed to make sure you don't create more then one instance of the callback.
       callbacks.removeScripts id:#yourUniqueID;
       callbacks.addScript #selectionSetChanged "yourFunction()" id:#yourUniqueID;
   So in a practical application would be as follows:
-- This is needed to make sure you don't create more then one instance of the callback.
       callbacks.removeScripts id:#reportNameAndSize;
 callbacks.addScript #selectionSetChanged "for eachObj in selection as array do (print eachObj.name; print (distance eachObj.max eachObj.min))" id:#reportNameAndSize;
   However to make it simpler you should make a function that is called rather then writing it all out in the string input:
function reportNameAndSize inputObjs =
      (
      for eachObj in inputObjs as array do
    	(
    	print eachObj.name;
    	print  (distance eachObj.max eachObj.min);
    	);
      );
   
       -- This is needed to make sure you don't create more then one instance of the callback.
        callbacks.removeScripts id:#reportNameAndSize;
        callbacks.addScript #selectionSetChanged "reportNameAndSize selection;" id:#reportNameAndSize;