Are you sure this is what the user would expect? Iâve seen extensions make objects unique in order to make the programming easier - at the expence of breaking the component definition/instance contract that users expect.
Did create a unique definition for each individual instance or did re-use definitions for instances that previously used the same definition? If you did the former the file size while increase quite a bit.
You mean like the DC extension? An extension making an instance unique when interacting with it, instead of having a true DC system built-in the core of SketchUp.
Add or remove dynamic attributes affects all instances.
If the user chooses to modify only the selected instances, he must expect it to be made unique.
Youâre still right, making all instances of a piece of furniture unique will increase the volume of the file.
And the loading time can be very long, if there are many instances!
For this reason, making unique will only be applied in the cleaning method of the selection.
The method of cleaning all the project or all the furniture proposed by Click-Cuisine does not need to make unique! ( So no increase in the file size, no execution time. )
I understand that cleaning dynamic components in a selection may seem odd or unnecessary!
This method is under study to determine if it is more beneficial than harmful.
please read and try to understand what happens in this codeâŠ
ask questions when you donât follow the codeâŠ
I left in âcollectingâ the handles, but commented out the highlightingâŠ
# ClickCuisine::Cleaner (C) Copyright 2017 john@drivenupthewall.co.uk
#
#
require 'sketchup.rb'
# your namespace
module ClickCuisine
# your cleaner
module Cleaner
extend self
def target(ents)
ents.grep(Sketchup::Group).concat(ents.grep(Sketchup::ComponentInstance))
end
def kids?(entity)
entity.definition.entities rescue entity.entities
end
def hidden(e)
e.hidden?
end
def layer(e, ln)
e.layer.name =~ ln
end
def to_clean(entity)
#
kids = kids?(entity)
tents = target(kids)
lngth = tents.length
return unless lngth > 0
tents.each do |child|
# add any child we do not want, we can use known names to help...
if hidden(child) || layer(child, /VIGNETTES/) || child.definition.name == '00'
@to_go << child
# now we can remove dynamic attributes from the ones we want to keep
elsif child.definition.attribute_dictionaries
child.definition.attribute_dictionaries.delete('dynamic_attributes')
child.attribute_dictionaries.delete('dynamic_attributes') if child.attribute_dictionaries
end
# we can also 'collect' the handles here or you could have a separate ruby without @to_go[] code...
if child.parent != Sketchup.active_model
# again, we can use known names to help...
@handles << child if child.definition.name =~ /F.*POIGNEE/
end
# send it back to start like in 'Snakes and Ladders'
to_clean(child)
end # do
end # def
# we start and end here
def main
model = Sketchup.active_model
defs = model.definitions
ents = model.entities
lays = model.layers
mats = model.materials
sel = model.selection
# we create an array we can fill from outside this method
@to_go = []
# we can also 'collect' the handles
@handles = []
# we send the whole model to the cleaners
to_clean(model)
# create an operation before touching geometry
model.start_operation('cc_clean')
# to_clean(model) returns the array which we can erase
ents.erase_entities(@to_go)
# then we cleanup properly
[defs, lays, mats].each{|a| a.purge_unused}
# always close the operation
ensure model.commit_operation
# we can then do stuff with the handles in @ handles
# sel.add(@handles)
end
end
end
file = File.basename(__FILE__)
unless file_loaded?(file)
UI.menu('Plugins').add_item('Click Cuisine Cleaner') { ClickCuisine::Cleaner.main }
file_loaded(file)
end
# ClickCuisine::Cleaner.main
Does your code purge all hidden sub-components and dynamic attributes in SketchUp or am I mistaken?
My goal is to purge the selected components:
Method 1 - Activate all Click-Kitchen 2 Dynamic Parent Components using the definitions names:
def method1
["IKEA","PLAN BAR SUR PIEDS","TABLE SUR PIED"].each{|name|
match = /#{name}/i
m=Sketchup.active_model;
s=m.selection;
m.definitions.each{|d|s.add d.instances if d.name =~ match }}
end
Method 2 - Purge all dynamic attributes and hidden components in the selection.
### It's code that I want to write. :-(
Thus, users of Click-Cuisine 2, will not affect other components that have nothing to do with the Plugin.
To purge all the hidden components and dynamic attributes of the SketchUp file, I know this solution:
def erase_hidden_components
Sketchup.active_model.definitions.each{|d|d.entities.grep(Sketchup::ComponentInstance).each{|e|e.erase! if e.hidden?}}
end
def purge_dynamic_attributes
m=Sketchup.active_model;m.definitions.each{|d|d.attribute_dictionaries.delete("dynamic_attributes")
d.instances.each{|i|i.attribute_dictionaries.delete("dynamic_attributes")}}
end
erase_hidden_components
purge_dynamic_attributes
But I do not want to do that!
Tomorrow I will study your code better, because it is certain that I have things to learn.
will cause the code to look 3 times over the same thingsâŠ
you can do them all at once if you recall the code from earlier posts at SCFâŠ
names = Regexp.union("IKEA","PLAN BAR SUR PIEDS","TABLE SUR PIED")
tents.each do |child|
next unless child.definition.name =~ names
EDIT: in the version of C_C I have, you would be better with a single filter methodâŠ
hereâs a cut and paste test snippetâŠ
model = Sketchup.active_model
sel = model.selection
def davids(child)
dicts = child.definition.attribute_dictionaries
'david B.' == dicts['GSU_ContributorsInfo']['NicknamesKey'].first
rescue
false
end
end
# to test select other items then run
davids(sel[0])
when combined into the cleaner, correctly, you will then only destroy âyourâ named DCâsâŠ