sketchucation logo sketchucation
    • Login
    1. Home
    2. TNTDAVID
    3. Posts
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    🛣️ Road Profile Builder | Generate roads, curbs and pavements easily Download
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 99
    • Posts 736
    • Groups 2

    Posts

    Recent Best Controversial
    • Remove dynamic attributes in ruby

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

      posted in Developers' Forum
      TNTDAVIDT
      TNTDAVID
    • RE: Activate last selection

      Thank you for your help! ☀
      I will analyze the Selection Memory Plugin and post the method if I find it.

      posted in Developers' Forum
      TNTDAVIDT
      TNTDAVID
    • RE: Sketchup 2018 ???

      @pilou said:

      je dirais 90 % de version free pour 10 % de version Pro!

      C'est très inquiétant!

      posted in Français
      TNTDAVIDT
      TNTDAVID
    • RE: Sketchup 2018 ???

      Afficher le prix des composants n'est pas mal comme nouveauté pour les PRO!

      Il serait peut-être mieux de renommer la version gratuite en suppriment 2017?

      Psychologiquement les utilisateurs n'aiment pas utiliser des versions périmés et peuvent fuir SketchUp!

      J'espère qu'ils vont cartonner avec la version Gratuite en ligne et permettre un jours d'installer les Plugins proposé par la communauté de développeurs.

      posted in Français
      TNTDAVIDT
      TNTDAVID
    • RE: Sketchup 2018 ???

      Je pense qu'il est plus simple de télécharger Sketchup 2018 sur cette page:

      https://www.sketchup.com/fr/download/all#fr

      La version pro 2018 ne devient pas free après la période d'essai?

      posted in Français
      TNTDAVIDT
      TNTDAVID
    • RE: Science sans conscience...

      Tout est conscience. ☀

      posted in Français
      TNTDAVIDT
      TNTDAVID
    • Activate last selection

      Hello everyone! ☀

      Can I activate a previous selection in a method?

      For example:

      • I select a piece of furniture in SketchUp.

      • I activate a method that selects handles that are sub-components.

      • Subsequently, it disables the furniture selection.

      • Another method changes the Handles.

      • Can we then reactivate the furniture selection?

      If so, how should I proceed?

      Thank you

      posted in Developers' Forum
      TNTDAVIDT
      TNTDAVID
    • RE: Remove and purge hidden components.

      **They always told me to be persistent and I thank all those who gave me this advice. 😄

      Here is the method to remove all hidden sub-components in a parent component:

      
      def supprimer_tous_les_sous_composants_selection(instance)
          children = instance.definition.entities.select { |e| e.respond_to?(;definition) }
          children.each { |c| supprimer_tous_les_sous_composants_selection(c);
          c.erase! if c.hidden?
          }
          end
      	
          supprimer_tous_les_sous_composants_selection(Sketchup.active_model.selection.first)
      

      Here is the method to remove all the dynamic attributes of all the components present in a selection:

      
      def selectionner_tous_les_sous_composants_selection(instance)
          children = instance.definition.entities.select { |e| e.respond_to?(;definition) }
          instance.model.selection.add(children)
          children.each { |c| selectionner_tous_les_sous_composants_selection(c);
          }
          end	
      	
      def supprimer_tous_les_attributs_dynamiques_selection
          mod = Sketchup.active_model
          sel = mod.selection
          sel.each{|s|s.definition.attribute_dictionaries.delete("dynamic_attributes");
        sel.grep(Sketchup;;ComponentInstance).each{|i|i.attribute_dictionaries.delete("dynamic_attributes")}}
          end	
      	
      def desactiver_toutes_les_selections
          mod = Sketchup.active_model
          ent = mod.active_entities
          sel = mod.selection
          instances = sel.grep(Sketchup;;ComponentInstance)
          sel.clear
          end		
      	
      selectionner_tous_les_sous_composants_selection(Sketchup.active_model.selection.first)
      supprimer_tous_les_attributs_dynamiques_selection
      desactiver_toutes_les_selections
      
      

      You can test these methods directly with the ruby console, after selecting a dynamic component.

      You will notice that all hidden components and dynamic attributes will be removed, even if they are nested at multiple levels.

      Thank you to everyone who helped me. 😉

      See you

      David**

      posted in Developers' Forum
      TNTDAVIDT
      TNTDAVID
    • RE: Remove and purge hidden components.

      **I can select all the definitions by their names and apply a cleaning of hidden components:

      
      def methode1 ### select components and sub-components with the name of the definitions.	
          ["IKEA","DOOR","DRAWER","HANDLES"].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	
      	
      def methode2 ### remove hidden components in the selection		
          Sketchup.active_model.selection.grep(Sketchup;;ComponentInstance).each{|s|
          s.definition.entities.grep(Sketchup;;ComponentInstance).each{|e|e.erase! if e.hidden?}}
          end
      		
      def methode_end 
          methode1
          methode2	
          end
      

      I'm progressing but this solution is not great. 😕

      Any help would be highly appreciated.**

      posted in Developers' Forum
      TNTDAVIDT
      TNTDAVID
    • RE: Remove and purge hidden components.

      **I finally found how to remove hidden sub-components from a selection:

      mod = Sketchup.active_model
      sel = mod.selection
      sel.grep(Sketchup;;ComponentInstance).each{|s|;
      s.definition.entities.grep(Sketchup;;ComponentInstance).each{|e|e.erase! if e.hidden?}}
      

      The problem is that only the first level of nesting is removed by the method.

      I will continue to search in esperente found the solution.

      See you

      David**

      posted in Developers' Forum
      TNTDAVIDT
      TNTDAVID
    • RE: Remove and purge hidden components.

      **Little reminder:

      It is possible to remove all hidden components of a SketchUp file, with this method:

      Sketchup.active_model.definitions.each{|d|d.entities.grep(Sketchup;;ComponentInstance).each{|e|e.erase! if e.hidden?}}
      

      It is possible to remove all hidden components with the name of a definition, with this method:

      Sketchup.active_model.definitions.each{|d|next unless d.name=~/IKEA/; d.entities.grep(Sketchup;;ComponentInstance).each{|e|e.erase! if e.hidden?}}
      

      How to remove all hidden components and sub-components in a selection?

      Thank you

      David**

      posted in Developers' Forum
      TNTDAVIDT
      TNTDAVID
    • RE: Remove and purge hidden components.

      **Bonjour,

      Votre solution TIG pour supprimer les composants masqués à l'intérieur des définition IKEA, fonctionne très bien! 😉

      Sketchup.active_model.definitions.each{|d|next unless d.name=~/IKEA/; d.entities.grep(Sketchup;;ComponentInstance).each{|e|e.erase! if e.hidden?}}
      

      A l'intérieur de la définition IKEA, il y a beaucoup d'autres définitions qui ont des sous composants masqués.

      Est-il possible de supprimer tous les composants masqués pour toutes les définitions présentes dans les meubles IKEA ?

      L'idéal serait de na pas avoir à citer toutes les définitions existant dans les meubles IKEA.

      Merci**

      posted in Developers' Forum
      TNTDAVIDT
      TNTDAVID
    • RE: Redraw a dynamic component

      **I ended up bypassing the problem by selecting a different definition than "handles" in method 2.

      I asked to select the IKEA definition, which corresponds to the furniture that contains the facades and the handle inside.

      
      def ikeaCI(ents)
          sel = Sketchup.active_model.selection
          ents.each do |e|
       if e.is_a? Sketchup;;ComponentInstance
          sel.add e if e.definition.name=~/#{"IKEA"}/
          ikeaCI(e.definition.entities)
          end
          end
          end	
      
      

      This is possible because I specified the definition of the highest components of the hierachie.

      Is it possible to select the highest components of the hierarchy without specifying the name of that definition?

      Thank you TIG for your method that allows me to redraw the visible handles. 👍**

      posted in Developers' Forum
      TNTDAVIDT
      TNTDAVID
    • RE: Redraw a dynamic component

      **I solved the problem of my previous post!

      Now, I'm facing another problem that is much more difficult to solve.

      The code below adds an attribute to all the "Handles" definitions that are visible in the components being selected.

      
      def handlesCI(ents)
          sel = Sketchup.active_model.selection
          ents.each do |e|
          if e.is_a? Sketchup;;ComponentInstance
          sel.add e if e.definition.name=~/#{"HANDLES"}/
          handlesCI(e.definition.entities)
          sel.grep(Sketchup;;ComponentInstance){|i|
          next unless i.visible?
          i.set_attribute 'dynamic_attributes','attribut', '1'
          }
          end
          end
          end
      

      This method does not work to refresh only visible components.

      
      def handlesCI(ents)
          sel = Sketchup.active_model.selection
          ents.each do |e|
          if e.is_a? Sketchup;;ComponentInstance
          sel.add e if e.definition.name=~/#{"HANDLES"}/
          handlesCI(e.definition.entities)
          sel.grep(Sketchup;;ComponentInstance){|i|
          next unless i.visible?
          $dc_observers.get_latest_class.redraw_with_undo(i)
          }
          end
          end
          end
      

      I need your help to understand the problem.

      Thank you

      David**

      posted in Developers' Forum
      TNTDAVIDT
      TNTDAVID
    • RE: Redraw a dynamic component

      **Here I am in a paradox!

      If I apply your TIG method, the handles selected in Method 2 will also be redrawn.

       
      def methodeTIG(ents)
          sel = Sketchup.active_model.selection
          array = []
          ents.grep(Sketchup;;ComponentInstance).each{|e| ### collect only visible instances
          next unless e.visible?
          array << e if e.definition.name =~ /#{"HANDLES"}/
          methodeTIG(e.definition.entities) ### repeat for nested entities in visibles
          }
          array.each{|i| ### process this array of instances
          $dc_observers.get_latest_class.redraw_with_undo(i)
          }
          end  	  
      
      def methode2(ents)
          sel = Sketchup.active_model.selection
          ents.each do |e|
          if e.is_a? Sketchup;;ComponentInstance
          sel.add e if e.definition.name=~/#{"HANDLES"}/
          methode2(e.definition.entities)
          end
          end
          end
      
      def methode_end
          methodeTIG(instances)
          methode2(instances) ### The handles of this method are drawn by the methodTIG! 
          end
      
      
      

      How can I avoid this?

      Thank you**

      posted in Developers' Forum
      TNTDAVIDT
      TNTDAVID
    • RE: Redraw a dynamic component

      **Your method works TIG, but it does not keep the "Handles" definitions selected.

      The goal is to update all Invisible Handles, then select any definition "Handles" without visibility restrictions.**

      posted in Developers' Forum
      TNTDAVIDT
      TNTDAVID
    • RE: Redraw a dynamic component

      **Hello, ☀

      I now want to refresh the visible dynamic components.

      If not, the answer must be "nil".

      The methde below works for components that are not nested:

      m=Sketchup.active_model;
      s=m.selection;
      m.definitions.each{|d|s.add d.instances if d.name=~/#{"BOUTON"}/}
      s.grep(Sketchup;;ComponentInstance){|i|
      next if i.hidden?
      $dc_observers.get_latest_class.redraw_with_undo(i)
      }
      

      Oddly if the components with the "BOUTON" definitions, are nested in another component, they will be considered as visible even if they are hidden.

      Do you know what is the problem?

      Thank you**

      posted in Developers' Forum
      TNTDAVIDT
      TNTDAVID
    • RE: Redraw a dynamic component

      **OK TIG, I understand!

      The Ruby is very wide and has many instructions such as:

      !,&&,||,and,box,else,elsif,eql?,equal,if,then,not,gold,require,unless,wheen,true, false...

      I had not yet read "unless".

      I realize that it takes many years of Ruby to totally understand him master it.

      As I learn according to my needs, this undoubtedly slows down my general understanding of ruby.

      Promised, next time I would make more effort with your examples before publishing it does not work. 😉

      Ps: Your solution works wonderfully TIG

      Thanks a lot for your help.

      David**

      posted in Developers' Forum
      TNTDAVIDT
      TNTDAVID
    • RE: Redraw a dynamic component

      This still does not work for components without attributes:

      Sketchup.active_model.selection.grep(Sketchup;;ComponentInstance){|i|
      next unless i.definition.attribute_dictionaries["dynamic_attributes"]
      i.definition.set_attribute('dynamic_attributes', 'teste', '1')
      $dc_observers.get_latest_class.redraw_with_undo(i)
      }
      
      posted in Developers' Forum
      TNTDAVIDT
      TNTDAVID
    • RE: Redraw a dynamic component

      **Sorry TIG for not having specified the method used.

      I tried these 2 methods:

      Sketchup.active_model.selection.grep(Sketchup;;ComponentInstance){|i|
      next unless i.definition.attribute_dictionaries["dynamic_attributes"]
      i.set_attribute 'dynamic_attributes','teste', '1'
      $dc_observers.get_latest_class.redraw_with_undo(i)
      }
      

      Sketchup.active_model.selection.grep(Sketchup;;ComponentInstance){|i|
      next unless i.definition.attribute_dictionaries["dynamic_attributes"]
      i.set_attribute("dynamic_attributes", "test", "1")
      i.attribute_dictionaries["dynamic_attributes"]
      $dc_observers.get_latest_class.redraw_with_undo(i)
      }
      

      None of the 2 solutions work on a component without dynamic attributes.

      @unknownuser said:

      Error: #<NoMethodError: undefined method []' for nil:NilClass> <main>:1:in block in <main>'
      <main>:in each' <main>:in grep'
      <main>:in <main>' -e:1:in eval'
      nil

      But these 2 solutions work on components already have dynamic attributes.**

      posted in Developers' Forum
      TNTDAVIDT
      TNTDAVID
    • 1 / 1