Rotate a component before place it with a key imput

Rotate a component before place it with a key imput

Postby boom02 » Sun Jun 04, 2017 11:49 am

I am trying to generate some geometry and then place it with model.place_component.
I would like to mimic the function from Revit when you place a family if you press space, the family rotates and you place it rotated.
Here is the code I am working with:
#create geometry
def geom(x,y,z,xc=0,yc=0,zc=0)

group = Sketchup.active_model.entities.add_group
face = group.entities.add_face [0,0,0],[x,0,0],[x,y,0],[0,y,0]


return group


repeat = false

comp_to_place = geom(w,d,h)

def_comp = comp_to_place.definition

#place component
model = Sketchup.active_model
model.place_component(def_comp, repeat)
#if user press space, cancel model place, rotate component, start model place again
#delete place component that sits in 0,0,0

My idea to approach this challenge is to get the user input and when the user press space to cancel the model place, rotate the geometry and start a new model.place_component with the rotated geometry.
Do you guys think this is the right way? And if yes how can I get the key press from the user? Thank you!


Re: Rotate a component before place it with a key imput

Postby Dan Rathbun » Sun Jun 11, 2017 9:38 pm

boom02 wrote:Do you guys think this is the right way?

NO. The spacebar is pre-coded to activate the native SelectionTool. Many users are used to it this way, and do not want to change it. Those that have changed it, have done so for their own choice of command.

Secondly, you cannot affect how the built-in place_component works as it is a native tool, most especially not when using the repeat mode. (Ie, there really is no way to trap the spacebar and prevent it from bubbling-up to SketchUp's shortcut handler.)

The way it is designed, when not in repeat mode, is that once placed, the normal MoveTool is active, and it's hover rotate mode can be used. Just hover the MoveTool cursor over a the side of a component's bounding box, and 4 rotate handles will appear. Move to one of the handles and you'll see the cursor change to a protractor.

I myself, also kinda miss the ACAD spin before place feature.

boom02 wrote:... how can I get the key press from the user?

The best way is inside a custom tool class written in Ruby.

And you'd need to create a menu item pointing at a method object that rotates the selected object. Then that menu command can be assigned any shortcut, by users according to their own desires.
    I'm not here much anymore. But a PM will fire email notifications.
    User avatar
    Dan Rathbun 
    PluginStore Author
    PluginStore Author

    SketchUcation One-Liner Adverts

    by Ad Machine » 5 minutes ago

    Ad Machine 


    Return to Developers' Forum

    Who is online

    Users browsing this forum: No registered users and 2 guests

    Visit our sponsors: