For example, here's a bit of code I wrote which allows you to right click on a component which you wish to exchange for another component and select the new component to use by simply clicking an instance of it in the drawing.
Heres the code which handles adding a menu option to the UI
class SwapTool
# The activate method is called by SketchUp when the tool is first selected.
def activate
Sketchup::set_status_text("Select replacement component", SB_PROMPT)
end
def deactivate(view)
view.invalidate
end
# The onLButtonUp method is called when the user releases the left mouse button.
def onLButtonUp(flags, x, y, view)
ph = view.pick_helper(x, y) #pick helper deals with working out what you have clicked on
ph.do_pick(x, y)
entity = ph.best_picked
return nil if not entity.kind_of?(Sketchup::ComponentInstance) #if the thing thats clicked on is not a component then do nothing.
Sketchup.active_model.start_operation("Swap components") #tells sketch up that all the next commands will be one undo operation
swap_components(entity.definition) # calls the swap_components method
Sketchup.active_model.commit_operation #finishes the undo operation
Sketchup.send_action("selectSelectionTool:") #tells sketch up to activate the select tool
end
def onCancel(flag, view)
Sketchup.send_action("selectSelectionTool:")
end
end # class SwapTool
As you can see it's pretty simple and concise compared to pascal.
You could possibly use swig to generate bindings to your existing C++ classes automatically
You can post now and register later.
If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.
Question
Will
I'd like much better support for scripting. The ruby scripting API for google sketchup is light years ahead of the pascal scripting system used by VW.
See here:
https://developers.google.com/sketchup/docs/tutorial_geometry
For example, here's a bit of code I wrote which allows you to right click on a component which you wish to exchange for another component and select the new component to use by simply clicking an instance of it in the drawing.
Heres the code which makes the swap:
Heres the code which handles adding a menu option to the UI
As you can see it's pretty simple and concise compared to pascal.
You could possibly use swig to generate bindings to your existing C++ classes automatically
http://www.swig.org/
Perhaps you could also use QT for the user interface.
http://qt.nokia.com/products/
I'd be happy with ruby, python, or any modern object oriented scripting language.
Kind Regards,
Will
Link to comment
13 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.