# Select all things in the file
model = Sketchup.active_model
# Create component, Give a name, other settings are default
comps_path = Sketchup.find_support_file("Components")
model.name= "ComponentName"
model.description= "Some text describing the component."
filename = "#{model.name}.skp"
filepath = File.join(comps_path,filename)
model.save_copy(filepath)
# Clear out stuff so we don't get copies of resources
model.entities.clear!
model.definitions.purge_unused
model.layers.purge_unused
model.materials.purge_unused
# Load the new component definition
cdef = model.definitions.load(filepath)
# Add an instance of the new definition at the ORIGIN:
model.entities.add_instance(cdef,IDENTITY)
Another problem, the above code is working well for all sketchup file. However, for the large .skp file, such as 800Mb…it takes about 40 mins…So, is there a way I could optimize that?
Secondly, set the model’s name and description that’ll be displayed in the Components panel …
model.name= "Some Component Name"
model.description= "Some text that describes the component."
EDIT: You can also do this manually from the File panel of the Model Info dialog.
(There are also the glue, opening, shadow and face camera controls for components on this panel.)
Then, save the model.
Lastly, as said above …
Open the save location and copy it to your %AppData% “Components” folder (or subfolder), or some other location if you’ve already set up “local components collection(s)”.
To get quickly to your user components: Window (menu) > Preferences (dialog) > Files (panel)
and click the browse to folder button …
And BTW, … inserting 800MB components into other models is crazy. This’ll slow down modeling considerably.