I’m getting some bugsplats (rather unpredictably) when running this chunk of code:
def load_component (anchorbolt, nuttype, washertype)
current_time = Time.now
formatted_time = current_time.strftime("%Y%m%d%H%M%S")
model = Sketchup.active_model
definitions = model.definitions
this_dir=File.dirname(__FILE__)
# Fix for ruby 2.0
if this_dir.respond_to?(:force_encoding)
this_dir=this_dir.dup.force_encoding("UTF-8")
end
filename1 = File.join(this_dir,"components/#{anchorbolt}.skp")
@componentdefinition = definitions.load(filename1)
@componentdefinition.name = "#{@Anchorbolt}_#{formatted_time}"
filename2 = File.join(this_dir,"components/#{nuttype}.skp")
@componentdefinition_nut = definitions.load(filename2)
filename3 = File.join(this_dir,"components/#{washertype}.skp")
@componentdefinition_washer = definitions.load(filename3)
end
About a year ago Eneroth made some mention of the problems with loading components from files in this thread:
I think this is what I am running into here, and it is very frustrating.
After I call this method and load the three components (files), I then modify the main component by dropping the geometry from the nut and washer components into it.
Here is the main anchor bolt method that loads the components (via the method shown above) and then modifies the main component definition:
The problem is I have no idea on how to deal with this instability. My only solution would be to convert the components to groups and then purge the components from the model so that when the plugin reloads them again it will perform the task in a predictable manner.
I’m noticing that the plugin does not crash when re-loading the nut or the washer components. These components do not get modified so I’m not sure exactly how it is handled but they do not appear to be the problem.
If I specify a different sized anchor bolt then a different file is loaded and there is no problem, the bug splat only happens when the plugin tries to reload the same file or component and enters some sort of state of confusion, or something.
After some further testing I think the editing of the main anchor bolt component is the issue. I can probably avoid the issue by creating the overall component from scratch each time and then dropping the other components into this main component so that the file or loaded components never actually get modified by the plugin. For some reason when the component is modified and then the plugin attempts to reload this component from a file it becomes unstable. I’m really not understanding what is going on here but I will do my best to come up with a work around.
Each time the foundation is edited a new anchor bolt component definition is created which is not particularly desirable but at least it is no longer is crashing SketchUp.
The only way I’ve seen DefinitonsList#load crash SketchUp is when loading a component made in a newer SketchUp version. The other unexpected behavior I’ve seen has been related to overriding existing definitions or not having the file loaded at all as SketchUp thought an existing component was identical.
… and if you have reproducible components and code that causes a splat, please file it along with file attachments in the public API issue tracker. It can become part of the test suite to prevent regression bugs even if it might be fixed in recent version(s).
I can’t quite put my finger on it but the problem seems to be with reloading the component after it has been edited by the plugin.
My new method does not attempt to “edit” any loaded component but rather creates a new container component where I simply drop the loaded components into and then explode them into a simple group within this container component. This appears to have eliminated all of the instability.