• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Remove dynamic attributes in ruby

Scheduled Pinned Locked Moved Developers' Forum
5 Posts 3 Posters 2.5k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    TNTDAVID
    last edited by TNTDAVID 17 Nov 2017, 13:50

    **Hello everyone ☀

    edit:

    To add a dynamic attribute to all instances in SketchUp, proceed as follows:

    
    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:

    
    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**

    [b:8wt9py2i]* Nouveau !!![/b:8wt9py2i] Découvrez notre nouveau Plugin [url=http://www.composant-dynamique.com/:8wt9py2i][color=#40FF00:8wt9py2i]C[/color:8wt9py2i][color=#77FF00:8wt9py2i]l[/color:8wt9py2i][color=#ADFF00:8wt9py2i]i[/color:8wt9py2i][color=#E4FF00:8wt9py2i]c[/color:8wt9py2i][color=#FFDB09:8wt9py2i]k[/color:8wt9py2i][color=#FF921B:8wt9py2i]-[/color:8wt9py2i][color=#FF492E:8wt9py2i]C[/color:8wt9py2i][color=#FF0040:8wt9py2i]u[/color:8wt9py2i][color=#ED2577:8wt9py2i]i[/color:8wt9py2i][color=#DA49AD:8wt9py2i]s[/color:8wt9py2i][color=#C86EE4:8wt9py2i]i[/color:8wt9py2i][color=#AD77FF:8wt9py2i]n[/color:8wt9py2i][color=#8965FF:8wt9py2i]e[/color:8wt9py2i] [color=#4040FF:8wt9py2i]2[/color:8wt9py2i][/url:8wt9py2i], pour créer vos cuisines 3D !

    1 Reply Last reply Reply Quote 0
    • J Offline
      juju
      last edited by 17 Nov 2017, 19:04

      Eneroth De-DC-ify

      Save the Earth, it's the only planet with chocolate.

      1 Reply Last reply Reply Quote 0
      • T Offline
        TNTDAVID
        last edited by 17 Nov 2017, 19:52

        **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**

        [b:8wt9py2i]* Nouveau !!![/b:8wt9py2i] Découvrez notre nouveau Plugin [url=http://www.composant-dynamique.com/:8wt9py2i][color=#40FF00:8wt9py2i]C[/color:8wt9py2i][color=#77FF00:8wt9py2i]l[/color:8wt9py2i][color=#ADFF00:8wt9py2i]i[/color:8wt9py2i][color=#E4FF00:8wt9py2i]c[/color:8wt9py2i][color=#FFDB09:8wt9py2i]k[/color:8wt9py2i][color=#FF921B:8wt9py2i]-[/color:8wt9py2i][color=#FF492E:8wt9py2i]C[/color:8wt9py2i][color=#FF0040:8wt9py2i]u[/color:8wt9py2i][color=#ED2577:8wt9py2i]i[/color:8wt9py2i][color=#DA49AD:8wt9py2i]s[/color:8wt9py2i][color=#C86EE4:8wt9py2i]i[/color:8wt9py2i][color=#AD77FF:8wt9py2i]n[/color:8wt9py2i][color=#8965FF:8wt9py2i]e[/color:8wt9py2i] [color=#4040FF:8wt9py2i]2[/color:8wt9py2i][/url:8wt9py2i], pour créer vos cuisines 3D !

        1 Reply Last reply Reply Quote 0
        • T Offline
          TNTDAVID
          last edited by 19 Nov 2017, 14:06

          **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:

          
          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:

          
          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.**

          [b:8wt9py2i]* Nouveau !!![/b:8wt9py2i] Découvrez notre nouveau Plugin [url=http://www.composant-dynamique.com/:8wt9py2i][color=#40FF00:8wt9py2i]C[/color:8wt9py2i][color=#77FF00:8wt9py2i]l[/color:8wt9py2i][color=#ADFF00:8wt9py2i]i[/color:8wt9py2i][color=#E4FF00:8wt9py2i]c[/color:8wt9py2i][color=#FFDB09:8wt9py2i]k[/color:8wt9py2i][color=#FF921B:8wt9py2i]-[/color:8wt9py2i][color=#FF492E:8wt9py2i]C[/color:8wt9py2i][color=#FF0040:8wt9py2i]u[/color:8wt9py2i][color=#ED2577:8wt9py2i]i[/color:8wt9py2i][color=#DA49AD:8wt9py2i]s[/color:8wt9py2i][color=#C86EE4:8wt9py2i]i[/color:8wt9py2i][color=#AD77FF:8wt9py2i]n[/color:8wt9py2i][color=#8965FF:8wt9py2i]e[/color:8wt9py2i] [color=#4040FF:8wt9py2i]2[/color:8wt9py2i][/url:8wt9py2i], pour créer vos cuisines 3D !

          1 Reply Last reply Reply Quote 0
          • D Offline
            Dan Rathbun
            last edited by 2 Dec 2017, 05:29

            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:

            
            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.

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            Buy SketchPlus
            Buy SUbD
            Buy WrapR
            Buy eBook
            Buy Modelur
            Buy Vertex Tools
            Buy SketchCuisine
            Buy FormFonts

            Advertisement