Get Landing Face the component lays on


#1

I’m trying to figure out how we can get the landing Face that the user places the new component on.
For my example (please see the pic), the user will use Move/Placing control to place the component at the midpoint of the square desk’s face. I can use onPlaceComponent to trigger and get the Component Instance. However, I don’t know how to get the landing Face.

If anyone knows a solution, please let me know. Thanks in advanced.


#2

Set snapto for behavior and use component.glued_to to retrieve the entity that this instance is glued to.
But, I like the model.raytest method :wink:


#3

I used model.raytest in my plugin


#4

@voquochai Could you give me the code example?

I tried to use snapto and glued_to, but it doesn’t work for me.

def onPlaceComponent(instance)

   behavior = instance.definition.behavior
   behavior.snapto = SnapTo_Arbitrary
   placement_face = instance.glued_to
   puts "Placement Face: #{placement_face}"

end

Also, your demo is quite similar as the thing I’m trying to do, I want to make the new component can be rotated automatically based on the landing face. If you could share a bit how you did it, that’d be great!


#5

You can use either Sketchup::InputPoint or Sketchup::PickHelper. The former uses inferencing (snapping) the latter doesn’t (but allow for more control over what entity to pick).

(You can also use model.raytest, but InputPoint and PickHelper will give you more information and be more consistent with SU’s own tools in most cases.


#6

@tt_su Yes, with the new tool. How to use Sketchup::InputPoint or Sketchup::PickHelper with native ComponentTool, after user place component from Components Dialog?


#7

If you use place_component I’m afraid you aren’t able to customize its behaviour.


#8

Thanks @tt_su and @voquochai, yes, I’m trying to get the landing face in onPlaceComponent of ModelObserver. I’m wondering if we can create new tool inherited some behaviors of Placement tool or not? or if you know there is any possible way do get the landing face. Please let me know. Thanks.


#9

It is not possible use use SketchUp’s tools as a base for custom tool. That would be nice though.

(Add your feature request in our API tracker: https://github.com/SketchUp/api-issue-tracker/issues)


#10

Thanks @tt_su. I added the feature request to SU’s API Tracker https://github.com/SketchUp/api-issue-tracker/issues/134