Class: Sketchup::InstancePath

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/sketchup-api-stubs/stubs/Sketchup/InstancePath.rb

Overview

The InstancePath class represent the instance path to a given entity within the model hierarchy.

Version:

  • SketchUp 2017

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Sketchup::InstancePath

Examples:

model = Sketchup.active_model
group = model.entities.add_group
edge = group.entities.add_line([10, 10, 10], [20, 20, 20])
path = Sketchup::InstancePath.new([group, edge])

Parameters:

  • path (Array<Sketchup::Entity>)

    The leaf can be any entity, but the rest must be a group or component instance.

Raises:

  • (ArgumentError)

    if the instance path isn’t composed of instances and an optional leaf entity.

Version:

  • SketchUp 2017



137
138
# File 'lib/sketchup-api-stubs/stubs/Sketchup/InstancePath.rb', line 137

def initialize(path)
end

Instance Method Details

#==(other) ⇒ Boolean

Returns ‘true` if the instances paths represent the same set of entities.

Examples:

model = Sketchup.active_model
group = model.entities.add_group
edge = group.entities.add_line([10, 10, 10], [20, 20, 20])
path = Sketchup::InstancePath.new([group, edge])
if path.size > 1
  # do something
end

Returns:

  • (Boolean)

    ‘true` if the instances paths represent the same set of entities.

Version:

  • SketchUp 2017



30
31
# File 'lib/sketchup-api-stubs/stubs/Sketchup/InstancePath.rb', line 30

def ==(other)
end

#[](index) ⇒ Sketchup::Entity

Note:

