Remove dynamic attributes in ruby

Remove dynamic attributes in ruby

Postby TNTDAVID » Fri Nov 17, 2017 2:50 pm

Hello everyone :enlight:

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
0
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 !
User avatar
TNTDAVID 
PluginStore Author
PluginStore Author
 

Re: Remove dynamic attributes in ruby

Postby juju » Fri Nov 17, 2017 8:04 pm

0
Save the Earth, it's the only planet with chocolate.
User avatar
juju 
Premium Member
Premium Member
 

Re: Remove dynamic attributes in ruby

Postby 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
0
* Nouveau !!!
Découvrez notre nouveau Plugin Click-Cuisine 2, pour créer vos cuisines 3D !
User avatar
TNTDAVID 
PluginStore Author
PluginStore Author
 

Re: Remove dynamic attributes in ruby

Postby 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.
0
* Nouveau !!!
Découvrez notre nouveau Plugin Click-Cuisine 2, pour créer vos cuisines 3D !
User avatar
TNTDAVID 
PluginStore Author
PluginStore Author
 

Re: Remove dynamic attributes in ruby

Postby 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.
0
    I'm not here much anymore. But a PM will fire email notifications.
    User avatar
    Dan Rathbun 
    PluginStore Author
    PluginStore Author
     

    SketchUcation One-Liner Adverts

    by Ad Machine » 5 minutes ago



    Ad Machine 
    Robot
     



     

    Return to Developers' Forum

    Who is online

    Users browsing this forum: FigueroaMX and 4 guests

    Visit our sponsors: