Question

I created a sketchUp plugin that draws a wall (with lenght, width and height).

Now I would like to insert a "window" in that wall (fixed length, width and height, depending on the wall). How can I:

  1. Create but not yet draw the group containing the window. Link it to the current mouse position
  2. Constrain the current mouse position to the front plane of the wall I drew before
  3. When the user clicks, the window is inserted and the group is shown
Was it helpful?

Solution

The easy way to do it, that doesn't fulfill your request 100% - but do use existing SketchUp conventions, is to create a component definition and then use Model.place_component to activate SketchUp's native tool to position a new component instance.

In order to fulfill your question 100%:

  1. A Group is an instance. You cannot create one and not place it in the model. You can create it in step 3 when the user clicks. (Though, a window sounds like a candidate for a component since you usually have multiple copies of the same window type.)

  2. You cannot constrain the mouse cursor itself, but if you implement a custom Tool and make use of the InputPoint class you can selectively determine what is a valid insertion point when the user clicks. You can also draw virtual lines and polygons to the viewport to give a preview of your window.

  3. Profit!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top