SketchUp  Ruby API Reference 

Class Index

Method Index

Developers Guide

Examples

Drawingelement class

Drawingelement is a base class for an item in the model that can be displayed. These items include edges, contruction points, construction lines, and images. Arc curves and arcs are not included because they are not drawing elements by themselves, but are a composition of edges. 

Parent:Entity

Methods: bounds, cast_shadows= , cast_shadows?, erase! ,hidden= ,hidden?, layer, layer=, material, material=, receive_shadows=, receive_shadows? , visible=, visible?

Example Code: drawingelementtests.rb

Instance Methods


bounds

The bounds method is used to retrieve the bounding box for an drawing element.

Syntax

boundingbox = drawingelement.bounds

Return Value

boundingbox - A BoundingBox object if successful

Example

depth = 100
width = 100
model = Sketchup.active_model
entities = model.active_entities
pts = []
pts[0] = [0, 0, 0]
pts[1] = [width, 0, 0]
pts[2] = [width, depth, 0]
pts[3] = [0, depth, 0]
# Add the face to the entities in the model
face = entities.add_face pts
# Remember, anything that can be displayed, such as a face, is also
# a DrawingElement. So, I can call bounds on a face and because face
# sub-classes DrawingElement.
boundingbox = face.bounds

 

 


cast_shadows=

The cast_shadows= method is used to set the Drawingelement to cast shadows.

Syntax

status = cast_shadows= true | false

Arguments

true | false - true if you want the Drawingelement object to cast shadows, false if you do not want the Drawingelement object to cast shadows.

Return Value

status - true if successful, false if unsuccessful.

Example

 

 

 


cast_shadows?

The cast_shadows? method is used to determine if the Drawingelement is casting shadows.

Syntax

status = cast_shadows?

 

Return Value

status - true if the Drawingelement is casting shadows, false if unsuccessful.

Example

 

 

 


erase!

The erase! method is used to erase an element from the model.

Syntax

status = drawingelement.erase!

Return Value

status - true if successful, false if unsuccessful

Comments

Erasing an Edge also erases all of the Face objects that use the Edge.

Example

depth = 100
width = 100
model = Sketchup.active_model
entities = model.active_entities
pts = []
pts[0] = [0, 0, 0]
pts[1] = [width, 0, 0]
pts[2] = [width, depth, 0]
pts[3] = [0, depth, 0]
# Add the face to the entities in the model
face = entities.add_face pts
status = face.erase!

 

 


hidden=

The hidden= method is used to set the hidden status for an element.

Syntax

status = drawingelement.hidden = true | false

Arguments

true | false - true if you want to hide the element, false if you do not want to hide the element

Return Value

status - true if the element has been hidden, false if the element has not been hidden.

Example

depth = 100
width = 100
model = Sketchup.active_model
entities = model.active_entities
pts = []
pts[0] = [0, 0, 0]
pts[1] = [width, 0, 0]
pts[2] = [width, depth, 0]
pts[3] = [0, depth, 0]
# Add the face to the entities in the model
face = entities.add_face pts
UI.messagebox "Click OK to Hide the Box"        
status = face.hidden=true

 

 


hidden?

The hidden? method is used to determine if the element is hidden.

Syntax

status = drawingelement.hidden?

Return Value

status -true if hidden, false if not hidden

Comments

Hidden elements are still in the model, but they are not displayed.

Example

depth = 100
width = 100
model = Sketchup.active_model
entities = model.active_entities
pts = []
pts[0] = [0, 0, 0]
pts[1] = [width, 0, 0]
pts[2] = [width, depth, 0]
pts[3] = [0, depth, 0]
# Add the face to the entities in the model
face = entities.add_face pts        
status = face.hidden?

 

 


layer

The layer method is used to retrieve the Layer object of the drawing element.

Syntax

layer = drawingelement.layer

Return Value

layer - a layer object if successful

Example

depth = 100
width = 100
model = Sketchup.active_model
entities = model.active_entities
pts = []
pts[0] = [0, 0, 0]
pts[1] = [width, 0, 0]
pts[2] = [width, depth, 0]
pts[3] = [0, depth, 0]
# Add the face to the entities in the model
face = entities.add_face pts  
layer = face.layer      

 

 


layer=

The layer= method is used to set the layer for the drawing element.

Syntax

layer = drawingelement.layer = layer | "layername"

Arguments

layer - a layer number 

layername - a layer name

Return Value

layer - the new Layer object if successful

Comments

An exception is raised if you give a string that doesn't match any layer name.

Example

depth = 100
width = 100
model = Sketchup.active_model
entities = model.active_entities
pts = []
pts[0] = [0, 0, 0]
pts[1] = [width, 0, 0]
pts[2] = [width, depth, 0]
pts[3] = [0, depth, 0]
# Add the face to the entities in the model
face = entities.add_face pts  
# Add a layer
layer = layers.add "joe"
# Put the face on the joe layer (instead of layer 0)
newlayer = face.layer=layer
     

 

 


material

The material method is used to retrieve the material for the drawing element.

Syntax

material = drawingelement.material

Return Value

material - the Material object if successful

Example

depth = 100
width = 100
model = Sketchup.active_model
entities = model.active_entities
pts = []
pts[0] = [0, 0, 0]
pts[1] = [width, 0, 0]
pts[2] = [width, depth, 0]
pts[3] = [0, depth, 0]
# Add the face to the entities in the model
face = entities.add_face pts  
material = face.material

 

 


material=

The material= method is used to set the material for the drawing element.

Syntax

material = drawingelement.material = material | "materialname" | color | "colorname"

Arguments

material - a material object 

materialname - the name of a material

color - a color object

colorname - the name of a color

Return Value

material - the new Material object if successful

Example

depth = 100
width = 100
model = Sketchup.active_model
entities = model.active_entities
pts = []
pts[0] = [0, 0, 0]
pts[1] = [width, 0, 0]
pts[2] = [width, depth, 0]
pts[3] = [0, depth, 0]
# Add the face to the entities in the model
face = entities.add_face pts  
m = materials.add "Joe"
begin
# Returns nil if not successful, path if successful. Should return a texture object
m.texture="c:\\Program Files\\@Last Software\\SketchUp 4\\Materials\\Carpet.jpg"
rescue
UI.messagebox $!.message
end
# You will see the material applied when you reverse the box's faces
material = face.material=m

 

 


receive_shadows= 

The receive_shadows= method is used to set the Drawingelement to receive shadows.

Syntax

status = receive_shadows= true | false

Arguments

true | false - true if you want the Drawingelement object to receive shadows, false if you do not want the Drawingelement object to receive shadows.

Return Value

status - true if successful, false if unsuccessful.

Example

 

 

 


receive_shadows?

The receive_shadows? method is used to determine if the Drawingelement is receiving shadows.

Syntax

status = receive_shadows?

 

Return Value

status - true if the Drawingelement is receiving shadows, false if unsuccessful.

Example

 

 

 

visible=

The visible= method is used to set the visible status for an element. This method performs an opposite function to the hidden= method.

Syntax

status = drawingelement.visible = true | false

Arguments

true | false - true if you want to hide the element, false if you do not want to hide the element

Return Value

status - true if the element has been hidden, false if the element has not been hidden.

Example

depth = 100
width = 100
model = Sketchup.active_model
entities = model.active_entities
pts = []
pts[0] = [0, 0, 0]
pts[1] = [width, 0, 0]
pts[2] = [width, depth, 0]
pts[3] = [0, depth, 0]
# Add the face to the entities in the model
face = entities.add_face pts  
UI.messagebox "Click OK to Hide the Box"        
status = face.visible=false

 

 

visible?

The visible? method is used to determine if the element is visible. This method performs an opposite function to the hidden? method.

Syntax

status = drawingelement.visible?

Return Value

status - true if hidden, false if not hidden

Example

depth = 100
width = 100
model = Sketchup.active_model
entities = model.active_entities
pts = []
pts[0] = [0, 0, 0]
pts[1] = [width, 0, 0]
pts[2] = [width, depth, 0]
pts[3] = [0, depth, 0]
# Add the face to the entities in the model
face = entities.add_face pts  
status = face.visible?