[Bug] Add_group inside a component
-
Hi all!
I try to make a group of a component inside another component (so with definition parent).
But when group is created, it is deplaced to the origin of the component definition. And it generates a bug on close SU.But when I try to make a group of a component B inside another component A , and SU has component definition B opened, It works.
So there is a bug on creation of a group. It cames from the parent of the selection to group. If you are on the model of the drawing, and the group to create is inside a component definition parent, it won't work.
-
I think that's been reported to Google, but it's a good reminder that groups and components need some help.
-
I'm experiencing the same thing.
By the way, are you working on converting Components to Group by any chance?
-
Just noticed that
ComponentInstances
which are not nested or grouped will returnModel
.
ButComponentInstances
located inside another component will return aComponentDefinition
.So when you use
instance.parent
inside an component you modify the definition instead of the parent entities space. -
It's been a long time I try to convert all components into groups by ruby... See here...
Yes, thomthom, bug appears when parent of entities to group are not model.
I have made a set of tools for components and groups. One of these tools can convert one component into a group. It also works with sub components!! It works because you have to select it before conversion, and if you want to select, you have to enter in the first component. So SU parent is the component definition... so 'model.entities.add_group' works. Now tool I want to create could convert ALL components into groups. It works well with components with model parent, but there is a bug with the other components....
Sorry for my poor english it's quite difficult to explain clearly what I noticed ! -
Ahh. Heh. Looks like I'm trying to reinvent the wheel. Even the name of the ruby 'tt_c2g.rb', is pretty much similar to the name of yours. I was looking in to this yesterday. I managed to convert components to groups in the current selection fine. Though after a few bugsplats as SU was picky to how it was created. grouping the component and exploding seemed like the way to go.
From there I thought it'd be an easy process off just making an recursive method, but alas. two hours of bugsplats later it's no go. I quicly realised the many issues.
My latest attempt was to avoid using
.parent
and manually keep track of theentities
space which the group could be added to. But something is wrong. SU still bugsplats. It was getting quite late so I might have done some logical errors.I've attached my version of it. I've only worked on it yesterday, but the cursed thing is getting to me. It shouldn't be this hard.
And IMO, the
.parent
of Groups and Components should not return the Definition. That's just wrong. We have.definition
for that. I find it very odd that there's nothing to trace back the model space entities and components is placed in.
-
@thomthom said:
And IMO, the
.parent
of Groups and Components should not return the Definition. That's just wrong. We have.definition
for that. I find it very odd that there's nothing to trace back the model space entities and components is placed in.If I select a component and type:
Sketchup.active_model.selection[0].parent
it returns:
#<Sketchup::Model:0xcf39148>
I don't get a definition. If I am inside a component and then select a nested component and run that code then I get a
ComponentDefiniction
. But that is to be expected since I am inside a component. It is returning the parent of the selected component, which happens to be a component. And its parent is the Model. -
@chris fullmer said:
I don't get a definition. If I am inside a component and then select a nested component and run that code then I get a
ComponentDefiniction
. But that is to be expected since I am inside a component. It is returning the parent of the selected component, which happens to be a component. And its parent is the Model.No, that's not the parent ComponentInstance. It's the definition of your selected ComponentInstance that's returned.
-
tt_c2g!!
@unknownuser said:
And IMO, the .parent of Groups and Components should not return the Definition. That's just wrong. We have .definition for that. I find it very odd that there's nothing to trace back the model space entities and components is placed in.
.parent
(that returns the definition) is useful to know where we are. Inside a component, or not. However I think it's the.add_group
function is bugged... We should be able to transform a component directly in its definition.
I tried to create a group of all entities from the definition, and it create the group on the origin of the definition. And when you close the drawing, it bugs. So when you try this'component.definition.entities.add_group(sub_component)'
and you aren't inside this component on your model space, it bugs.
PS : Sorry I don't know how to tell clearly when you are inside a component by double-clickinf on it... -
@matt666 said:
However I think it's the
.add_group
function is bugged...Well, there sure is something about it, as the manual says: http://code.google.com/intl/nb/apis/sketchup/docs/ourdoc/entities.html#add_group
@unknownuser said:
NOTE: calling add_group with entities in its parameters has been known to crash SketchUp. It is preferable to create an empty group and then add things to its Entities collection.
Though, how you go about not providing entities to the method's argument, I don't know. http://www.sketchucation.com/forums/scf/viewtopic.php?f=180&t=17153
-
@matt666 said:
I tried to create a group of all entities from the definition, and it create the group on the origin of the definition. And when you close the drawing, it bugs. So when you try this
'component.definition.entities.add_group(sub_component)'
and you aren't inside this component on your model space, it bugs.Exactly the same as what I see. Wonder if we could summon a SU developer to provide some feedback.
-
# get the required component-definition and the required transformation... g1 = model.active_entities.add_group g1ents = g1.entities g1ents.add_instance(component_definition,transformation) g1ents.add_line([0,0,0],[1,1,1]) # this adds a component, then an edge... # you can even add a group inside a group thus... g2 = g1ents.add_group triangle_face= g2.entities.add_face([0,0,0],[1,0,0],[0,1,0]) # etc etc...
...
-
How would you add existing geometry to a group though TIG? There is no
entities.add_existing_entities
method. ornew_ents = entities.copy!
or anything. -
@chris fullmer said:
How would you add existing geometry to a group though TIG? There is no
entities.add_existing_entities
method. ornew_ents = entities.copy!
or anything.model=Sketchup.active_model g1=model.active_entities.add_group ### initially empty g2=model.entities.add_group(model.selection) ### or any other 'list' of miscellaneous geometry, ### text, instances, groups, dims etc g1.entities.add_group(g2) g2.explode ### if required... ### misc stuff moved into a group. ### I know you can skip making g1 and just use g2 ### but here g1 is either 'pre-existing' or needed later... ### OR ### to copy items into a group, rather than move them ### into a group you can use... g1=model.active_entities.add_group ### initially empty g2=model.entities.add_group(model.selection) ### as above... g3=g2.copy g2.explode ### to restore originals back as they were... g1.entities.add_group(g3) g3.explode ### if required... ### more misc stuff copied into a group. ### I know you can skip making g1 and just use g2 and g3 ### but here g1 is either 'pre-existing' or needed later...
...
-
So the problem isn't with adding existing geometry to a group, it is with adding geometry to a group that is nested.
Seems like it should be quite possible then to find all nested components. Then find the deepest one. Then add its existing geometry to a new group created inside the component. Then explode the outer componentinstance. Thanks TIG (again and again and again)
Chris
-
Adding entities to a definition is bug ridden... you can try...
g1=model.active_entities.add_group(model.selection) component=instance.definition g=component.entities.add_group(g1) g.explode g1.explode
to give you 'loose' stuff inside the component definition...
BUT when it Bug-splats it's NOT my fault !
It doesn't work because it's trying to move these grouped entities from their parent - the model - into the definition, which itself is another 'parent'. You CAN add new geometry or a group into a definition, BUT then to do that you need to add each of these bits as brand-new geometry. It would be possible to 'copy the info' of each of the group's entities as base-level entities and then recreate them inside the definition bit-by-bit, and at the end you can delete the original items since they are 'moved' into the definition... However, that's a pretty complex task... Info for every group, mining down into it's components, then info for each face, its edges, its materials, its layer etc etc...
We need a 'definition.entities.adopt(array_of_another_parents_entities)' method to transfer to another 'parent' ? I don't have time to do it right now - has anyone go one ???
... -
... Google?
-
Work around...
I've go a half-baked script that might work. I'll post it in a separate thread soon...
... -
Aaah... Cool!
Advertisement