SketchUp  Ruby API Reference 

Class Index

Method Index

Developers Guide

Examples

Behavior class

The Behavior class is used to control the behavior of components. A behavior is accessed from a ComponentDefinition object.

Parent:Entity

Methods: always_face_camera= , always_face_camera? ,  cuts_opening=, cuts_opening?, is2d=, is2d? , set_shadows_face_sun= , shadows_face_sun?  , snapto, snapto=

Example Code: behaviortests.rb

Instance Methods


always_face_camera=

The always_face_camera= method is used to set the  always_face_camera behavior for a component.

Syntax

status = behavior.always_face_camera=true | false

Arguments

true – sets the always_face_camera behavior to true 

false – sets the always_face_camera behavior to false

Return Value

status – the status of the always_face_camera behavior if successful

Comments

If the always_face_camera behavior is true, a component will always try to orient itself so that the Y axis of the component is facing the camera.

Example

status = behavior.always_face_camera=false



if (status)

# if status is true, print the status

UI.messagebox status

else

# code to respond to always_face_camera being false

end

 

 


always_face_camera?

The always_face_camera? method is used to retrieve the  always_face_camera behavior for a component.

Syntax

behvior = behavior.always_face_camera?

Return Value

behavior - true if the component is set to always face the camera, false if the component is not set to always face camera.

Comments

If the always_face_camera behavior is true, then a component will always try to orient itself so that the -Y axis of the component is facing the camera.

Example

model = Sketchup.active_model
# Returns a DefintionList
definitions = model.definitions
path = Sketchup.find_support_file "BedTraditional.skp" ,"Components/Furniture/"
begin
definition = definitions.load path
rescue
UI.messagebox $!.message
end
behavior = definition.behavior
b = behavior.always_face_camera?
if (b)
UI.messagebox b
else
UI.messagebox "Always Face Camera is equal to false
end

status = behavior.always_face_camera = true
b = behavior.always_face_camera?
if (b)
UI.messagebox b
else
UI.messagebox "Failure"
end

 

 


cuts_opening=

The cuts_opening= method is used to set the cut opening behavior for a component.

Syntax

status = behavior.cuts_opening=true | false

Arguments

true – sets the cuts_opening behavior to true 

false – sets the cuts_opening behavior to false

Return Value

status – the status of the cuts_opening behavior (either true or false)

Example

status = behavior.cuts_opening=false

if (status)
# if status is true, print the status
UI.messagebox status
else
# code to respond cuts_opening being false
end

 

 


cuts_opening?

The cuts_opening? method is used to verify the status of a component’s cut opening behavior.

Syntax

status = behavior.cuts_opening?

Return Value

status – the status of the cuts_opening behavior (either true or false)

Example

staus=behavior.cuts_opening?

if (status)
#if status is true, do something
else
# if status is false, do something else
end

 

 


is2d=

The is2d= method is used to set the  2D behavior for a component: whether it can be glued or aligned to a face.

Syntax

status = behavior.is2d=true | false

Arguments

true – sets the 2D behavior to true 

false – sets the 2D behavior to false

Return Value

true – sets the 2D behavior to true 

false – sets the 2D behavior to false

Return Value

status – the status of the 2D behavior (either true or false)

Example

status = behavior.is2d=false

if (status)
# if status is true, print the status
UI.messagebox status
else
# code to respond is2d behavior being false
end

 

 


is2d?

The is2d? method is used to verify the status of a component’s 2D behavior.

Syntax

status = behavior.is2d?

Return Value

status – the status of the 2D behavior (either true or false)

Example

staus=behavior.is2d?

if (status)
#if status is true, do something
else
# if status is false, do something else
end

 

 


set_shadows_face_sun=

The shadows_face_sun= method is used to identify whether the component's shadow will be cast from the component's current position as though the component were facing the sun. See the Component entity within the SketchUp User's guide for more information on this feature.

Syntax

behavior = behavior.set_shadows_face_sun = status

Arguments

status - true if the component's is to be cast from the component's current position as though the component were facing the sun. False to cause the shadow to be cast from the component's current position

Return Value

behavior - the Behavior object

Example

behavior = behavior.shadows_face_sun= true

 

 


shadows_face_sun?

The shadows_face_sun? method is used to determine whether the component's shadow is being cast from the component's current position (as though the component were facing the sun). See the Component entity within the SketchUp User's guide for more information on this feature.

Syntax

status = behavior.shadows_face_sun?

Return Value

status - true if the component's is to be cast from the component's current position as though the component were facing the sun. False to cause the shadow to be cast from the component's current position.

Example

model = Sketchup.active_model
# Returns a DefintionList
definitions = model.definitions
path = Sketchup.find_support_file "fan.skp" ,"Components/Architecture_Sampler/"
begin
definition = definitions.load path
rescue
UI.messagebox $!.message
end behavior = definition.behavior
status = behavior.always_face_camera?
if (status)
UI.messagebox status
else
UI.messagebox "Always Face Camera is equal to false"
end
# Returns
behavior.always_face_camera = true
begin

s = behavior.shadows_face_sun?
rescue
UI.messagebox $!.message
end
if (s)
UI.messagebox s
else
UI.messagebox "Failure"
end

 

 


snapto

The snapto method is used to verify the status of a component’s "snap to" behavior.

Syntax

status = behavior.snapto

Return Value

status – the status of the snapto behavior (either true or false)

Comments

If the always_face_camera behavior is true, a component will always try to orient itself so that the Y axis of the component is facing the camera.

Example

staus=behavior.snapto?

if (status)
#if status is true, do something
else
# if status is false, do something else
end

 

 


snapto=

The is2d= method is used to set the snap to behavior for a component: whether it aligns (snaps) to a particular orientation.

Syntax

status = behavior.snapto=true | false

Arguments

true – sets the snapto behavior to true 

false – sets the snapto behavior to false

Return Value

status – the status of the snapto behavior (either true or false)

Example

status = behavior.snapto=false

if (status)
# if status is true, print the status
UI.messagebox status
else
# code to respond snapto behavior being false
end