Basic understanding of instances ???
-
hi,
i would like to discuss the basic structure of how skp works:i normaly generate a model per ruby (some elements in some groups and some components) , which are all packed
in a master group.
so i can delete the whole thing by deleting the master group from ruby.
ok.
when i again genarate the object with same parameters, the components have additional numbers ( like
@m_pf_l#27 , while starting with @m_pf_l before 1st delete.)so what happens? if i delete the master group WITH all components in it, does sketchup keep a table of names of deleted compnents or even all the components ??? my file gets bigger after a certain time, so maybe this is also a point.
so is is possible to purge the file from ruby , but to purge only the elements from the latest deleted group?
or shal i somehow delete or component instances WITHIN the master group, before deleting the master group itself?i found this in the forum:
Sketchup.active_model.definitions["CompoName"].instances.each{|e|e.erase!}, but don't know, if it will work for the master group only , or delete also its copies, which the user wants to keep.
thanx
stan -
ComponentDefinitions, Groups and Images are are variants of
model.definitions
.
There are two methods -definition.group?
anddefinition.image?
- used to filter the list of definitions to find just those types.
All definitions have a unique name - even though you may not always see it.
So two different unnamed groups will have different definition names [Group#1, Group#2 etc].ComponentDefinitions are different from Groups/Images in that they appear in the "Component Browser" and can have multiple or no instances at all and stay there until you 'Purge' the model...
They can of course have multiple instances of the same thing, be made_unique, glue, cut, face_me etc
In contrast a Group must have at least one instance, otherwise SketchUp tidies up after you and deletes the unused Group from the definitions list.
You can also copy a Group and make multiple instances of it [done manually and in code] - see what "Entity Info" says...
If you manually edit a second instance of a Group, then it is automatically made unique when you close the edit.
If you manually edit a second instance of a Component, then it is NOT automatically made unique, and the changes appear in all other instances.
When you edit the entities of a Group OR Component then the changes apply to all instances.
You must usegroup2.make_unique
to mimic the manually achieved result.
Also ALL empty definitions [e.g. fromdefn.entities.clear!
] are auto-purged.So to go back to your question...
If you manually or code to erase a lone group, or a group of nested groups, then that will remove all of those groups' definitions from the definitions list.
However, removing a group of component-instances will only remove the group's definition from the definitions list.
Also deleting a lone component-instance does not remove its component definition from the definitions list, even though it is unused.
An unused component-definition will stay in the definitions list until it is purged or you usedefinition.entities.clear!
within anmodel.start_operation()...commit_operation
block.When you add a new definition by name by code - and that name is already in use - it is auto-incremented.
So the initial "compo" becomes "compo#1", "compo#2" etc, unless any earlier versions are unused and then purged from the definitions list - in which case unused names are recycled... -
Tig: how would i do something like this ?
definition.group?
read component list looking for groups in list # example ( group_name1 and all in that group)
Collect all in that group then put into arraythe_item.push(FoundPile.new(fname, pname, fb.entity, fb.transformation)) # the_item is defined as array previously
it would do this for all that are in that particular group or for the gub groups inside it as shown in the image
-
groupdefs=[]; Sketchup.active_model.definitions.each{|d| groupdefs << d if d.group? }
an array of definitions, which are groups.
IF you want to list by name use:
groupnames=[]; Sketchup.active_model.definitions.each{|d| groupnames << d.name if d.group? }
To retrieve that definition 'by name' later use:
groupdef=Sketchup.active_model.definitions['groupname']
Also:
entities_by_defn={}; groupdefs.each{|d| entities_by_defn[d]=d.entities.to_a }
a hash of group_definitions, each containing an array of that definition.entities.
To get the name of a group-definition use:
dname=groupdef.name
To get the instances of a group use:
group_instances=groupdef.instances
To find the instance's name, transformation etc, use:
group=group_instances[0]
then use:
group.name group.transformation
etc... you have many other methods relating to each instance...
.layer .material .hidden?
etc -
thank you very much Tig ..
This may help solve a problem .
may you have a good day -
A couple of years ago I wrote an overview of definitions and instances in SketchUp:
http://www.thomthom.net/thoughts/2012/02/definitions-and-instances-in-sketchup/
Advertisement