Painting Plugin Help
-
Hi,
I want to create a plugin that will feel like I am painting. Have couple ideas but want to start by copying a 2D or 3D geometry and by pressing & holding a key it will keep pasting the geometry so that if I move the mouse it will feel like a Photoshop brush.
Javascript Code that will be sended to Ruby with other code using params;
if (keyIsDown[SPACE]) { paint = 1 } if (keyIsDown[SPACE] == false) { paint = 0 ; }
Here is Ruby Script ;
if params['paint'].to_i == 1 ; Sketchup.send_action(CMD_PASTE) ; end
The thing is that when I click Spacebar the object paste itself but problem is I need to click with mouse to put it down and this disrupt the flow of things. I want to Press spacebar and object automatically paste itself down without clicking mouse.
Any Suggestions?
-
Yeah, you need to specify in your code where to put the instance. You would do that with a pickhelper. Is this plugin written inside a SketchUp Tool class? You will need to do it as a tool to track the cursor position, so you can then insert the instance at the cursor position.
-
The description is a bit lacking. Not 100% sure what you're code is doing, but when you say "I need to click with mouse to put it down and this disrupt the flow of things." I then take it you used
Model.place_component
? In order to just insert a component you useentities.add_instance
.... ah ... you trigger SketchUp's Copy and Paste commands. What you probably want to do instead is use a variable to store the reference to the instance or definition you want to "copy" - then you can use
entities.add_instance
. -
Didier Bur has done several Component Spray plugins. Look at what he has done.
-
Hi, thanks for the replays
Chris Fullmer this might be the answer but I need to study how to apply this little more. If I am not mistaken this will get the coordinates of the object that is referenced under the mouse.
So somehow I need to make a variable that gets the values of does coordinates so I can do what Thomthom said... entities.add_instance
Dan Rathbun the Compo Spray has the same issue I am having and that is that in other to keep dropping coponent one has to keep clicking the left mouse click.
It would be ideal to click & hold and components constantly keep dropping.
I already have web dialog updating 15 frame a second all I need is a way to get rid of the multiple clicks and I am golden.
Note: Still lack a lot of knowledge in creating geometry with code but little by little I will learn...thank you guys really appreciate it.
-
Here is a really quick tool that shows how to "paint" with components. I forget how the "flags" work, but it looks like you get a flag of 1 if the mouse button is down. Isn't there a list somewhere of the flags?
I wrote this quickly as a test code. I run my code snippets like this in a multi-line code editor in SU (Like Jims, or Alex Schreyers, or Aerilius).
You must have a component selected before running the snippet. Then just hold the left mouse button down and move the mouse and it will paint the selected instance.
class Cltool def activate @@sel = Sketchup.active_model.selection[0] @@ents = Sketchup.active_model.active_entities end def onMouseMove(flags,x,y,view) ip1 = view.inputpoint x,y point = ip1.position if flags == 1 add_object(point) end end def add_object(point) t = Geom;;Transformation.new(point) @@ents.add_instance(@@sel.definition,t) end end Sketchup.active_model.select_tool Cltool.new
-
Christ Fullmer you are a genius!!!
This transform SketchUp into the best painting application in my opinion...I will see If I can expand this & add new features to make it even better.
I am so excited!...again thanks!
Advertisement