The ComponentInstance class is used to represent component instances of a component definition or components that have been dragged from the Component Browser and placed (thus, instanced) within the Model. Therefore, the ComponentInstance class contains a reference to a corresponding ComponentDefinition object and a Transformation object (which contains the location of the component in the Drawing Window).
The add_observer method is used to add an observer to the current object.
Arguments:
Returns:
entities = Sketchup.active_model.entities definition = Sketchup.active_model.definitions[0] transformation = Geom::Transformation.new([0,0,0]) componentinstance = entities.add_instance(definition, transformation) status = componentinstance.add_observer observer
The definition method is used to retrieve the component definition for this component instance.
Returns:
# First create an instance for us to look at. entities = Sketchup.active_model.entities definition = Sketchup.active_model.definitions[0] transformation = Geom::Transformation.new([0,0,0]) componentinstance = entities.add_instance(definition, transformation) # You can get an instance's defintion with this method. definition = componentinstance.definition
The definition= method is used to set the component definition for this
component.
This method causes the instance to use a different definition, but it will
use the same transformation to position it in the Model.
Arguments:
Returns:
# Assumes that the active model contains two different components. instance1 = Sketchup.active_model.entities[0] instance2 = Sketchup.active_model.entities[1] # Grab handles to our two definitions. definition1 = instance1.definition definition2 = instance2.definition # Replace 2nd instance with the 1st definition. instance2.definition = definition1
The explode method is used to explode the component instance into separate entities.
Returns:
point = Geom::Point3d.new 10,20,30 transform = Geom::Transformation.new point model = Sketchup.active_model entities = model.active_entities path = Sketchup.find_support_file "Bed.skp", "Components/Components Sampler/" definitions = model.definitions componentdefinition = definitions.load path instance = entities.add_instance componentdefinition, transform
The glued_to method is used to retrieve the entity that this instance is
glued to.
Returns nil if it is not glued to anything.
Returns:
point = Geom::Point3d.new 10,20,30 transform = Geom::Transformation.new point model = Sketchup.active_model entities = model.active_entities path = Sketchup.find_support_file "Bed.skp", "Components/Components Sampler/" definitions = model.definitions componentdefinition = definitions.load path instance = entities.add_instance componentdefinition, transform status = instance.glued_to
The glued_to= method glues this instance to a face.
This method will raise an exception if the instance cannot be glued to the
given face. Instances cannot be glued if the definition of the instance
doesn't support gluing or if the alignment is wrong.
Returns:
depth = 100 width = 100 path=Sketchup.find_support_file "Bed.skp", "Components/Components Sampler/" model = Sketchup.active_model entities = model.active_entities pts = [] pts[0] = [0, 0, 0] pts[1] = [width, 0, 0] pts[2] = [width, depth, 0] pts[3] = [0, depth, 0] # Add the face to the entities in the model face = entities.add_face pts point = Geom::Point3d.new 10,10,0 transform = Geom::Transformation.new point definitions = model.definitions componentdefinition = definitions.load path instance = entities.add_instance componentdefinition, transform begin status = instance.glued_to = face rescue UI.messagebox $!.message end if (status) UI.messagebox status.to_s else UI.messagebox "Failure" end
The locked= method is used to lock a component instance.
Returns:
entities = Sketchup.active_model.entities definition = Sketchup.active_model.definitions[0] transformation = Geom::Transformation.new([0,0,0]) componentinstance = entities.add_instance(definition, transformation) status = componentinstance.locked = true
The locked? method is used to determine if a component instance is locked.
Returns:
entities = Sketchup.active_model.entities definition = Sketchup.active_model.definitions[0] transformation = Geom::Transformation.new([0,0,0]) componentinstance = entities.add_instance(definition, transformation) status = componentinstance.locked?
The make_unique method is used to create a component definition for this instance that is not used by any other instances.
Returns:
point = Geom::Point3d.new 10,20,30 transform = Geom::Transformation.new point model = Sketchup.active_model entities = model.active_entities path = Sketchup.find_support_file "Bed.skp", "Components/Components Sampler/" definitions = model.definitions componentdefinition = definitions.load path instance = entities.add_instance componentdefinition, transform # Returns unique component instance status = instance.make_unique
The move! method is the same as the transform! method, except that it does
not record the move as an undo operation.
This method is useful for moving entities inside of an animation or page
transition.
Arguments:
Returns:
entities = Sketchup.active_model.entities definition = Sketchup.active_model.definitions[0] transformation = Geom::Transformation.new([0,0,0]) componentinstance = entities.add_instance(definition, transformation) new_transformation = Geom::Transformation.new([100,0,0]) componentinstance.move! new_transformation
The name method is used to get the name of this instance.
Returns:
entities = Sketchup.active_model.entities definition = Sketchup.active_model.definitions[0] transformation = Geom::Transformation.new([0,0,0]) componentinstance = entities.add_instance(definition, transformation) name = componentinstance.name
The name method is used to set the name of this instance.
Arguments:
Returns:
entities = Sketchup.active_model.entities definition = Sketchup.active_model.definitions[0] transformation = Geom::Transformation.new([0,0,0]) componentinstance = entities.add_instance(definition, transformation) componentinstance.name = "Sang"
The remove_observer method is used to remove an observer from the current object.
Arguments:
Returns:
entities = Sketchup.active_model.entities definition = Sketchup.active_model.definitions[0] transformation = Geom::Transformation.new([0,0,0]) componentinstance = entities.add_instance(definition, transformation) status = componentinstance.remove_observer observer
The transform! method is used to apply a transformation to a component instance.
Arguments:
Returns:
entities = Sketchup.active_model.entities definition = Sketchup.active_model.definitions[0] transformation = Geom::Transformation.new([0,0,0]) componentinstance = entities.add_instance(definition, transformation) new_transformation = Geom::Transformation.new([100,0,0]) componentinstance.transform! new_transformation
The transformation method is used to retrieve the transformation of this instance.
Returns:
entities = Sketchup.active_model.entities definition = Sketchup.active_model.definitions[0] transformation = Geom::Transformation.new([0,0,0]) componentinstance = entities.add_instance(definition, transformation) t = componentinstance.transformation
The transformation= method is used to set the transformation on this instance.
Arguments:
Returns:
entities = Sketchup.active_model.entities definition = Sketchup.active_model.definitions[0] transformation = Geom::Transformation.new([0,0,0]) componentinstance = entities.add_instance(definition, transformation) new_transformation = Geom::Transformation.new([100,0,0]) componentinstance.transformation = new_transformation