Create groups of instances correctly
-
Hi all, I want to create a new group and place inside group or component with previously created in sketchup. I have observed that writing
.Add_group(component)
or.Add_group(group)
may cause bug splats.. I do not know how to do this properly, Thanks in advance for your help
(google translator) -
See this snippet example: [Code] encapsulate instance into group
The error that was causing BugSplats was supposed to be fixed in v8.
-
You should use
gp=entities.add_group()
Then immediatelygents=gp.entities
then add things to the 'gents
'...The only time you can add a group specifying its contents directly is if you are SURE that the contents are in the sane context as the group itself.
It you 'cross-thread' context and entities you get splats...
If you manually select some items and then 'group' them then that group is in the same context as the items selected - you cannot manually select items across different contexts...
Similarly in code, you can only add items to a group directly IF they are BOTH in the active_entities context...
So this will work:
model=Sketchup.active_model ss=model.selection gp=model.active_entities.add_group(ss.to_a)
BUT this MIGHT fail if themodel.entities != model.entities
model=Sketchup.active_model ss=model.selection gp=model.entities.add_group(ss.to_a)
The selection might NOT be in themodel.entities
context.
However, since a [manual] selection is always in the active_entities, it might be safe.
A foolproof way would be:
model=Sketchup.active_model
ss=model.selection
gp=ss[0].parent.entities.add_group(ss.to_a)[/ruby]Just THINK what you are coding
-
thank you very much Dan and TIG this information is exactly what I needed
-
Unfortunately I have to perform the task outside the active context for what I'm going to use the method proposed by Dan, but I think you need to add the following properties;
material, attribute_dictionaries, layer, description, entity_name, name, receives_shadows, casts_shadows
I wonder if there are more properties that can be inherited by the new instance
(google translator) -
material ?
-
Yes, if the user has applied a material without opening the instance, the material is assigned to the instance and not to the faces, then it would seem that after executing the code, the object has lost color
-
@dacastror said:
... Dan, but I think you need to add the following properties;
material, attribute_dictionaries, layer, description, entity_name, name, receives_shadows, casts_shadows
I wonder if there are more properties that can be inherited by the new instance
(google translator)Yes you are correct. Just before the old instance is deleted, it's properties need to be copied over to the new instance.
Advertisement