SketchUp  Ruby API Reference 

Class Index

Method Index

Developers Guide

Examples

ComponentDefinition class

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.

Parent:Drawingelement

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

Example Code: cdtests.rb

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

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.

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

 

 



add_observer

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

Syntax

status = object.add_observer observer

Arguments

observer - an observer

Return Value

true if successful, false if unsuccessful.

Example

 

 


behavior

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

Syntax

behavior = componentdefinition.behavior

Return Value

behavior - a Behavior object if successful

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

Return Value

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

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

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

Return Value

status - the description if successful, false if unsuccessful

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

Return Value

entities - an Entities object if successful

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?

Return Value

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

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

Return Value

guid - a string guid if successful

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?

Return Value

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

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

Return Value

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

 

 


image?

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

Syntax

status = componentdefinition.image?

Return Value

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

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

Return Value

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

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?

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.

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

Return Value

name - the component definition's name if successful

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

Return Value

name - the name assigned to the component definition if successful

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

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

 

 



remove_observer

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

Syntax

status = object.remove_observer observer

Arguments

observer - an observer

Return Value

true if successful, false if unsuccessful.

Example

 

 


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