What is the task at hand? We want to make the Copy Object To Object command more efficient
There is a nifty little command – little oft used in Tekla. The “Copy Object To Object” command. It’s handy, but it could be made better: all the model objects have to be selected individually. That can be a little bit of a pain. In this lesson we will create some code, using the Open API, to allow users to select multiple objects (all at once) by which the copy object to object command can be applied to.
Where is the pertinent Call in the API? I’d prefer this type of thing to be a method on the relevant ModelObject. But it’s static method in the Operation class. Here is the hello world example, straight from the documentation:
Copying Object to Object – Hello World Example:
This is fantastic! Now let us outline what we want the command to do:
What do we want our command to do?
- We want the user to select an object (or group of objects).
- We then want the user to select a “source” object.
- We want the user to then select all objects to copy to.
- The program should then use the parent object as a source, and use that as a reference to copy everything selected in step #1 to all the objects selected in step #3.
1. Ask the user to select a bunch of model objects – The objects to copy
We can use the Picker class, located in the Tekla.Structures.Model.UI namespace. And there is a handy object which thankfully has been exposed: PickObjects(Picker.PickObjectsEnum, String). This returns a ModelObjectEnumerator which we can iterate over.
2. Ask the user to select the source object:
You can get the source object in the same manner as the above code – except you would use the PickObject method instead of the PickObjects (plural) method.
3. Ask the user to select the objects to copy to:
We can use the same method used in step 1.
4. Copy from Object To Object
The rest is as easy as A-B-C:
5. Finally, we want to Redraw Views after the Copying Operation has completed
…That’s all folks. Hope you learned something!