Get Landing Face the component lays on

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.

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:

2 Likes

I used model.raytest in my plugin

1 Like

@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!

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.

@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?

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

2 Likes

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.

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: Issues · SketchUp/api-issue-tracker · GitHub)

Thanks @tt_su. I added the feature request to SU’s API Tracker Custom Tool inherited from Native Tool · Issue #134 · SketchUp/api-issue-tracker · GitHub

1 Like

你只要给你的组件自动添加一个行为即可:
definition = Sketchup.active_model.definitions[0]
behavior = definition. behavior
behavior.is2d=true
behavior. snapto= SnapTo_Arbitrary# 这个值范围是 0-3,根据自己的需要来设置
放置组件
Sketchup.active_mdoel.place_component(definition,false)