Class: Sketchup::PickHelper

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

Overview

The PickHelper class is used to pick entities that reside under the current cursor location. PickHelper and InputPoint are similar, but InputPoint also uses inferencing. You can retrieve a PickHelper object using the pick_helper method on a View object.

Entities that are picked (found under the cursor when a mouse or keyboard event occurs), are called Pick Records and are placed in an indexed list.

Version:

  • SketchUp 6.0

Constant Summary collapse

PICK_CROSSING =

Constants

nil
PICK_INSIDE =

Stub value.

nil

Instance Method Summary collapse

Instance Method Details

#all_pickedObject

The all_picked method is used to get an array of entities from the active entities from all the pick paths. Duplicates might occur if there are multiple pick paths for entities that ends in a group or component.

For example, if the pick hits at the border of an edge and face inside a group there will be two pick paths - one for the face and one for the edge. Since this method returns entities from the active entities it would return an array with the group two times.

Examples:

ph = view.pick_helper
ph.do_pick(x, y)
entities = ph.all_picked

Returns:

  • elements - the array of elements in the pick.

Version:

  • SketchUp 6.0



41
42
# File 'lib/sketchup-api-stubs/stubs/Sketchup/PickHelper.rb', line 41

def all_picked
end

#best_pickedObject

The best_picked method is used to retrieve the “best” entity picked (entity that you would have picked if you were using the select tool).

Returns nil if nothing was picked. You must have called do_pick before calling this method.

Examples:

ph = view.pick_helper
ph.do_pick(x, y)
best_entity = ph.best_picked

Returns:

  • entity - the best picked entity

Version:

  • SketchUp 6.0



58
59
# File 'lib/sketchup-api-stubs/stubs/Sketchup/PickHelper.rb', line 58

def best_picked
end

#boundingbox_pick(bounding_box, pick_type, transformation = IDENTITY) ⇒ Object

Used to pick a set of entities from a model from a BoundingBox. The pick criteria can be for completely-contained or partially-contained entities, similar to how the Selection tool works.

Examples:

boundingbox = Geom::BoundingBox.new
boundingbox.add([1, 1, 1], [100, 100, 100])
ph = Sketchup.active_model.active_view.pick_helper

# Rotate the box 45' around the z-axis
angle = 45
transformation = Geom::Transformation.new(ORIGIN, Z_AXIS, angle)

num_picked = ph.boundingbox_pick(boundingbox, Sketchup::PickHelper::PICK_CROSSING, transformation)
if num_picked > 0
  Sketchup.active_model.selection.add(ph.all_picked)
end

Parameters:

  • bounding_box

    BoundingBox object defining the volume to use for picking

  • pick_type

    PICK_INSIDE to select entities completely contained or PICK_CROSSING to select entities partially contained.

  • transformation (optional) (defaults to: IDENTITY)

    Transformation that will be applied to the volume defined by the BoundingBox that allows for a rotation.

Returns:

  • The number of Entity objects picked

Version:

  • SketchUp 2016



94
95
# File 'lib/sketchup-api-stubs/stubs/Sketchup/PickHelper.rb', line 94

def boundingbox_pick(bounding_box, pick_type, transformation = IDENTITY)
end

#countObject

The count method is used to count the number of entities picked (number of pick records)

Examples:

number = pickhelper.count

Returns:

  • number - the number of entities picked

Version:

  • SketchUp 6.0



106
107
# File 'lib/sketchup-api-stubs/stubs/Sketchup/PickHelper.rb', line 106

def count
end

#depth_at(index) ⇒ Object

The depth_at method retrieves the depth of one of the currently picked entities in the list of pick records.

Examples:

ph = view.pick_helper
ph.do_pick(x, y)
# Iterate all pick-routes:
pickhelper.count.times { |pick_path_index|
  puts pickhelper.depth_at(pick_path_index)
}

Parameters:

  • index

    A number from 0 to number of items picked minus one.

Returns:

  • integer - the depth of the entity if successful

Version:

  • SketchUp 6.0



126
127
# File 'lib/sketchup-api-stubs/stubs/Sketchup/PickHelper.rb', line 126

def depth_at(index)
end

#do_pick(x, y, aperture = 0) ⇒ Object

The do_pick method is used to perform the initial pick. This method is generally called before any other methods in the PickHelper class.

Returns the number of entities picked. The x and y values are the screen coordinates of the point at which would want to do a pick.

Examples:

ph = view.pick_helpernum = ph.do_pick(x, y)

Parameters:

  • x

    X screen coordinate for the pick.

  • y

    Y screen coordinate for the pick.

  • aperture (defaults to: 0)

    The size of the pick-aperture.

Returns:

  • Integer - The number of Entity objects picked

Version:

  • SketchUp 6.0



150
151
# File 'lib/sketchup-api-stubs/stubs/Sketchup/PickHelper.rb', line 150

def do_pick(x, y, aperture = 0)
end

#element_at(index) ⇒ Object

The element_at method is used to retrieve a specific entity in the list of picked elements. This element will be from the active entities.

Use count() to get the number of possible pick paths.

Examples:

ph = view.pick_helper
ph.do_pick(x, y)
# Iterate all pick-routes:
pickhelper.count.times { |pick_path_index|
  puts pickhelper.element_at(pick_path_index)
}
# You would iterate the same elements in all_picked.

Parameters:

  • index

    A number from 0 to number of items picked minus one.

Returns:

  • entity - the entity at the index position in the list of picked entities.

Version:

  • SketchUp 6.0



174
175
# File 'lib/sketchup-api-stubs/stubs/Sketchup/PickHelper.rb', line 174

def element_at(index)
end

#init(x, y, aperture = 0) ⇒ PickHelper

The #init method is used to initialize the PickHelper for testing points.

You do not normally need to call this method, but you can use this if you want to call #test_point or #pick_segment on a lot of points.

If the optional aperture is given, it is given in pixels.

Examples:

ph = view.pick_helper
ph.init(x, y, 5)
# Find all points picked by the screen click.
selected = points.select { |point|
  ph.test_point(point)
}

Parameters:

  • x (Integer)

    X screen coordinate for the pick.

  • y (Integer)

    Y screen coordinate for the pick.

  • aperture (Integer) (defaults to: 0)

    aperture in pixels.

Returns:

Version:

  • SketchUp 6.0



204
205
# File 'lib/sketchup-api-stubs/stubs/Sketchup/PickHelper.rb', line 204

def init(x, y, aperture = 0)
end

#leaf_at(index) ⇒ Object

The leaf_at method retrieves the deepest thing in a pick path.

For example, if you have a face that is within a component that is within another component, leaf_at returns the face.

Use count() to get the number of possible pick paths.

Examples:

ph = view.pick_helper
ph.do_pick(x, y)
# Iterate all pick-routes:
pickhelper.count.times { |pick_path_index|
  p pickhelper.leaf_at(pick_path_index)
}

Parameters:

  • index

    A number from 0 to number of items picked minus one.

Returns:

  • entity - the leaf entity

Version:

  • SketchUp 6.0



228
229
# File 'lib/sketchup-api-stubs/stubs/Sketchup/PickHelper.rb', line 228

def leaf_at(index)
end

#path_at(index) ⇒ Object

The path_at method is used to retrieve the entire path for an entity in the pick list (as an array).

If one of the pick paths end in a face nested in a group nested in a component this method will return an array of these entities. The Group will be first and the face will be last.

The first item in the array will be from the active entities and the last item will be a drawing element that is not a group, component or image.

Examples:

ph = view.pick_helper
ph.do_pick(x, y)
# Iterate all pick-routes:
pickhelper.count.times { |pick_path_index|
  p pickhelper.path_at(pick_path_index)
}

Parameters:

  • index

    A number from 0 to number of items picked minus one.

Returns:

  • array - an array of entities including the leaf

Version:

  • SketchUp 6.0



255
256
# File 'lib/sketchup-api-stubs/stubs/Sketchup/PickHelper.rb', line 255

def path_at(index)
end

#pick_segment(points) ⇒ Integer, false #pick_segment(points, x, y, aperture = 0) ⇒ Integer, false

Note:

The return value will be a negative index when a segment is picked.

The #pick_segment method is used to pick a segment of a polyline curve that is defined by an array of points.

If you click on a point in a polyline curve, the index of the point in the curve is returned (starting at 0).

If you click on a segment in the polyline curve, the index of the segment is returned. Segments are returned by negative indicies and start at index -1 (for the segment connecting the first two points) and increase by a factor of -1 (for example, the segment connecting second and third point is -2).

There is no need to invoke #do_pick for this and the results are unrelated.

Examples:

point1 = Geom::Point3d.new(0 ,0, 0)
point2 = Geom::Point3d.new(10, 0, 0)
segment = [point1, point2]
ph = view.pick_helper
# If testing many points this is the fastest way to test.
ph.init(x, y)
picked = ph.pick_segment(segment)
# This do not require .init
picked = ph.pick_segment(segment, x, y)

Overloads:

  • #pick_segment(points) ⇒ Integer, false

    This is more efficient if you need to test a number of segments for the same set of screen coordinates. But then you must use #init first.

    Parameters:

    • points (Array<Geom::Point3d>)

      A series of points in the polyline as a list of parameters or an array containing Point3d objects.

    Returns:

    • (Integer, false)

      an index on success, false on failure

  • #pick_segment(points, x, y, aperture = 0) ⇒ Integer, false

    Returns an index on success, false on failure.

    Parameters:

    • points (Array<Geom::Point3d>)

      A series of points in the polyline as a list of parameters or an array containing Point3d objects.

    • x (Integer)

      screen mouse position in pixels.

    • y (Integer)

      (required if x given) screen mouse position in pixels.

    • aperture (defaults to: 0)

      aperture in pixels.

    Returns:

    • (Integer, false)

      an index on success, false on failure

