Make A Component Using only Ruby code
-
Is there any information on creating a component using only Ruby code? So far I have created a 3D model of my component and I basically want to now turn it into a component. I am assuming that the procedure would be to create a component definition and add it to the definition list. Then collect all of the faces and edges of my component and add them to the new componentdefinition.entities collection. I would then like to save the model as a .skp file. Is that it? Is there a better way? I want to use code only from input parameters - no user intervention after inputs. Any advice would be appreciated. I will be happy to share some sample code on this forum when completed. Thanks.
-
Hi Steve,
You seem to have a grip on it for the most part. Instead of creating the geometry before creating the ComponentDefinition, you should create the Definition and then add entities to its Entities collection.
You can use
ComponentDefinition#save_as
to save it out to disk.new_def = Sketchup.active_model.definitions.add("My Component") new_def.entities.add_face(...) new_def.save_as("C;/My Component.skp") model.entities.add_instance(new_def, [0,0,0])
Advertisement