Nested groups
-
Hi all, I need some help in understanding nested groups.I have to build something like as follows:
LEVEL_0 (a group)
|_____ OBJECTS_TYPE_1 (a group)
|_________ OBJ_1a (a group)
|_________ OBJ_2a (a group)
|_________ ...
|_________ OBJ_na (a group)
|_____ OBJECTS_TYPE_2 (a group)
|_________ OBJ_1b (a group)
|_________ OBJ_2b (a group)
|_________ ...
|_________ OBJ_mb (a group)So I used:
@level[0] = SkecthUp.active_model.active_entities.add_group() @level[0].name="LEVEL_0" @sublevel1 = @level[0].entities.add_group @sublevel1.name = "OBJECTS_TYPE_1" @sublevel2 = @level[0].entities.add_group @sublevel2.name = "OBJECTS_TYPE_2" # loop code for geometry generation i=0 n=5 @type1=[] # I waant to store OBJECTS_TYPE_1 into an array for further processing @type2=[] # same ... n1=0 # incremental number of OBJECTS_TYPE_1 n2=0 # incremental number of OBJECTS_TYPE_2 while i < n pts << [xj,yj,zj] # xj, yj, zy getted from other part of my script if (layer=="TYPE_1") @OBJ_1a = @sublevel1.entities.add_group ent1=@OBJ_1a.entities @type1[n1] = ent1.add_face(pts) @type1[n1].pushpull(hpil,false) if n1<9 @OBJ_1a.name= "OBJ_0" + (n1+1).to_s + "a" else @OBJ_1a.name= "OBJ_" + (n1+1).to_s + "a" end n1 += 1 elsif (layer=="TYPE_2") @OBJ_2a = @sublevel2.entities.add_group ent2=@OBJ_2a.entities @type2[n2] = ent2.add_face(pts) @type2[n2].pushpull(hpil,false) if n2<9 @OBJ_2a.name= "OBJ_0" + (n1+1).to_s + "b" else @OBJ_2a.name= "OBJ_" + (n1+1).to_s + "b" end n2 += 1 end endRunning my code I get an error
Error: #<TypeError: reference to deleted Group>
The error is on line
@OBJ_1a = @sublevel1.entities.add_groupof the code above. What is wrong?
-
As soon as you make an empty group.. you must ADD something to it in the next statement or two.
A cpoint is often used.If you don't,.. SketchUp will delete the empty group automatically.
-
As Dan says... an empty group won't last for long.
Add something like this:
@sublevel1.entities.add_cpoint(ORIGIN)
immediately after making the group [you need to do it for every 'empty' nested group]...
You won't need to do it where you add a group into a group etc, as then that means the container-group is no longer empty as it contains a nested group!
Then to tidy up later, after there is some geometry inside the group, use something like:
group.entities.erase_entities(group.entities.grep(Sketchup::ConstructionPoint))
to delete the cpoint [substitute the 'reference' needed, where I have used 'group'] -
@dan rathbun said:
As soon as you make an empty group.. you must ADD something to it in the next statement or two.
A cpoint is often used.If you don't,.. SketchUp will delete the empty group automatically.
Thank you Dan!!!

-
@tig said:
As Dan says... an empty group won't last for long.
Add something like this:
@sublevel1.entities.add_cpoint(ORIGIN)
immediately after making the group [you need to do it for every 'empty' nested group]...
You won't need to do it where you add a group into a group etc, as then that means the container-group is no longer empty as it contains a nested group!
Then to tidy up later, after there is some geometry inside the group, use something like:
group.entities.erase_entities(group.entities.grep(Sketchup::ConstructionPoint))
to delete the cpoint [substitute the 'reference' needed, where I have used 'group']Thanks TIG!! Now all the world is clear as a sunny day!!!

I'm going to correct my code.....
-
THANXXXXXXXXX!!!! it works!!!!!!
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement