sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Component inst to component Def in a Selection

    Scheduled Pinned Locked Moved Developers' Forum
    5 Posts 3 Posters 399 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.
    • M Offline
      Matt666
      last edited by

      Hi all !

      When you make a loop to a selection with component instances inside, the loop pass on all component instances.
      We can save some time : Replacing Comp inst by Comp definitions in the selection before looping on it.
      Here is a code that returns an array of the selection with component instances replaced by their component definitions. Naturally, component definitions in the array are uniq.

      class Sketchup;;Entities
      	def InstancesToDefinitions
      		lst = []
      		ci = self.select{|c|c.typename == "ComponentInstance"}
      		ci.each{|e|lst.push e.definition}
      		return (lst+(self.to_a-ci)).uniq
      	end
      end
      
      class Sketchup;;Selection
      	def InstancesToDefinitions
      		lst = []
      		ci = self.select{|c|c.typename == "ComponentInstance"}
      		ci.each{|e|lst.push e.definition}
      		return (lst+(self.to_a-ci)).uniq
      	end
      end
      

      Try to save a few time with ruby 😉

      Frenglish at its best !
      My scripts

      1 Reply Last reply Reply Quote 0
      • Didier BurD Offline
        Didier Bur
        last edited by

        Hi,

        What's that for ?
        Désolé, mais à quoi ça sert ?

        DB

        1 Reply Last reply Reply Quote 0
        • M Offline
          Matt666
          last edited by

          Salut Didier !

          Cette fonction sert à faire gagner du temps de travail dans les boucles sur les entités.
          Par exemple, tu as 100 instances d'un même composant parmi une sélection de 150 entités.
          Et bien cette fonction remplace les instances par la définition du composant dans la sélection. Donc tu n'as plus qu'une sélection de 50 entités, + 1 définition de composant.

          This function affords to save some working time on entities loops. It replaces instances by the component definition in the selection.
          For example, you have 100 instances from just one component into a 150 entities selection. So, your selection counts 50 entities (100-50) + 1 component definition !

          Est-ce plus clair ? Y vois-tu une utilité ? Dis moi ce que tu en penses !
          Tell me your opinions about it, please!
          😄

          Frenglish at its best !
          My scripts

          1 Reply Last reply Reply Quote 0
          • Didier BurD Offline
            Didier Bur
            last edited by

            😲 😒

            DB

            1 Reply Last reply Reply Quote 0
            • P Offline
              Pout
              last edited by

              Looks interesting.
              I think i can use this in a loop we have analyzes all objects and can contain several instances.
              Thx 😄

              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