Version:

  • SketchUp 6.0



305
306
# File 'lib/sketchup-api-stubs/stubs/Sketchup/PickHelper.rb', line 305

def pick_segment(*args)
end

#picked_edgeObject

The picked_edge method is used to retrieve the “best” Edge picked.

Returns nil if there were no edges picked. You must have called do_pick before calling this method.

Examples:

ph = view.pick_helper
ph.do_pick(x, y)
edge = ph.picked_edge

Returns:

  • edge - an Edge object if successful

Version:

  • SketchUp 6.0



321
322
# File 'lib/sketchup-api-stubs/stubs/Sketchup/PickHelper.rb', line 321

def picked_edge
end

#picked_element(index) ⇒ Object

The picked_element method retrieves the best drawing element, that is not an edge or a face, picked.

Returns nil if nothing was picked. You must have called do_pick before calling this method.

Examples:

ph = view.pick_helper
ph.do_pick(x, y)
entity = ph.picked_element

Parameters:

  • index

Returns:

  • element - a drawing element that is not an edge or face if successful

Version:

  • SketchUp 6.0



341
342
# File 'lib/sketchup-api-stubs/stubs/Sketchup/PickHelper.rb', line 341

def picked_element(index)
end

#picked_faceObject

The picked_face method is used to retrieve the best face picked.

Returns nil if there were no faces picked. You must have called do_pick before calling this method.

Examples:

ph = view.pick_helper
ph.do_pick(x, y)
face = ph.picked_face

Returns:

  • face - a Face object if successful

Version:

  • SketchUp 6.0



357
358
# File 'lib/sketchup-api-stubs/stubs/Sketchup/PickHelper.rb', line 357

def picked_face
end

#test_point(point) ⇒ Boolean #test_point(point, x, y, aperture = 0) ⇒ Boolean

The #test_point method is used to test a point to see if it would be selected using the default or given pick aperture.

There is no need to invoke #do_pick for this and the results are unrelated.

Examples:

ph = view.pick_helper
# If testing many points this is the fastest way to test.
ph.init(x, y)
picked = ph.test_point(point)
# These do not require init()
picked = ph.test_point(point, x, y)
picked = ph.test_point(point, x, y, aperture)

Overloads:

  • #test_point(point) ⇒ Boolean

    This is more efficient if you want to test a lot of points using the same screen point. But you must have called the #init method first for this to work.

    Parameters:

  • #test_point(point, x, y, aperture = 0) ⇒ Boolean

    Parameters:

    • point (Geom::Point3d)
    • x (Integer)
    • y (Integer)
    • aperture (Integer) (defaults to: 0)

Returns:

  • (Boolean)

Version:

  • SketchUp 6.0



391
392
# File 'lib/sketchup-api-stubs/stubs/Sketchup/PickHelper.rb', line 391

def test_point(*args)
end

#transformation_at(index) ⇒ Object

The transformation_at method is used to get a transformation at a specific pick path index in the pick helper.

The transformation combines the transformation of all groups, components and images in the pick path. This transformation can be used to transform the coordinates of the leaf entity into the coordinates of the active entities.

Examples:

ph = view.pick_helper
ph.do_pick(x, y)
# Iterate all pick-routes:
pickhelper.count.times { |pick_path_index|
  puts pickhelper.transformation_at(pick_path_index)
}

Parameters:

  • index

    The index where the transformation should be retrieved.

Returns:

  • transformation - the transformation found

Version:

  • SketchUp 6.0



415
416
# File 'lib/sketchup-api-stubs/stubs/Sketchup/PickHelper.rb', line 415

def transformation_at(index)
end

#viewObject

The view method is used to get the view associated with the PickHelper.

Examples:

view = pickhelper.view

Returns:

  • view - the associated view

Version:

  • SketchUp 6.0



426
427
# File 'lib/sketchup-api-stubs/stubs/Sketchup/PickHelper.rb', line 426

def view
end

#window_pick(start_point, end_point, pick_type) ⇒ Object

Used to pick a set of entities from a model based on a screen coordinate rectangular area defined by two points. The pick criteria can be for completely-contained or partially-contained entities, similar to how the Selection tool works. The z value of the points passed in are ignored.

Examples:

ph = Sketchup.active_model.active_view.pick_helper
start_point = Geom::Point3d.new(100, 100, 0)
end_point = Geom::Point3d.new(500, 500, 0)
num_picked = ph.window_pick(start_point, end_point, Sketchup::PickHelper::PICK_CROSSING)

Parameters:

  • start_point

    First screen coordinate point.

  • end_point

    Second screen coordinate point.

  • pick_type

    PICK_INSIDE to select entities completely contained or PICK_CROSSING to select entities partially contained.

Returns:

  • The number of Entity objects picked

Version:

  • SketchUp 2016



453
454
# File 'lib/sketchup-api-stubs/stubs/Sketchup/PickHelper.rb', line 453

def window_pick(start_point, end_point, pick_type)
end