Behavior

class Behavior

Parent: Entity | Class Index
Methods:always_face_camera=, always_face_camera?, cuts_opening=, cuts_opening?, is2d=, is2d?, snapto, snapto= |
Sample Code: behaviortests.rb |

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

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?
Arguments:
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)
Comments:
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?
Arguments:
Return Value:
status – the status of the cuts_opening behavior (either true or false)
Comments:
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:
status – the status of the 2D behavior (either true or false)
Comments:
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?
Arguments:
Return Value:
status – the status of the 2D behavior (either true or false)
Comments:
Example:

staus=behavior.is2d?

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

snapto
The snapto method is used to verify the status of a component’s "snap to" behavior.
Syntax:
status = behavior.snapto
Arguments:
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)
Comments:
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