123456789_123456789_123456789_123456789_123456789_

Class: Sketchup::Snap

Relationships
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: Sketchup::Drawingelement

Overview

A Snap is a custom grip used by SketchUp’s Move tool. Snaps can be added at strategic places such as connectors to help assembling objects.

#direction is the direction a snap is “pointing”. This can be thought of as the normal direction of the snap. It can also be thought of as the direction you move an object when plugging it into another object, e.g. inserting a power coord.

#up controls the rotation around the Snap’s axis.

When two objects are snapped together, the Snaps have opposite #direction vectors but matching #up vectors.

Examples:

# Copy all snaps from source group/component to the corresponding
# location in a target group/component, as if the objects have
# have been snapped together.
#
# @param [Sketchup::Group, Sketchup::ComponentInstance] source
# @param [Sketchup::Group, Sketchup::ComponentInstance] target
def copy_snap(source, target)
  # Transformation for going from the coordinate system of the source to
  # that of the target.
  transformation =
    target.transformation.inverse * source.transformation

  source.definition.entities.grep(Sketchup::Snap) do |source_snap|
    # Transform position and orientation between local coordinate systems.
    position = source_snap.position.transform(transformation)
    # Direction vector is reversed between two connected snaps;
    # the snaps point "into" each other.
    direction = source_snap.direction.transform(transformation).reverse
    # Up vector is aligned between two connected snaps.
    up = source_snap.up.transform(transformation)

    target.entities.add_snap(position, direction, up)
  end
end

Version:

  • SketchUp 2025.0

Instance Attribute Summary

Drawingelement - Inherited

#casts_shadows=

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

#casts_shadows?

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

#hidden=

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

#hidden?

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

#layer

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

#layer=

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

#material

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

#material=

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

#receives_shadows=

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

#receives_shadows?

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

#visible=

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

#visible?

The #visible? method checks if a Drawingelement object is not explicitly hidden (i.e. its hidden property is false).

Entity - Inherited

#deleted?

The deleted? method is used to determine if your entity is still valid (not deleted by another script, for example.).

#valid?

The #valid? method is used to determine if your entity is still valid (not deleted by another script, for example).

Instance Method Summary

Drawingelement - Inherited

#bounds

The #bounds method is used to retrieve the ::Geom::BoundingBox bounding a Drawingelement.

#erase!

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

Entity - Inherited

#add_observer

The add_observer method is used to add an observer to the current object.

#attribute_dictionaries

The attribute_dictionaries method is used to retrieve the AttributeDictionaries collection attached to the entity.

#attribute_dictionary

The attribute_dictionary method is used to retrieve an attribute dictionary with a given name that is attached to an Entity.

#delete_attribute

The #delete_attribute method is used to delete an attribute from an entity.

#entityID

The entityID method is used to retrieve a unique ID assigned to an entity.

#get_attribute

The #get_attribute method is used to retrieve the value of an attribute in the entity’s attribute dictionary.

#inspect

The #inspect method is used to retrieve the string representation of the entity.

#model

The model method is used to retrieve the model for the entity.

#parent

The parent method is used to retrieve the parent of the entity.

#persistent_id

The #persistent_id method is used to retrieve a unique persistent id assigned to an entity.

#remove_observer

The remove_observer method is used to remove an observer from the current object.

#set_attribute

The set attribute is used to set the value of an attribute in an attribute dictionary with the given name.

#to_s

The #to_s method is used to retrieve the string representation of the entity.

#typename

The typename method retrieves the type of the entity, which will be a string such as “Face”, “Edge”, or “Group”.

Instance Method Details

#directionGeom::Vector3d

The #direction method is used to get the direction this Snap is “pointing”.

When two Snaps are snapped into each other, they have the opposite #direction.

Examples:

snap = Sketchup.active_model.entities.add_snap(ORIGIN)
direction = snap.direction

Version:

  • SketchUp 2025.0

#positionGeom::Point3d

The #position method is used to get the position of this Snap.

Examples:

snap = Sketchup.active_model.entities.add_snap(ORIGIN)
position = snap.position

Version:

  • SketchUp 2025.0

#set(position) ⇒ Snap #set(position, direction) ⇒ Snap #set(position, direction, up) ⇒ Snap

The #set method is used to move and/or reorient a Snap.

Examples:

snap = Sketchup.active_model.entities.add_snap(ORIGIN)
snap.set(Geom::Point3d.new(1.m, 0, 0))

Overloads:

  • #set(position) ⇒ Snap

    With only a position provided, the Snap keeps its current orientation.

    Parameters:

  • #set(position, direction) ⇒ Snap

    With a position and a direction vector provided, but no up vector, SketchUp tries to keep the Snap upright.

    Parameters:

  • #set(position, direction, up) ⇒ Snap

    Parameters:

Returns:

  • (Snap)

    self

Raises:

Version:

  • SketchUp 2025.0

#upGeom::Vector3d

The #up method is used to get a vector representing the rotation of this Snap along its axis.

When two Snaps are snapped into each other, they have the same aligned #up direction.

Examples:

snap = Sketchup.active_model.entities.add_snap(ORIGIN)
up = snap.up

Version:

  • SketchUp 2025.0