|
SketchUp Ruby API Reference |
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
The always_face_camera= method is used to set the always_face_camera behavior for a component.
status = behavior.always_face_camera=true | false
true – sets the always_face_camera behavior to true
false – sets the always_face_camera behavior to false
status – the status of the always_face_camera behavior if successful
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.
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
The always_face_camera? method is used to retrieve the always_face_camera behavior for a component.
behvior = behavior.always_face_camera?
behavior - true if the component is set to always face the camera, false if the component is not set to always face camera.
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.
model = Sketchup.active_model# Returns a DefintionListdefinitions = model.definitionspath = Sketchup.find_support_file "BedTraditional.skp" ,"Components/Furniture/"begindefinition = definitions.load pathrescueUI.messagebox $!.messageendbehavior = definition.behaviorb = behavior.always_face_camera?if (b)UI.messagebox belseUI.messagebox "Always Face Camera is equal to falseendstatus = behavior.always_face_camera = trueb = behavior.always_face_camera?if (b)UI.messagebox belseUI.messagebox "Failure"end
The cuts_opening= method is used to set the cut opening behavior for a component.
status = behavior.cuts_opening=true | false
true – sets the cuts_opening behavior to true
false – sets the cuts_opening behavior to false
status – the status of the cuts_opening behavior (either true or false)
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
The cuts_opening? method is used to verify the status of a component’s cut opening behavior.
status = behavior.cuts_opening?
status – the status of the cuts_opening behavior (either true or false)
staus=behavior.cuts_opening?
if (status)
#if status is true, do something
else
# if status is false, do something else
end
The is2d= method is used to set the 2D behavior for a component: whether it can be glued or aligned to a face.
status = behavior.is2d=true | false
true – sets the 2D behavior to true
false – sets the 2D behavior to false
true – sets the 2D behavior to true
false – sets the 2D behavior to false
status – the status of the 2D behavior (either true or false)
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
The is2d? method is used to verify the status of a component’s 2D behavior.
status = behavior.is2d?
status – the status of the 2D behavior (either true or false)
staus=behavior.is2d?
if (status)
#if status is true, do something
else
# if status is false, do something else
end
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.
behavior = behavior.set_shadows_face_sun = status
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
behavior - the Behavior object
behavior = behavior.shadows_face_sun= true
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.
status = behavior.shadows_face_sun?
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.
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
The snapto method is used to verify the status of a component’s "snap to" behavior.
status = behavior.snapto
status – the status of the snapto behavior (either true or false)
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.
staus=behavior.snapto?
if (status)
#if status is true, do something
else
# if status is false, do something else
end
The is2d= method is used to set the snap to behavior for a component: whether it aligns (snaps) to a particular orientation.
status = behavior.snapto=true | false
true – sets the snapto behavior to true
false – sets the snapto behavior to false
status – the status of the snapto behavior (either true or false)
status = behavior.snapto=falseif (status)# if status is true, print the statusUI.messagebox statuselse# code to respond snapto behavior being falseend