Loading a definition to the model


I’m trying to load a new Component Definition to my sketchup model using the following line -
But this is taking around 30 seconds for me just to load 1 definition when the file is having 7k existing component definitions, even though the file size is around 300MB.
Is there any alternative way to load outside component definitions into a model which is faster than this?

A 300MB file with 7000 definitions already sounds heavy. I’m curious how much time takes if you try to open it from the UI? It should be similar as you load it by code… (It also depends what is the file_path ?)
You can try this:
Model #import-instance_method
However I don’t think it will be so much difference regards loading time.

Even from the UI it’s taking the same amount of time as through the code (I used File->Import)

Model #import-instance_method
This one actually took more time (like 3x the time taken by model.definitions.load)

I think I have read that the amount of work SketchUp does to add another component increases with the number of components already in the model, even if the new one is relatively simple. 7000 existing definitions is already much more than most models contain, so that may be the source of the slowdown.

If you are not using all of those 7000 definitions, I would suggest purging the unused ones.

definitions = Sketchup.active_model.definitions
unused = definitions.count {|cdef| cdef.count_used_instances == 0 }
definitions.purge_unused if unused > 0
1 Like

That’s true.
When i start building the model with around 200-300 definitions it loads within a couple of seconds. As the count increases the time taken to load new component increases.

I tried this.
It reduced the number of definitions from 7000 to 900.
But still the time taken to load the definition is the same.
Do we know what factors affect the loading of a new definition into a model?

Did you resave, close and reopen the file, then retest ?

Yup, did that

I did not find an open issue in the tracker for this. Could you please log an issue?


1 Like