Class: Sketchup::ComponentDefinition

Inherits:
Drawingelement show all
Includes:
Comparable

Overview

The ComponentDefinition class is used to define the contents for a SketchUp component. Components are a collection of entities that can be instanced and reused multiple times throughout a model. For example, you could draw a chair once, turn it into a component, and then use 6 instances of it to surround a table. Edits to the original “definition” will then propagate across all of its instances.

The ComponentDefinition class contains the global entities and settings for each definition. See the ComponentInstance class for how each copy is defined.

Version:

  • SketchUp 6.0

Instance Method Summary # collapse

Methods inherited from Drawingelement

#bounds, #casts_shadows=, #casts_shadows?, #erase!, #hidden=, #layer, #layer=, #material, #material=, #receives_shadows=, #receives_shadows?, #visible=, #visible?

Methods inherited from Entity

#attribute_dictionaries, #attribute_dictionary, #delete_attribute, #deleted?, #entityID, #get_attribute, #inspect, #model, #parent, #persistent_id, #set_attribute, #to_s, #typename, #valid?

Instance Method Details

#<=>(compdef2) ⇒ Object

The <=> method is used to compare two ComponentDefinition objects for sorting. The comparison is done based on the component name.

Examples:

c1=Sketchup.find_support_file "Bed.skp",
  "Components/Components Sampler/"
c2=Sketchup.find_support_file "Fence.skp",
  "Components/Components Sampler/"
if c1 <=> c2
  UI.messagebox("c1 sorts before c2")
end

Returns status - a -1 if component1 is less then component2. A 1 if component1 greater than component2

Parameters:

  • compdef2

    The second component definition in the comparison.

Returns:

  • status - a -1 if component1 is less then component2. A 1 if component1 greater than component2

Version:

  • SketchUp 6.0

#==(compdef2) ⇒ Object

The == method is used to test if two ComponentDefinition objects are the same (based on their address in memory).

Examples:

c1=Sketchup.find_support_file "Bed.skp",
  "Components/Components Sampler/"
c2=Sketchup.find_support_file "Fence.skp",
  "Components/Components Sampler/"
if c1 == c2
  UI.messagebox("These definitions are the same.")
end

Returns status - true if the ComponentDefinition objects are the same object. False if the objects are not the same.

Parameters:

  • compdef2

    The second component definition in the comparison.

Returns:

  • status - true if the ComponentDefinition objects are the same object. False if the objects are not the same.

Version:

  • SketchUp 6.0

#add_classification(schema_name, schema_type) ⇒ Object

The add_classification method is used to add a given classification to the component.

Note that you cannot classify image definitions.

Examples:

definition = Sketchup.active_model.definitions.first
success = definition.add_classification("IFC 2x3", "IfcDoor")

Returns true if the classification succeeds. Otherwise false.

Parameters:

  • schema_name

    a String - Schema name to add

  • schema_type

    a String - Schema type to add

Returns:

  • true if the classification succeeds. Otherwise false.

Version:

  • SketchUp 2015

#add_observer(observer) ⇒ Object

The add_observer method is used to add an observer to the current object.

Examples:

componentdefinition = Sketchup.active_model.definitions[0]
status = componentdefinition.add_observer observer

Returns true if successful, false if unsuccessful.

Parameters:

  • observer

    An observer.

Returns:

  • true if successful, false if unsuccessful.

Version:

  • SketchUp 6.0

#behaviorObject

The behavior method is used to retrieve the Behavior object associated with a component definition.

Examples:

path = Sketchup.find_support_file "Bed.skp",
  "Components/Components Sampler/"
model = Sketchup.active_model
definitions = model.definitions
componentdefinition = definitions.load path
behavior = componentdefinition.behavior

Returns:

  • behavior - a Behavior object if successful

Version:

  • SketchUp 6.0

#count_instancesObject

The count_instances method is used to count the number of unique component instances in a model using this component definition. This does not represent the total number of instances placed in the model as it doesn't take into account instances inside unused definitions.

Examples:

path = Sketchup.find_support_file('Bed.skp',
  'Components/Components Sampler/')
definitions = Sketchup.active_model.definitions
definition = definitions.load(path)
number = definition.count_instances

Returns:

  • count - the number of component instances of this component definition (if successful)

Version:

  • SketchUp 6.0

#count_used_instancesObject

The count_used_instances method is used to count the total number of component instances in a model using this component definition. This method takes into account the full hierarchy of the model.

Examples:

path = Sketchup.find_support_file('Bed.skp',
  'Components/Components Sampler/')
definitions = Sketchup.active_model.definitions
definition = definitions.load(path)
number = definition.count_used_instances

Returns:

  • count - the number of component instances of this component definition (if successful)

Version:

  • SketchUp 2016

