class ComponentDefinition

 

Parent: DrawingElement

Class Index

Methods: <=>, ==, behavior, count_instances, description, description=, entities, group?, guid, hidden?, image?, insertion_point, instances, internal?, name, name=, path, save_thumbnail

 

Sample Code:cdtests.rb

 

The ComponentDefinition class is used to define the contents for a component (the entities contained within a component). The ComponentDefinition can be thought of as the class used to represent components in the SketchUp Component Browser.  
 

Instance Methods

 

<=>

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

Syntax:

status = componentdefinition1 <=> componentdefinition2

Arguments:

componet1 - the first component in the comparison

component2 - the second component in the comparison

Return Value:

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

Comments:

 

Example:

path1=Sketchup.find_support_file "BedTraditional.skp" ,"Components/Furniture/"
path2=Sketchup.find_support_file "TableRound36.skp", "Components/Furniture/"
model = Sketchup.active_model

definitions = model.definitions
componentdefinition1 = definitions.load path1
componentdefinition2 = definitions.load path2

# Yields a -1
status = componentdefinition1 <=> componentdefinition2


 

==

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

Syntax:

status = componentdefinition1 == componentdefinition2

Arguments:

componetdefinition1 - the first component definition in the comparison

componentdefinition2 - the second component definition in the comparison

Return Value:

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

Comments:

 

Example:

path1=Sketchup.find_support_file "BedTraditional.skp" ,"Components/Furniture/"
path2=Sketchup.find_support_file "TableRound36.skp", "Components/Furniture/"

model = Sketchup.active_model
definitions = model.definitions
componentdefinition1 = definitions.load path1
componentdefinition2 = definitions.load path2

# Yields a false
status = componentdefinition1 == componentdefinition2


 

behavior

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

Syntax:

behavior = componentdefinition.behavior

Arguments:

 

Return Value:

behavior - a Behavior object if successful

Comments:

 

Example:

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

if (behavior)
UI.messagebox behavior
else
UI.messagebox "Failure"
end


 

count_instances

The count_instances method is used to count the number of component instances in a model using this component definition.

Syntax:

count = componentdefinition.count_instances

Arguments:

 

Return Value:

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

Comments:

 

Example:

path=Sketchup.find_support_file "BedTraditional.skp" ,"Components/Furniture/"
model = Sketchup.active_model
definitions = model.definitions
componentdefinition = definitions.load path
number = componentdefinition.count_instances

if (number)
UI.messagebox number
else
UI.messagebox "Failure"
end

 

description

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

Syntax:

description = componentdefinition.description

Arguments:

 

Return Value:

description - the description of the component definition if successful

Comments:

Component definitions do not have a description, by default.

Example:

# Set the description
componentdefinition.description="This is a traditional bed"
description = componentdefinition.description

 
 

description=

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

Syntax:

status = componentdefinition.description = description

Arguments:

 

Return Value:

status - the description if successful, false if unsuccessful

Comments:

 

Example:

componentdefinition.description="This is a traditional bed"
description = componentdefinition.description


 

entities

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

Syntax:

entities=componentdefinition.entities

Arguments:

 

Return Value:

entities - an Entities object if successful

Comments:

 

Example:

entities = componentdefinition.entities

if (entities)
length = entities.length
UI.messagebox "Number of Entities in Component: #{length}"
else
UI.messagebox "Failure"
end


 

group?

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

Syntax:

status = componentdefinition.group?

Arguments:

 

Return Value:

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

Comments:

 

Example:

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

if (status)
UI.messagebox status
else
UI.messagebox "No Groups in the Component"
end

 
 

guid

The guid method is used to retrieve the unique identifier of this component definition.

Syntax:

guid = componentdefinition.guid

Arguments:

 

Return Value:

guid - a string guid if successful

Comments:

 

Example:

guid = componentdefinition.guid


 

hidden?

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

Syntax:

status = componentdefinition.hidden?

Arguments:

 

Return Value:

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

Comments:

 

Example:

status = componentdefinition.hidden?

 

instances

The instances method is used to determine the number of component instances that use this component definition

Syntax:

instances = componentdefinition.instances

Arguments:

 

Return Value:

instances - the number of instances based on this component definition (if successful)

Comments:

 

Example:

status = componentdefinition.image?           
if (status)
UI.messagebox "Component definition defines an image"
else
UI.messagebox status
UI.messagebox "Component definition does not define an image"
end

 

image?

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

Syntax:

status = componentdefinition.image?

Arguments:

 

Return Value:

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

Comments:

 

Example:

status = componentdefinition.image?           
if (status)
UI.messagebox "Component definition defines an image"
else
UI.messagebox status
UI.messagebox "Component definition does not define an image"
end

 

insertion_point

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

Syntax:

point = componentdefinition.insertion_point

Arguments:

 

Return Value:

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

Comments:

 

Example:

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 "BedTraditional.skp" ,"Components/Furniture/"
definitions = model.definitions\
componentdefinition = definitions.load path
instance = entities.add_instance componentdefinition, transform\
point = componentdefinition.insertion_point

 

internal?

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

Syntax:

status = componentdefinition.internal?

Arguments:

 

Return Value:

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

Comments:

 

Example:

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 "BedTraditional.skp" ,"Components/Furniture/"
definitions = model.definitions
componentdefinition = definitions.load path
status = componentdefinition.internal?

 
 

name

The name method retrieves the name of the component definition.

Syntax:

name = componentdefinition.name

Arguments:

 

Return Value:

name - the component definition's name if successful

Comments:

 

Example:

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


 

name=

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

Syntax:

name - componentdefinition.name = name

Arguments:

 

Return Value:

name - the name assigned to the component definition if successful

Comments:

 

Example:

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

 
 

path

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

Syntax:

path = componentdefinition.path

Arguments:

 

Return Value:

path - a valid path if successful, false if unsuccessful

Comments:

Returns nil if it is an internal component.

Example:

path=Sketchup.find_support_file "BedTraditional.skp" ,"Components/Furniture/"
model = Sketchup.active_model
definitions = model.definitions
componentdefinition = definitions.load path
path = componentdefinition.path

 

save_thumbnail

The save_thumbnail method is used to save a thumbnail image to a file.

Syntax:

status = componentdefinition.save_thumbnail "filename"

Arguments:

"filename" - the name of the file, with extension, to save the thumbnail as

Return Value:

status - true if successful, false if unsuccessful

Comments:

Returns nil if it is an internal component.

Example:

path = Sketchup.find_support_file "fan.skp" ,"Components/Architecture_Sampler/"
model = Sketchup.active_model
definitions = model.definitions
componentdefinition = definitions.load path
status = componentdefinition.save_thumbnail "testthumbnail.jpg"
UI.messagebox status