Class: Sketchup::Behavior

Inherits:
Entity show all
Defined in:
lib/behavior.rb

Overview

The Behavior class is used to control the "behavior" of components, which roughly correlates to the series of options that you see in the Components dialog under the "edit" tab, such as whether it casts shadows, glues to walls, etc.

A Behavior object is accessed from a ComponentDefinition object, not created with a Behavior.new call.

Examples:

# Grab the Behavior object from the first component definition.
model = Sketchup.active_model
definition = model.definitions[0]
behavior = definition.behavior

See Also:

Since:

  • SketchUp 6.0

Instance Method Summary collapse

Methods inherited from Entity

#add_observer, #attribute_dictionaries, #attribute_dictionary, #delete_attribute, #deleted?, #entityID, #get_attribute, #model, #parent, #remove_observer, #set_attribute, #to_s, #typename, #valid?

Instance Method Details

#always_face_camera=(state) ⇒ Object

Set the always-face-camera behavior for a component.

Examples:

model = Sketchup.active_model
behavior = model.definitions[0].behavior
status = behavior.always_face_camera = false

Since:

  • SketchUp 6.0


33
34
# File 'lib/behavior.rb', line 33

def always_face_camera=(state)
end

#always_face_camera?Boolean

Determine if the always-face-camera behavior is enabled. 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.

Examples:

model = Sketchup.active_model
# Returns a DefinitionList
definitions = model.definitions
path = Sketchup.find_support_file "Bed.skp", "Components/Components Sampler/"

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

Since:

  • SketchUp 6.0


69
70
# File 'lib/behavior.rb', line 69

def always_face_camera?
end

#cuts_opening=(state) ⇒ Object

Set the cut-openings behavior for a component.

Examples:

model = Sketchup.active_model
behavior = model.definitions[0].behavior
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

Since:

  • SketchUp 6.0


89
90
# File 'lib/behavior.rb', line 89

def cuts_opening=(state)
end

#cuts_opening?Boolean

Determine if the cuts-openings behavior is set for a component.

Examples:

model = Sketchup.active_model
behavior = model.definitions[0].behavior
status = behavior.cuts_opening?
if (status)
  # if status is true, do something
else
  # if status is false, do something else
end

Since:

  • SketchUp 6.0


106
107
# File 'lib/behavior.rb', line 106

def cuts_opening?
end

#is2d=(state) ⇒ Object

Set the 2D behavior for a component: whether it can be glued or aligned to a face.

Examples:

model = Sketchup.active_model
behavior = model.definitions[0].behavior
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

Since:

  • SketchUp 6.0


127
128
# File 'lib/behavior.rb', line 127

def is2d=(state)
end

#is2d?Boolean

Determine if the 2D behavior is set: whether it can be glued or aligned to a face.

Examples:

model = Sketchup.active_model
behavior = model.definitions[0].behavior
status = behavior.is2d?
if (status)
  # if status is true, do something
else
  # if status is false, do something else
end

Since:

  • SketchUp 6.0


144
145
# File 'lib/behavior.rb', line 144

def is2d?
end

#no_scale_mask=(scale_mask) ⇒ Object

Note:

For 2-dimensional components (such as face-me components), not all of the handles in the list above are even used. Also, if the component you are modifying is already selected with the scale tool, then you or your user must deactivate and reactivate the scale tool for your new behavior to take effect.

Set an integer that is really a bit-by-bit description of which scale tool handles are hidden on a given component. This is useful for creating definitions that can only be scaled in particular ways. If a bit contains a 1, then a certain handle set will be hidden when the user selects the component and activates the Scale tool. Here is the map of which bits control which handles. Bit0: disable scale along red (X), Bit1: disable scale along green (Y), Bit2: disable scale along blue (Z), Bit3: disable scale in red/blue plane (X+Z), Bit4: disable scale in green/blue plane (Y+Z), Bit5: disable scale in red/green plane (X+Y), Bit6: disable scale uniform (from corners) (XYZ).

Examples:

# Disable the green and red-axes handles by setting bits 1 and 2 to 1.
definition = Sketchup.active_model.definitions[0]
behavior = definition.behavior
behavior.no_scale_mask = (1 << 1) + (1 << 2)

Since:

  • Sketchup 7.0


179
180
# File 'lib/behavior.rb', line 179

def no_scale_mask=(scale_mask)
end

#no_scale_mask?Fixnum

Get an integer that is a bit-by-bit description of which scale tool handles are hidden when the user selects this single component with the scale tool. See the #no_scale_mask= method for details on the bit encodings used.

Examples:

definition = Sketchup.active_model.definitions[0]
behavior = definition.behavior
no_scale_mask = behavior.no_scale_mask?

Since:

  • Sketchup 7.0


196
197
# File 'lib/behavior.rb', line 196

def no_scale_mask?
end

#shadows_face_sun=(status) ⇒ Object

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.

Examples:

model = Sketchup.active_model
behavior = model.definitions[0].behavior
behavior.shadows_face_sun = true

Since:

  • SketchUp 6.0


215
216
# File 'lib/behavior.rb', line 215

def shadows_face_sun=(status)
end

#shadows_face_sun?Boolean

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.

Examples:

model = Sketchup.active_model
behavior = model.definitions[0].behavior
status = behavior.shadows_face_sun?

Since:

  • SketchUp 6.0


232
233
# File 'lib/behavior.rb', line 232

def shadows_face_sun?
end

#snaptoFixnum

Get components "snap to" behavior. Returns a constant indicating the snapping behavior of the component described by behavior. Snapping behavior is how the x-y plane of a component instance will be snapped against a face. Possible values are: SnapTo_Arbitrary (0) => Snap to any arbitrary face. SnapTo_Horizontal (1) => Snap to horizontal face like floors. SnapTo_Vertical (2) => Snap to vertical face like walls. SnapTo_Sloped (3) => Snap to sloped face like sloping roofs.

Examples:

model = Sketchup.active_model
behavior = model.definitions[0].behavior
status = behavior.snapto
if (status)
  # if status is true, do something
else
  # if status is false, do something else
end

Since:

  • SketchUp 6.0


255
256
# File 'lib/behavior.rb', line 255

def snapto
end

#snapto=(type) ⇒ Object

Set components "snap to" behavior. Snapping behavior is how the x-y plane of a component instance will be snapped against a face. Possible constant values are: SnapTo_Arbitrary (0) => Snap to any arbitrary face. SnapTo_Horizontal (1) => Snap to horizontal face like floors. SnapTo_Vertical (2) => Snap to vertical face like walls. SnapTo_Sloped (3) => Snap to sloped face like sloping roofs.

Examples:

model = Sketchup.active_model
behavior = model.definitions[0].behavior
behavior.snapto = SnapTo_Horizontal

Since:

  • SketchUp 6.0


274
275
# File 'lib/behavior.rb', line 274

def snapto=(type)
end