#descriptionObject

The description method is used to retrieve the description of the component definition.

Component definitions do not have a description, by default.

Examples:

# Get the description
componentdefinition = Sketchup.active_model.definitions[0]
description = componentdefinition.description

Returns:

  • description - the description of the component definition if successful

Version:

  • SketchUp 6.0

#description=(description) ⇒ Object

The description= method is used to set the description for the component definition.

Examples:

componentdefinition = Sketchup.active_model.definitions[0]
componentdefinition.description = "This is a traditional bed"
description = componentdefinition.description

Returns status - the description if successful, false if unsuccessful

Parameters:

Returns:

  • status - the description if successful, false if unsuccessful

Version:

  • SketchUp 6.0

#entitiesObject

The entities method retrieves a collection of all the entities in the component definition

Examples:

componentdefinition = Sketchup.active_model.definitions[0]
entities = componentdefinition.entities

Returns:

  • entities - an Entities object if successful

Version:

  • SketchUp 6.0

#get_classification_value(path) ⇒ Object

The get_classification_value method is used to retrieve the value from a classification attribute given a key path.

Examples:

definition = Sketchup.active_model.definitions.first
definition.add_classification("IFC 2x3", "IfcDoor")

path = ["IFC 2x3", "IfcDoor", "ObjectType", "IfcLabel"]
value = definition.get_classification_value(path)

Parameters:

  • path

    An array composed of the key path to the value.

Returns:

  • mixed - a Ruby object if successful, nil otherwise.

Version:

  • SketchUp 2015

#group?Object

The group? method is used to determine if this component definition is used to hold the elements of a group.

Examples:

path = Sketchup.find_support_file "Bed.skp",
  "Components/Components Sampler/"
model = Sketchup.active_model
definitions = model.definitions
componentdefinition = definitions.load path
status = componentdefinition.group?

Returns:

  • status - true if the definition is used to hold a group, false if the definition does not hold a group.

  • (Boolean)

Version:

  • SketchUp 6.0

#guidObject

The guid method is used to retrieve the unique identifier of this component definition. The guid changes after the component definition is modified and the component edit is exited.

Examples:

componentdefinition = Sketchup.active_model.definitions[0]
guid = componentdefinition.guid

Returns:

  • guid - a string guid if successful

Version:

  • SketchUp 6.0

#hidden?Object

The hidden method is used to determine if this component definition should be hidden on the component browser.

Examples:

componentdefinition = Sketchup.active_model.definitions[0]
status = componentdefinition.hidden?

Returns:

  • status - true if the definition should be hidden, false if the definition should not be hidden

  • (Boolean)

Version:

  • SketchUp 6.0

#image?Object

The image? method is used to determine if this component definition is used to define an image.

Examples:

componentdefinition = Sketchup.active_model.definitions[0]
status = componentdefinition.image?
if (status)
  UI.messagebox "Component definition defines an image"
else
  UI.messagebox status.to_s
  UI.messagebox "Component definition does not define an image"
end

Returns:

  • status - true if the component definition defines an image, false if the component definition does not define an image.

  • (Boolean)

Version:

  • SketchUp 6.0

#insertion_pointObject

The insertion_point method is used to retrieve the Point3d object where the component was inserted.

Examples:

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
point = componentdefinition.insertion_point

Returns:

  • point - the Point3d where the component was inserted if successful. False if unsuccessful.

Version:

  • SketchUp 6.0

#insertion_point=(point) ⇒ Geom::Point3d

Sets the insertion point of your definition.

Examples:

point = Geom::Point3d.new(10, 20, 0)
componentdefinition = Sketchup.active_model.definitions[0]
componentdefinition.insertion_point = point

Returns The Point3d object used as the insertion point.

Parameters:

  • point (Geom::Point3d)

    The Point3d object to use as the insertion point.

Returns:

  • (Geom::Point3d)

    The Point3d object used as the insertion point.

Version:

  • SketchUp 6.0

#instancesObject

The instances method is used to return any array of ComponentInstancesfor this ComponentDefinition.

Examples:

componentdefinition = Sketchup.active_model.definitions[0]
instances = componentdefinition.instances

Returns:

  • instances - an array of ComponentInstances (if successful)

Version:

  • SketchUp 6.0

#internal?Object

The internal? method is used to determine if the component definition is internal to the Component Browser

Examples:

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
status = componentdefinition.internal?

Returns:

  • status - true if the component definition is internal to SketchUp's Component Browser. False if the component definition is not internal to SketchUp.

  • (Boolean)

Version:

  • SketchUp 6.0

#invalidate_boundsObject

Invalidates the bounding box of your definition. This command forces the update of the bounding box of definition while inside an operation. See Model.start_operation for how to start an operation.

