by njeremy2 » Thu May 31, 2012 1:56 pm
Hello everybody ! I'm starting to write a new plugin : Integration tool This plugin is used to integrate a draw into a group. Before this plugin when I want to integrate a draw into the group, I select it, I cut it, I select my group where I want to put it and then I select "paste in place". With that plugin, I want to automatise that. Here some screenshots of what I need to do. 



How should work my plugin : -I select the drawing I want to add -I start/activate the plugin -A messageBox comming : "Select the group where you want to integrate" -I select the group -The drawing is inside the group ! I just start to write the structure of code. I made research for "send_action" for cutting and paste my drawing https://developers.google.com/sketchup/docs/ourdoc/sketchup#send_actionCan I use "onLButtonDown" for selecting my group when the drawing is selected ? Can you help me to give me some leads to reach this objective ?
-
njeremy2
-
- Posts: 58
- Joined: Mon Apr 16, 2012 2:53 pm
- Name: jeremy
by thomthom » Thu May 31, 2012 2:14 pm
You can use the PickHelper to determine you are drawing on a face inside a group and then draw directly inside that group. njeremy2 wrote:I just start to write the structure of code. I made research for "send_action" for cutting and paste my drawing
Your approach seem to be translating directly what you do in SketchUp - by copying and pasting. But with when using the Ruby API there are usually other (and better) ways to do thing. (Remember, when you want to make a grouped box when using SketchUp UI you draw the cube then group it - with the API you create the group and draw directly into the group - different approach.) What I don't understand is why you want to do this... you want to avoid opening/closing the groups?
-

thomthom
- Global Moderator
-
- Posts: 17574
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: thomthom
- Operating system: Windows
- SketchUp version: 8
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
-
by TIG » Thu May 31, 2012 2:20 pm
What you can do manually is not accessible through the API. There are send_actions for Edit's Copy and Paste, but not Paste-In-Place. Also opening entities contexts is not possible... But here is a work around...
You preselect some 'things', so we know things=model.selection.to_a Having the 'group' picked bu the mouse click in the Tool tells us group.entities - and that is where the next to be preselected 'things' is to end up... Now make a 'temporary group' of the 'things' [it's safe to make it directly - this time - because the selection must be in the active_entities ! if the entities are cross-threaded it WILL Bugsplat!] tempgroup=model.active_entities.add_group(things) Now add an instance of the new 'tempgroup' to the group.entities thus: inst=group.entities.add_instance(tempgroup.entities.parent, tempgroup.transformation*(group.transformation.inverse)) then explode the instance and erase the original selection that is still grouped: inst.explode tempgroup.erase! - clones of the 'things' are now inside the group and the originals are gone.
I haven't tested this code - I typed from memory - so try it and adjust as appropriate...
TIG
-

TIG
- Global Moderator
-
- Posts: 13956
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- SketchUp version: 8
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by njeremy2 » Thu May 31, 2012 2:56 pm
thomthom wrote:You can use the PickHelper to determine you are drawing on a face inside a group and then draw directly inside that group. njeremy2 wrote:I just start to write the structure of code. I made research for "send_action" for cutting and paste my drawing
Your approach seem to be translating directly what you do in SketchUp - by copying and pasting. But with when using the Ruby API there are usually other (and better) ways to do thing. (Remember, when you want to make a grouped box when using SketchUp UI you draw the cube then group it - with the API you create the group and draw directly into the group - different approach.) What I don't understand is why you want to do this... you want to avoid opening/closing the groups?
I avoid nothing, I haven't got a special way to do that but I don't know how to start the plugin So if understand well, Tig advise me to get the selection and put it into temporary group. Then put this tempgroup into the existing "GROUP1" ? then explode GROUP1 and erase tempgroup ? At the end, there is no group if I explode GROUP1 ? (is it what you said ? I think I don't understand lol  ) Anyway, if the tempgroup is into GROUP1 with your solution it's good for me ! I will try this now !
-
njeremy2
-
- Posts: 58
- Joined: Mon Apr 16, 2012 2:53 pm
- Name: jeremy
by njeremy2 » Thu May 31, 2012 3:39 pm
thomthom wrote:You can use the PickHelper to determine you are drawing on a face inside a group and then draw directly inside that group.
Yes you can do that but my boss tell me that someone forget to go inside the group before drawing, that's why he asks me to do this plugin ... ... we have stupid sketchup users in france 
-
njeremy2
-
- Posts: 58
- Joined: Mon Apr 16, 2012 2:53 pm
- Name: jeremy
by njeremy2 » Thu May 31, 2012 4:35 pm
this line doesn't work : - Code: Select all
inst=group.entities.add_instance(tempgroup.entities.parent, tempgroup.transformation*(group.transformation.inverse))
What "transformation" module is use for ? Because in "Automatic Sketchup.pdf" transformation* doesn't exist. It's write : The transformation method is used to retrieve the transformation for the group.But what transformation ? I'm stuck here, I'm coming back tomorrow
-
njeremy2
-
- Posts: 58
- Joined: Mon Apr 16, 2012 2:53 pm
- Name: jeremy
by TIG » Thu May 31, 2012 9:01 pm
What error messages do you get ? Any group/instance has a transformation. We use it here to get the temp group into the group in the same relationships ...
TIG
-

TIG
- Global Moderator
-
- Posts: 13956
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- SketchUp version: 8
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by njeremy2 » Fri Jun 01, 2012 8:38 am
TIG wrote:What error messages do you get ? Any group/instance has a transformation. We use it here to get the temp group into the group in the same relationships ...
There is no error messages but this line isn't executed. model = Sketchup.active_model things = model.selection.to_a UI.messagebox "initialization ok" tempgroup=model.active_entities.add_group(things) UI.messagebox "add group ok" inst=group.entities.add_instance(tempgroup.entities.parent, tempgroup.transformation*(group.transformation.inverse)) UI.messagebox "add_instance ok" I put messageBox each line to see if the code is executed or not. "add instance ok" didn't appear so I guess is not working Into outliner, I see the plugin create a new group for my thing which is selected but it isn't integrated inside the initial group. 


-
njeremy2
-
- Posts: 58
- Joined: Mon Apr 16, 2012 2:53 pm
- Name: jeremy
by TIG » Fri Jun 01, 2012 9:19 am
Where in your code are you getting 'group' as a reference to the group into which you want to move the selected 'things' ? It will be set by picking a group with the Tool, but as a test now you can 'preselect' it earlier by highlighting the 'group' and having an extra line early on like this... model=Sketchup.active_model group=model.selection[0] then deselect the 'group' and select the 'things' to be added, then continuing with the code... things = model.selection.to_a ... If you do it line by line in the Ruby Console what is the result?
I have just tested it this way and it works perfectly...
TIG
-

TIG
- Global Moderator
-
- Posts: 13956
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- SketchUp version: 8
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by njeremy2 » Fri Jun 01, 2012 10:38 am
Here is my file,
When I test it, I select my drawing which I want to add in group. Then this plugin create group with that drawing put it cannot execute the next line (with transform)
I didn't test it in RUBY console into sketchup
file reupload at 11h49 - France
Please, register (free) to access all the attachments on the forums.
-
njeremy2
-
- Posts: 58
- Joined: Mon Apr 16, 2012 2:53 pm
- Name: jeremy
by TIG » Fri Jun 01, 2012 11:56 am
This is messed up... Run it with the Ruby Console open to see all of the error messages... You click the mouse-button, have a pick_helper but then set @group to be the the first item in the model.selection which is of course one of the things to be added into the 'group' ??? Also you haven't defined 'model' in the code so it'll fail at that step anyway... Try something like this: - Code: Select all
def onLButtonDown(flags, x, y, view) pickHelper = view.pick_helper pickHelper.do_pick(x, y) allPicked=pickHelper.all_picked @group = nil allPicked.each{|e|@group=e if e.is_a?(Sketchup::Group)} unless @group UI.messagebox("That's NOT a Group !") return nil end self.integration() Sketchup.send_action("selectSelectionTool:") end
The pick_helper stuff needs recasting... I added an 'exit' to the select tool. Also you should trap in 'activate' for an empty selection as they'd be nothing to tempgroup/add_ later... Here's an adjusted version that works... Also I'd also call the tool class something like 'Jeremy_integration_tool' ???
Please, register (free) to access all the attachments on the forums. TIG
-

TIG
- Global Moderator
-
- Posts: 13956
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- SketchUp version: 8
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by njeremy2 » Fri Jun 01, 2012 1:33 pm
Oh wooow! thank you TIG !  It works great ! you are fabulous ! When I look the code, it's different than what I tought ! Just a little question, if you initialise "@group=nil" is it the same if you do that : "@group=[]" ? Because after picking, you put each group you found inside "@group". Voila ! thank you so much 
-
njeremy2
-
- Posts: 58
- Joined: Mon Apr 16, 2012 2:53 pm
- Name: jeremy
by thomthom » Fri Jun 01, 2012 1:38 pm
njeremy2 wrote:Just a little question, if you initialise "@group=nil" is it the same if you do that : "@group=[]" ?
No - @group=[] == @group=Array.new
-

thomthom
- Global Moderator
-
- Posts: 17574
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: thomthom
- Operating system: Windows
- SketchUp version: 8
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
-
by TIG » Fri Jun 01, 2012 1:46 pm
You must set any reference that you want to use later outside of a block - so when it is set inside the {} block it is still accessible to the rest of the code. @group=nil sets an empty reference BUT @group=[] makes an empty array.
In the {} IF there's a selected group then @group is set to be it @group=e if.... Otherwise it stays as 'nil'. Then the test unless @group ... says if group is 'nil' you didn't pick on a group, so we exit with a message...
The current code doesn't 'insert' the group into @group, it makes it its reference. However, if you were 'collecting things' into an array initially made as groups=[] ... then you would use groups << e if... rather than the singular @group=e if..., that way you get a 'list' of matching objects...
TIG
-

TIG
- Global Moderator
-
- Posts: 13956
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- SketchUp version: 8
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by njeremy2 » Mon Jun 04, 2012 2:40 pm
oh ok! Thanks to all ! I understand now 
-
njeremy2
-
- Posts: 58
- Joined: Mon Apr 16, 2012 2:53 pm
- Name: jeremy
by Ad Machine » 5 minutes ago
Need Authorised SketchUp Training by experts in various disciplines? Check out our Training details.
-
Ad Machine
- Robot
-
- Posts: 2012
-
Return to Developers' Forum
|