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

Clean Dynamic Components

Scheduled Pinned Locked Moved Developers' Forum
6 Posts 3 Posters 618 Views 3 Watching
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 7 Nov 2016, 13:44

    Hello to all. ☀

    The code below removes all the attributes of all Dynamic Components.

    m=Sketchup.active_model;m.start_operation("unDC");m.definitions.each{|d|d.attribute_dictionaries.delete("dynamic_attributes") if d.attribute_dictionaries and d.attribute_dictionaries["dynamic_attributes"];d.instances.each{|i|i.attribute_dictionaries.delete("dynamic_attributes") if i.attribute_dictionaries and i.attribute_dictionaries["dynamic_attributes"]}};m.commit_operation
    

    How to adapt the code to remove only the component attribute with the definition "Steve"?

    The aim is that all the definitions starting with "Steve" for example copy "Steve # 1", "Steve # 2",
    "Steve # 3" are concerned.

    Do not worry, I do not want nothing wrong with Steve, it's just an example. 💚

    -

    Another research topic, how to remove "sub-components" masked?

    This removal should cover only those components with the definition "Steve" "Steve# 1", Steve#2 "," Steve#3 "...

    Thank you in advance for your help.

    Cordially

    David Barros

    [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 7 Nov 2016, 20:34

      See this thread in the official "Ruby API" forums:

      Selecting Specific Entity, Group or Component (By Name)

      I'm not here much anymore.

      1 Reply Last reply Reply Quote 0
      • T Offline
        TNTDAVID
        last edited by 7 Nov 2016, 23:49

        Thank you Dan for the link. 😉

        Here is the method to select all instances that begins with the definition "Steve":

        n="Steve";m=Sketchup.active_model;s=m.selection;s.clear;m.definitions.each{|d|s.add d.instances if d.name=~/#{n}/}
        

        Note, Steve can be replaced by any other name.

        How to combine these two codes, to remove all the dynamic attributes of steve component?

        m=Sketchup.active_model;m.start_operation("unDC");m.definitions.each{|d|d.attribute_dictionaries.delete("dynamic_attributes") if d.attribute_dictionaries and d.attribute_dictionaries["dynamic_attributes"];d.instances.each{|i|i.attribute_dictionaries.delete("dynamic_attributes") if i.attribute_dictionaries and i.attribute_dictionaries["dynamic_attributes"]}};m.commit_operation
        
        n="Steve";m=Sketchup.active_model;s=m.selection;s.clear;m.definitions.each{|d|s.add d.instances if d.name=~/#{n}/}
        

        Thank you in advance for your help.

        David

        [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 8 Nov 2016, 01:26

          The formula still more simplified:

          m=Sketchup.active_model;s=m.selection;m.definitions.each{|d|s.add d.instances if d.name=~/#{"Steve"}/}
          

          It activates all the instances that start with "Steve" in Sketchup.

          How to select only the "Steve" in an active component?

          The answer to this question is very important to me!

          Thank you to all those who will want to help me.

          David

          [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 8 Nov 2016, 15:47

            Don't use the selection. Use an array. Then use one of the Array class' iteration methods.

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • T Offline
              TIG Moderator
              last edited by 8 Nov 2016, 16:25

              Learn to use regular expression matching...
              Dan has provided many useful links to basic Ruby usage...

              d.name=~/Steve/

              matches 'Steve', 'Some Steve', 'Steve#1' etc
              BUT not 'steve' etc

              d.name=~/[Ss]teve/

              matches 'Steve', 'steve' etc

              To limit the match to a start position use
              d.name=~/^Steve/

              matches 'Steve', 'Steve#1' etc
              BUT not 'Some Steve' etc

              To limit the match to an and position use
              d.name=~/Steve$/

              matches 'Steve', 'Some Steve' etc
              BUT not 'Steve#1' etc

              To limit it to an exact match use
              d.name=~/^Steve$/

              matches 'Steve' only, nothing else
              note that is actually equivalent to
              d.name=="Steve"

              TIG

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

              Advertisement