Entity.parent gives wrong type
-
Thomas,
Does the PickHelper.transformation_at give the tranformation to transform back to model coordinates, or do you have to apply the transforms for each level?
-
ph.transformation_at(n)
gives you the total transformation for theleaf_at(n)
. If you need the transformation for an item in one of the paths you need to calculate that yourself.I'm attaching the pick_helper test I used to familiarize myself with the pickhelper.
The API docks doesn't explain very well the pick paths - and methods likeph.all_picked
as it only returns all the possible pickswithin current context - not all the entities you get via the paths.
I tried to make a diagram over the PickHelper - but it didn't do so well...
-
Thanks Thomas, that's very helpful.
I've seen several scripts lately with a reload method. That seems like a good idea too. What calls the reload? Do you have some sort of "master" script that calls the various reloads?
-
@spring.freediver said:
Thanks Thomas, that's very helpful.
I've seen several scripts lately with a reload method. That seems like a good idea too. What calls the reload? Do you have some sort of "master" script that calls the various reloads?
No - but I intend to. Some weeks ago I started organizing all my plugins in a new way - they are all under
TT::Plugins
- so I can iterate theTT::Plugins
module for child-modules and call reload on them.
But at the moment I just type in the consoleTT::Plugins::PluginName.reload
. (Or make a temp menu/toolbarbutton)I started adding a
.reload
because when developing I've started to place my plugins in isolated folder as another location - which a proxy loaded scans and loads. That let me set up subversion etc for each project. -
TIG,
If I get a face (or edge) from an inputpoint, and see that it's parent is a ComponentDefinition, I can use parent.group? to see if it is actually a group, and then know that there is only one instance, in parent.instances[0].
But, if parent.group? is false, I then know that it really is a component, and there may be multiple instances. Is there a way to find out which instance the selected face came from, and therefore what transformation needs to be applied? Is this a case where the PickHelper must be used because it is the only way to get the information?
-
@spring.freediver said:
TIG,
If I get a face (or edge) from an inputpoint, and see that it's parent is a ComponentDefinition, I can use parent.group? to see if it is actually a group, and then know that there is only one instance, in parent.instances[0].No - groups can have multiple instances. If you copy a group around you see that Entity Info lists how many copies there are.
The only difference between Groups and ComponentInstances is that SU automatically makes Group instances unique when you edit them.@spring.freediver said:
Is this a case where the PickHelper must be used because it is the only way to get the information?
Yes- PickHelper to get entities, InputPoint to get 3d coordinates.
-
I'm reluctant to post this, as it caused more confusion that anything else - but just in case: http://forums.sketchucation.com/viewtopic.php?f=180&t=30232
-
Thomas,
Your description that group component definitions can have multiple instances does not make sense to me. I think that when you make copies of a group, each copy has it's own definition. That is what allows you to change the geometry in one copy, and the change is not seen in the other copies. Each group has it's own set of entities.
But with components, there are multiple instances that refer to a single component definition, and share a set of entities. So if you change any of the entities in the component definition, the change is seen in all of the instances.
That is why it surprised me to learn that groups are actually component instances inside the Sketchup model. But I assumed that meant that they are "special" components that can only have one instance. And the group? method tells you that this is the case. If group? is false, then it is a "normal" component, which can have multiple instances, which led to my question about how to figure out which instance a given entity came from. I am starting to believe that it is not possible to tell if you only have an entity address, and that is why you must use a PickHelper.
Thanks again for your help... You are truely a Sketchup Pro
-
@spring.freediver said:
I think that when you make copies of a group, each copy has it's own definition.
Incorrect.
When you make a copy of a group, the copy does not get its own definition. It will share the definition of the group instance you copied from. You can see this by inspecting the definition's instance count after making a group copy.
(It's why my Selection Toys plugin allows you to convert group copied into component instances - because SU keeps the definition references.)The catch here is that when you use the native SU tools to modify a group SU makes that group instance unique.
But, if you modify a group via Ruby, then you modify all instance! This is why we have theGroup.make_unique
which we must call if modifying groups. (SU will output a deprecated warning in the console - but there really is no other means around this.)@unknownuser said:
Group.make_unique
The make_unique method is a deprecated method used to force a group to have a unique definition.Copying a group using the copy tool in SketchUp will create copies of the group that share a common definition until an instance is edited manually or this method is used. If multiple copies are made, all copies share a definition until all copies are edited manually, or all copies have this method used on them. This method ensures that the group uses a unique definition entry in the drawing database.
Beware:
Group.entities.parent
can on occasions return an incorrect definition! See this thread for more info and workaround: http://forums.sketchucation.com/viewtopic.php?t=19765@spring.freediver said:
I am starting to believe that it is not possible to tell if you only have an entity address, and that is why you must use a PickHelper.
Yes - you do need some way to return the path for the entity.
-
Wow, that is even stranger. Especially the part about changing a group in Ruby is different that changing one in Sketchup.
Before I read your post, I had written a script to loop through the model.definitions and report how many instances each had. I saw that after copying a group, the corresponding definition had multiple instances. But then I changed the geometry of each of the copies, and re-wrote the definition list. There were now separate definitions for each of the copies, with one instance each. So Sketchup does the "make unique" as soon as it sees you make a change to one of the copies of a group.
So it seems that Sketchup really doesn't have a unique entity that is a group. It just has component definitions and instances, and a special flag on the definition that says to make it "act" like a group. And if any instances of the definition get changed (interactively), it makes a new definition and instance, so it is still just another component with a "group" flag on it.
-
Yup - and you can use an Image definition and Group definition along with
entities.add_instance
.I'm guessing the behaviour of group instances is to preserve resources....
-
I have also noticed that the Instance.name method sometimes returns an empty string. In the outliner, I see the correct name, but when I traverse the instances in Ruby, and print out each instances name, I get a blank string for one of the groups. And I get the blank string whether I refer to it as an instance or a group (I assume that calls to Group.name and Instance name are actually the same.)
Is this a known bug? Is there any kind of work-around?
-
Both definitions and instances has a
.name
method. -
Yes, but the Instance.name method is returning an empty string. The Definition.name method returns a name like "Group#5".
This code is traversing the model hierarchy. For most groups and instances, it gets the correct name. But for one particular group, the name method returns an empty string. That is why I thought it might be a known bug.
-
If you make a group into a component it will take the original 'Group#nn' name as the definition's name.
You have to usedefinition.name="new_name"
to change it to something else.
When you place an instance you can give that a separate name [Entity Info].
So you can have a component definition named "My_component" and the instances of it can also have their own names "v1", "v2" etc...
Advertisement