Integration tool by using paste in place
-
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 usgroup.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 thegroup.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...
-
@thomthom said:
You can use the PickHelper to determine you are drawing on a face inside a group and then draw directly inside that group.
@njeremy2 said:
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 !
-
@thomthom said:
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
-
this line doesn't work :
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
-
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 said:
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.
%(#BF0000)[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 workingInto outliner, I see the plugin create a new group for my thing which is selected but it isn't integrated inside the initial group.
-
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...
-
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
-
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: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' ???
-
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
-
-
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 asgroups=[]
... then you would use
groups << e if...
rather than the singular@group=e if...
, that way you get a 'list' of matching objects... -
oh ok!
Thanks to all ! I understand now
Advertisement