OnPlaceComponent: place the instance in a group
-
System: Mac Os X 10.6.2
Sketchup: Pro 7.1.6859Hello everybody
I have a little Problem.. i hope it is something easy and i was to
stupid to figure it out of the api and the diagram.
I know how to create new groups. I know how to create new instances. I
know how copy instances into groups. I think the api
needs a clean up and to get more in detail sometimes.. but this is
another problem.If i have an instance like in the onPlaceComponent
(Sketchup::ModelObserver), is it possible to place this instance into
an existing group?
The only way i figured out now is, to place a new instance using the
definition with add_instance into the group and then delete the other
one.. but thats dirty
(group.entities.add_instance(instance.definition, transformation) ...)There has to be a way moving instances out of groups into others and
so on .. some possibility to edit the group-hierarchy
because when i use the outline window, it is possible. It has to be
possible with the api as well (i hope) ?Thanks in advanced and excuse my bad english
(i posted the question in the Google SketchUp Developers group as well, but it seems that there is not much going on. Hope thats okay)
larrywayn -
Moving things between context isn't as easy as one might think. Instances, like you describe by erasing the recreating are the easiest. What is more troublesome if you want to move loose mesh geometry. Then you need to group that and make a new instance of that group, explode it and then remove the old.
Then you have some issues with adding existing geometry into groups - some scenarios can cause crash.
-
sigh
why is something easy, like changing a group reference, hard to change in ruby?
i think it could be possible deleting and recreating everything, everytime.. but that takes time and performance (and also if it is buggy, its not that good). Thats not acceptable. if there are 100 components that would be no fun.. because the user should be able to move components dynamically from one group to another and without waiting till everything is recreated.another solution would be to use the componentnames only without groups. looping over the names and renaming the components. think thats much easier to implement.. but moving a group of elements, which contains together, (without grouping them) would be difficult, too
Damn Sketchup api ^^
-
You have to be careful not to cross-thread the entities sets context - else there'll be 'Bugsplats'.
The manual method and the API don't 'mesh'.
If the instance is in the model.entities the new_group to contain the 'moved' instance must be in model.entities too.
If the instance is in a group.entities set then the new_group you wish to 'move' the instance into must be in the group.entities too.
So something likenew_group = instance.parent.entities.add_group(instance)
To 'move' an instance out of one entities set into another entities set [e.g. either a preexisting or a just-made group] that isn't in the same 'context' is possible but very convoluted and simply adding another version and erasing the earlier one is by far the easiest and least troublesome option...
You could try a convoluted### instance == the thing to 'move' tri=instance.transformation defn=instance.definition gents=group.entities ### group is the destination container either preexisting ### or made 'empty' as in group=entities.add_group() trg=group.transformation tr=tri * trg ### untested - but something like this ! new_instance=gents.add_instance(defn, tr) ### clone its properties... inam=instance.name imat=instance.material ilay=instance.layer ihid=instance.hidden? ivis=instance.visible? ishw=instance.cast_shadows? irsh=instance.receive_shadows? ilok=instance.locked? iads=instance.attribute_dictionaries iglu=instance.glued_to ### transfer its properties... new_instance.name=inam new_instance.material=imat new_instance.layer=ilay new_instance.hidden=ihid new_instance.visible=ivis new_instance.cast_shadows=ishw new_instance.receive_shadows=irsh new_instance.locked=ilok iads.each{|atdict| name=atdict.name atdict.each_pair{|key,value|new_instance.set_attribute(name,key,value)}if key }if iads[0] new_instance.glued_to=nil ### as it can't remain glued to a face that's outside of its current entities set! ### ### you might want also to remove any observers that could trigger otherwise [unlikely] ### e.g. instance.remove_observer(observer) ### ### tidy up... instance.erase! ### you now have a new instance that is a 'clone' of the old one ### but moved from its original entities set into group.entities ### ### you might also need to add any observers that type of entity needs in your setup ### e.g. new_instance.add_observer(observer)
Hope this helps
-
Yup, there are a few areas where the API is less than ideal.
-
Thanks everybody.
Wasn't the solution i hoped for but instead i wrote a name organized system, which perfectly fits our needs.
Now there are other problems, hope i can get a solution for themlarrywayn
Advertisement