I'm getting there - but need some help.
-
To set a name default name, just do this:
default_name = "Cabinet1"
values = [500.mm, 720.mm, 300.mm, 18.mm, 18.mm, 18.mm, default_name]To make a longer name, take the returned value, which is n1, and append to it, like this:
group.name = n1 + " - SideL" ;To create an empty group, code:
new_empty_group = Sketchup.active_model.entities.add_group() ;To create a group with stuff in it, code:
stuff = an_array_of_entities_andor_groups_andor_components_you_have_already_created ;
new_populated_group = Sketchup.active_model.entities.add_group(stuff) ;Todd
-
Thanks very much Todd.
The first part works a treat - excellent.
I am not sure I fully understand what to put in the last bit about creating the Global group, but I'll experiment with that this evening.
Thanks again.
-
@unknownuser said:
To create a group with stuff in it, code:
stuff = an_array_of_entities_andor_groups_andor_components_you_have_already_created ;
new_populated_group = Sketchup.active_model.entities.add_group(stuff) ;I have searched around and can't find anything that really helps with this.
I assume that 'stuff' is the name that will be applied to the new group, but don't understand what to add after the = sign to include the other groups I have created.
Also, 'stuff' (the new group) needs to be called the same as the 'default_name' (eg Cabinet1) entered in the Gui.
Any further guidance would be appreciated.
-
OK.
In your code, every time you need a new group, for the left side, right side, bottom, whatever, you use the same variable name... "group". Doing that, you lose "addressability" to any group you've already created.
Therefore, change the names from "group" to "left_side_group" and "right_side_group" and "bottom_group", etc.
Then, you when are ready to create your big overall group, code this:
overall_group = Sketchup.active_model.entities.add_group( left_side_group, right_side_group, bottom_group )
Todd
-
A few other helpful pointers...
Within your method, you only need to do this once:
model = Sketchup.active_model
Same with this:
entities = model.active_entities
It's bad form to redefine entities like you are doing.
entities = model.active_entities group = entities.add_group entities = group.entities
I would not even set the first one. And for as little use you are getting out of it, not even the second one.
While you are creating your cabinet, you perform several "start_operations". You really only need one for the whole cabinet, and you should close it off at the end by an explicit "commit_operation".
Todd
-
Thanks again Todd.
You have saved me a lot of time trying to get this far.
@unknownuser said:
A few other helpful pointers...
I quickly tried to modify the script to take these comments in to account, and I somehow ended up breaking the script. I'll have another look at this later when I have some time, but I have about 15 other scripts I have done, similar to the one I posted here, for other types of cabinets, and I need to press on an incorporate the changes for grouping in those first.
One question though.
In the global grouping you said to use
@unknownuser said:
overall_group = Sketchup.active_model.entities.add_group( left_side_group, right_side_group, bottom_group )
This works well enough, but can you just clarify what name is given to this group?
From what I can figure, it has no name. If that's the case, can I somehow give the overall group the same name as was input for the Cabinet Code? -
Sure.
overall_group.name = n1
Todd
-
It's so easy when you know how.
Thanks again Todd.
-
@unknownuser said:
Then, you when are ready to create your big overall group, code this:
overall_group = Sketchup.active_model.entities.add_group( left_side_group, right_side_group, bottom_group )
This works for most of my scripts except:
Some of the scripts include items which may or may not be created depending on the input.
For example the script allows for there to be none, one, two or three drawers, and the overall_group call would be:overall_group = Sketchup.active_model.entities.add_group( left_side_group, right_side_group, bottom_group, drawer1_group, drawer2_group, drawer3_group)
This works if both drawers groups are created from the input, but if the option for the second drawer is not to have one, drawer2_group is not created so the overall_group is not created either.
My thoughts are that I need to write a couple of statements to check if the group has been created - something like this:
if drawer_group3 exists then
overall_group = Sketchup.active_model.entities.add_group( left_side_group, right_side_group, bottom_group, drawer1_group, drawer2_group, drawer3_group)else
if drawer_group2 exists then
overall_group = Sketchup.active_model.entities.add_group( left_side_group, right_side_group, bottom_group, drawer1_group, drawer2_group)else
if drawer_group1 exists then
overall_group = Sketchup.active_model.entities.add_group( left_side_group, right_side_group, bottom_group, drawer1_group)else
overall_group = Sketchup.active_model.entities.add_group( left_side_group, right_side_group, bottom_group, drawer1_group)
What I am not certain about is what the statements shown in red should be for checking if the group was previously created.
Can anyone assist.
Thanks.
-
Don't do that - too much redundant code.
Do something like this. As you create a new group, add it to the array of groups that will eventually be created...
all_groups = []
all_groups << left_side_group
...
all_groups << right_side_groupetc...
Then, if you create 3 drawers, append them all to your array like
if drawer_group1 exists then all_groups << drawer_group1 end
and so on.If you skip a drawer, no biggy.
Then, at the end,
overall_group = .....add_group(all_groups)
Todd
-
Thanks again Todd.
I have the script working, but not quite the way you suggested.
I used your advice and created the all_groups array, and added the groups using 'all_groups<<'.
However I kept getting a script error if I tried to use the
'if drawer1_group exists then all_groups << drawer1_group end 'The error read:
@unknownuser said:
single_door_rt_base
Error: #<NameError: C:/Program Files/Google/Google SketchUp 6/Plugins/sdrtbase.rb:348:insingle_door_rt_base': undefined local variable or method
exists' for main:Object>
C:/Program Files/Google/Google SketchUp 6/Plugins/sdrtbase.rb:348Line 348 is where the first 'if' line is.
As it happens, I already had some 'if' statements where the drawers were created, so I added the 'all_groups<<drawer1_group' before the end of the statement and it works fine.
However if you have any thoughts on the error I'd be interested to hear. (I wondered if there should be some other syntax like [ or ' or something)
Thanks again.
-
I was hoping you weren't going to type my "code" just as I typed, because it wasn't really "code", per se, as it was pseudo code. You're assignment is to work out the proper syntax. I was merely illustrating the concept.
Todd
-
As I said in the heading of my topic - 'I'm getting there'
I also said - 'but need some help.' and you have certainly given me that.
My problem is that I have no experience of programming/scripting, and I am short of time in developing a major project (the scripts for SU are only a part of the project) and have limited time to 'study' something new, particularly something as involved as Ruby - but I will persevere as time allows.
Thanks again for you patience and assistance so far - it has helped no end.
Advertisement