- open a sketchup file, select a group,
s1 = Sketchup.active_model.selection.first
- open a new file,
- copy s1 to new file:
- save the file,
- close file,
then, Sketchup crashed.
command + C to copy to the new file and save then close it, Sketchup won’t crash.
What are the differences between the two copy methods? How could I avoid the crash if I use API?
The API code is written so that it expects operations only upon the active model.
It is the API programmer’s responsibility to always write code that stays within this assumption.
Your crashing code example broke this rule. It attempted to add an instance of a component definition that did not belong to the model’s definition list that you were inserting it in.
Paradigm 1: (Something like this. – UNTESTED)
def onActivateModel(model) # <--<<< Mac ONLY
return if Sketchup.active_model.selection.empty?
# change model by opening a new one:
Would be to save out the component as a skp file, then load it into the new model’s definition list, then place an instance at the desired transform.
@tt_su Thomas, do you think this crash scenario should get a GitHub issue, even though it should not have been attempted. Ie … should
#add_instance raise an exception if the definition argument does not belong to the
entities receiver’s model ?