# 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.