This method is useful if you make changes to your geometry using the Ruby API and then need to know your bounding box size. This method forces SketchUp to recalculate the definition's bounding box when you choose.

Examples:

componentdefinition = Sketchup.active_model.definitions[0]
componentdefinition.invalidate_bounds

Returns:

  • true if successful

Version:

  • SketchUp 6.0

#nameObject

The name method retrieves the name of the component definition.

Examples:

path = Sketchup.find_support_file "Bed.skp",
  "Components/Components Sampler/"
model = Sketchup.active_model
definitions = model.definitions
componentdefinition = definitions.load path
name = componentdefinition.name

Returns:

  • name - the component definition's name if successful

Version:

  • SketchUp 6.0

#name=(name) ⇒ Object

The name= method is used to set the name of the component definition.

Examples:

path = Sketchup.find_support_file "Bed.skp",
  "Components/Components Sampler/"
model = Sketchup.active_model
definitions = model.definitions
componentdefinition = definitions.load path
name = componentdefinition.name="Bed"

Returns name - the name assigned to the component definition if successful

Parameters:

Returns:

  • name - the name assigned to the component definition if successful

Version:

  • SketchUp 6.0

#pathObject

The path method is used to retrieve the path where the component was loaded.

Returns nil if it is an internal component.

Examples:

path = Sketchup.find_support_file "Bed.skp",
  "Components/Components Sampler/"
model = Sketchup.active_model
definitions = model.definitions
componentdefinition = definitions.load path
path = componentdefinition.path

Returns:

  • path - a valid path if successful, false if unsuccessful

Version:

  • SketchUp 6.0

#refresh_thumbnailObject

The refresh_thumbnail method is used to force SketchUp to regenerate the thumbnail image that appears in the component browser. This is useful if you've used the API to change the geometry of your component and would like the thumbnail to match.

Examples:

componentdefinition = Sketchup.active_model.definitions[0]
componentdefinition.refresh_thumbnail

Returns:

  • nil

Version:

  • SketchUp 7.0

#remove_classification(schema_name, schema_type) ⇒ Object

The remove_classification method is used to remove a given classification from the component.

Note that you cannot classify image definitions.

Examples:

definition = Sketchup.active_model.definitions.first
success = definition.remove_classification("IFC 2x3", "IfcDoor")

Returns true if the removal succeeds. Otherwise false.

Parameters:

  • schema_name

    a String - Schema name to remove

  • schema_type

    a String - Schema type to remove. If not provided or an empty string, the currently applied schema type for the given schema name will be removed.

Returns:

  • true if the removal succeeds. Otherwise false.

Version:

  • SketchUp 2015

#remove_observer(observer) ⇒ Object

The remove_observer method is used to remove an observer from the current object.

Examples:

componentdefinition = Sketchup.active_model.definitions[0]
status = componentdefinition.remove_observer observer

Returns true if successful, false if unsuccessful.

Parameters:

  • observer

    An observer.

Returns:

  • true if successful, false if unsuccessful.

Version:

  • SketchUp 6.0

#save_as(file_path) ⇒ Object

The save_as method is used to save your definition as a SketchUp file at the specified file destination.

Examples:

my_definition = Sketchup.active_model.definitions[0]
success = my_definition.save_as "c:\\myComponent.skp"

Returns true if successful

Parameters:

  • file_path

    Local file path to save the .skp file to.

Returns:

  • true if successful

Version:

  • SketchUp 7.0

#save_thumbnail(filename) ⇒ Object

Saves a component thumbnail image. The image format is specified by the file extension of filePath. Supported image formats are bmp, jpg, png, tif, pct, and gif.

Examples:

componentdefinition = Sketchup.active_model.definitions[0]
componentdefinition.save_thumbnail "test_thumb.png"

Returns true if successful, false otherwise.

Parameters:

Returns:

  • true if successful, false otherwise.

Version:

  • SketchUp 7.0

#set_classification_value(path, value) ⇒ Object

The set_classification_value method is used to set the value of a classification attribute given a key path.

Examples:

definition = Sketchup.active_model.definitions.first
definition.add_classification("IFC 2x3", "IfcDoor")

path = ["IFC 2x3", "IfcDoor", "ObjectType", "IfcLabel"]
success = definition.set_classification_value(path, "Room 101")

Parameters:

  • path

    An array composed of the key path to the value.

  • value

    A value valid for that specific attribute.

Returns:

  • boolean - true if the path was valid, false otherwise.

Raises:

  • (NotImplementedError)

    when trying to set the value of “choice” attributes.

  • (RuntimeError)

    if the attributes being set are corrupt.

  • (TypeError)

    when trying to set a value that is not valid for the attribute.

Version:

  • SketchUp 2015