This method does not accept negative indices. For the exact behavior of an array, use {#to_a}.

The elements of an instance path can be accessed similarly to an array.

Examples:

model = Sketchup.active_model
group = model.entities.add_group
edge = group.entities.add_line([10, 10, 10], [20, 20, 20])
path = Sketchup::InstancePath.new([group, edge])
path[0] == group # returns true
path[1] == edge # returns true

Parameters:

  • index (Integer)

Returns:

Raises:

  • (IndexError)

    if the given index is out of bounds

  • (TypeError)

    if the index is not of integer type

  • (TypeError)

    if the instance path refer to deleted entities.

Version:

  • SketchUp 2017



57
58
# File 'lib/sketchup-api-stubs/stubs/Sketchup/InstancePath.rb', line 57

def [](index)
end

#each {|Sketchup::Entity| ... } ⇒ nil

The yielded entities will start with the root and end with the leaf.

Examples:

model = Sketchup.active_model
group = model.entities.add_group
edge = group.entities.add_line([10, 10, 10], [20, 20, 20])
path = Sketchup::InstancePath.new([group, edge])
path.each { |entity|
  # do something
}

Yields:

Returns:

  • (nil)

Raises:

  • (TypeError)

    if the instance path refer to deleted entities.

Version:

  • SketchUp 2017



78
79
# File 'lib/sketchup-api-stubs/stubs/Sketchup/InstancePath.rb', line 78

def each
end

#empty?Boolean

Examples:

model = Sketchup.active_model
group = model.entities.add_group
edge = group.entities.add_line([10, 10, 10], [20, 20, 20])
path = Sketchup::InstancePath.new([group, edge])
if path.empty?
  # do something...
end

Returns:

  • (Boolean)

Raises:

  • (TypeError)

    if the instance path refer to deleted entities.

Version:

  • SketchUp 2017



96
97
# File 'lib/sketchup-api-stubs/stubs/Sketchup/InstancePath.rb', line 96

def empty?
end

#include?(object) ⇒ Boolean

Returns ‘true` if the instance path contain the given object.

Examples:

model = Sketchup.active_model
group = model.entities.add_group
edge = group.entities.add_line([10, 10, 10], [20, 20, 20])
path = Sketchup::InstancePath.new([group, edge])
if path.include?(edge)
  # do something...
end

Parameters:

  • object (Object)

Returns:

  • (Boolean)

Raises:

  • (TypeError)

    if the instance path refer to deleted entities.

Version:

  • SketchUp 2017



117
118
# File 'lib/sketchup-api-stubs/stubs/Sketchup/InstancePath.rb', line 117

def include?(object)
end

#leafSketchup::Entity

The leaf of an instance path is the last element which can be any entity that can be represented in the model. This is normally a Drawingelement, but could be a Vertex.

An instance can also be a leaf.

Examples:

model = Sketchup.active_model
group = model.entities.add_group
edge = group.entities.add_line([10, 10, 10], [20, 20, 20])
path = Sketchup::InstancePath.new([group, edge])
path.leaf == edge # returns true

Returns:

Raises:

  • (TypeError)

    if the instance path refer to deleted entities.

Version:

  • SketchUp 2017



158
159
# File 'lib/sketchup-api-stubs/stubs/Sketchup/InstancePath.rb', line 158

def leaf
end

#lengthInteger

#length is an alias of #size.

Examples:

model = Sketchup.active_model
group = model.entities.add_group
edge = group.entities.add_line([10, 10, 10], [20, 20, 20])
path = Sketchup::InstancePath.new([group, edge])
if path.length > 1
  # do something
end

Returns:

  • (Integer)

Raises:

  • (TypeError)

    if the instance path refer to deleted entities.

See Also:

Version:

  • SketchUp 2017



179
180
# File 'lib/sketchup-api-stubs/stubs/Sketchup/InstancePath.rb', line 179

def length
end

#persistent_id_pathString

The serialized version of an instance path is the persistent ids of its entities concatenated with a period.

Examples:

model = Sketchup.active_model
group = model.entities.add_group
edge = group.entities.add_line([10, 10, 10], [20, 20, 20])
path = Sketchup::InstancePath.new([group, edge])
pid_path = path.persistent_id_path # something like "342.345"

Returns:

Raises:

  • (TypeError)

    if the instance path refer to deleted entities.

See Also:

Version:

  • SketchUp 2017



199
200
# File 'lib/sketchup-api-stubs/stubs/Sketchup/InstancePath.rb', line 199

def persistent_id_path
end

#rootSketchup::Group, ...

The root of an instance path is the element located closest to the model root. This will be a group or component instance. If you have a non-instance as a leaf with no other parent component this will return ‘nil`.

Examples:

model = Sketchup.active_model
group = model.entities.add_group
edge = group.entities.add_line([10, 10, 10], [20, 20, 20])
path = Sketchup::InstancePath.new([group, edge])
path.root == group # returns true

Returns:

Raises:

  • (TypeError)

    if the instance path refer to deleted entities.

Version:

  • SketchUp 2017



218
219
# File 'lib/sketchup-api-stubs/stubs/Sketchup/InstancePath.rb', line 218

def root
end

#sizeInteger

Examples:

model = Sketchup.active_model
group = model.entities.add_group
edge = group.entities.add_line([10, 10, 10], [20, 20, 20])
path = Sketchup::InstancePath.new([group, edge])
if path.size > 1
  # do something
end

Returns:

  • (Integer)

Raises:

  • (TypeError)

    if the instance path refer to deleted entities.

See Also:

Version:

  • SketchUp 2017



238
239
# File 'lib/sketchup-api-stubs/stubs/Sketchup/InstancePath.rb', line 238

def size
end

#to_aArray

Returns an array representing the instance path.

Examples:

model = Sketchup.active_model
group = model.entities.add_group
edge = group.entities.add_line([10, 10, 10], [20, 20, 20])
path = Sketchup::InstancePath.new([group, edge])
pid_string = path.to_a.join('.')

Returns:

  • (Array)

    an array representing the instance path.

Raises:

  • (TypeError)

    if the instance path refer to deleted entities.

Version:

  • SketchUp 2017



254
255
# File 'lib/sketchup-api-stubs/stubs/Sketchup/InstancePath.rb', line 254

def to_a
end

#transformationGeom::Transformation #transformation(index) ⇒ Geom::Transformation

Examples:

model = Sketchup.active_model
group = model.entities.add_group
edge = group.entities.add_line([10, 10, 10], [20, 20, 20])
path = Sketchup::InstancePath.new([group, edge])
tr = path.transformation

Overloads:

  • #transformationGeom::Transformation

    Returns the combined transformation up to the the leaf entity.

    Returns:

  • #transformation(index) ⇒ Geom::Transformation

    Returns the combined transformation up to the the given index.

    Parameters:

    • index (Integer)

    Returns:

Raises:

  • (IndexError)

    if the given index is out of bounds

  • (TypeError)

    if the index is not of integer type

  • (TypeError)

    if the instance path refer to deleted entities.

Version:

  • SketchUp 2017



283
284
# File 'lib/sketchup-api-stubs/stubs/Sketchup/InstancePath.rb', line 283

def transformation(*args)
end

#valid?Boolean

An instance path is valid if it has at least one element and consist of groups and instances with exception of the leaf which can be any entity.

This method doesn’t check if the path can actually be looked up in the model.

Examples:

model = Sketchup.active_model
group = model.entities.add_group
edge = group.entities.add_line([10, 10, 10], [20, 20, 20])
path = Sketchup::InstancePath.new([group, edge])
if path.valid?
  # do something...
end

Returns:

  • (Boolean)

Version:

  • SketchUp 2017



303
304
# File 'lib/sketchup-api-stubs/stubs/Sketchup/InstancePath.rb', line 303

def valid?
end