by TNTDAVID » Fri Nov 17, 2017 2:50 pm
Hello everyone
edit:
To add a dynamic attribute to all instances in SketchUp, proceed as follows:
- Code: Select all
def add_attribute mod = Sketchup.active_model mod.definitions.each do |d| d.instances.each do |i| d.set_attribute 'dynamic_attributes', 'lola','10' i.set_attribute 'dynamic_attributes', 'lola','10' end end end
add_attribute
To remove this attribute without affecting all the dictionary, you have to do like this:
- Code: Select all
def delete_attribute mod = Sketchup.active_model mod.definitions.each do |d| d.instances.each do |i| d.delete_attribute 'dynamic_attributes', 'lola' i.delete_attribute 'dynamic_attributes', 'lola' end end end
delete_attribute
If I change the value of the attributes manually on SketchUp, the deletion will no longer be possible!
How to get around the problem?
Thank you
Last edited by TNTDAVID on Sun Nov 19, 2017 3:09 pm, edited 1 time in total.
* Nouveau !!! Découvrez notre nouveau Plugin Click-Cuisine 2, pour créer vos cuisines 3D !
-

TNTDAVID
- PluginStore Author

-
- Posts: 732
- Joined: Thu Sep 20, 2012 9:11 am
- Location: Paris
- Name: TNTDAVID
- Operating system: Windows
- SketchUp version: 8
- License type: Pro
- SketchUp use: woodworking
- Level of SketchUp: Advanced
-
by juju » Fri Nov 17, 2017 8:04 pm
Save the Earth, it's the only planet with chocolate.
-

juju
- Premium Member

-
- Posts: 2741
- Joined: Mon Oct 22, 2007 1:45 pm
- Location: Durbanville, Cape Town, South Africa.
- Name: Juju
- Operating system: Windows
- SketchUp version: 2021
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Intermediate
by TNTDAVID » Fri Nov 17, 2017 8:52 pm
The opening of my TOPIC on the cleaning of dynamic components, motivated other developers to look into the problem.
The rb file is cripté thus impossible to read it.
In addition, this example does not answer the functions that I am currently looking for.
Thanks anyway juju
* Nouveau !!! Découvrez notre nouveau Plugin Click-Cuisine 2, pour créer vos cuisines 3D !
-

TNTDAVID
- PluginStore Author

-
- Posts: 732
- Joined: Thu Sep 20, 2012 9:11 am
- Location: Paris
- Name: TNTDAVID
- Operating system: Windows
- SketchUp version: 8
- License type: Pro
- SketchUp use: woodworking
- Level of SketchUp: Advanced
-
by TNTDAVID » Sun Nov 19, 2017 3:06 pm
I did not take the time to re-read my code and I was wrong in my examples!
To add a dynamic attribute to a selected component:
- Code: Select all
def add_attribute_in_selection mod = Sketchup.active_model sel = mod.selection sel.each do |s| s.set_attribute 'dynamic_attributes', 'lola','1' end end add_attribute_in_selection
And to remove it:
- Code: Select all
def delete_attribute_in_selection mod = Sketchup.active_model sel = mod.selection sel.each do |s| s.delete_attribute 'dynamic_attributes', 'lola' end end
delete_attribute_in_selection
My first example adds a dynamic attribute to all instances in SketchUp.
Sorry for this mistake for lack of attention!
ps: I still have not found how to remove a custom attribute created with SketchUp.
* Nouveau !!! Découvrez notre nouveau Plugin Click-Cuisine 2, pour créer vos cuisines 3D !
-

TNTDAVID
- PluginStore Author

-
- Posts: 732
- Joined: Thu Sep 20, 2012 9:11 am
- Location: Paris
- Name: TNTDAVID
- Operating system: Windows
- SketchUp version: 8
- License type: Pro
- SketchUp use: woodworking
- Level of SketchUp: Advanced
-
by Dan Rathbun » Sat Dec 02, 2017 6:29 am
David, why are using this crazy indentation ? Ruby uses 2 space indents, and all code at the same level must be at the same indent: - Code: Select all
def delete_attribute mod = Sketchup.active_model mod.definitions.each do |d| d.instances.each do |i| d.delete_attribute 'dynamic_attributes', 'lola' i.delete_attribute 'dynamic_attributes', 'lola' end end end
This way the beginning of blocks line up with the indent lines in code editors.
I'm not here much anymore. But a PM will fire email notifications.
-

Dan Rathbun
- PluginStore Author

-
- Posts: 5042
- Joined: Tue Oct 06, 2009 3:06 am
- Location: Florida, USA
- Name: Dan Rathbun
- Operating system: Windows
- SketchUp version: 2015
- License type: Pro
- SketchUp use: education
- Level of SketchUp: Advanced
by Ad Machine » 5 minutes ago
-
Ad Machine
- Robot
-
- Posts: 2012
-
Return to Developers' Forum
|