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

    Count instances in selection???

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 3 Posters 178 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.
    • A Offline
      artofseeing
      last edited by

      hi all,
      i have a script where i am at one point helpless with a problem:

      its a script giving me a summary of weights.
      i have components with dynamic attributes "gewicht" (weight).
      i select a couple, then i get a dialog box with the following:

      number of selected items.
      total weight.

      then:

      number of item a - name of item a - single weight item a
      number of itemb - name of item b - single weight item b
      and so on...

      depending on how many things are in my selection.

      one part doesnt work though, that which i put in bold above.
      it doesnt show me the number of instances in my selection, as iwant, but
      it rather shows me the number of instances in my model.
      and i cant see the code for it.any body got some advice? thx alot 😄
      the problem is, where it says: "e.definition.count_instances"
      so basically i want: "e.definitions.count_instances" for my selection.
      here's the part of the code:

      
      
         
       name=[]
         ss.each{|e|
        
        
            if e.class==Sketchup;;ComponentInstance
              
      
             name=name+[e.definition.count_instances.to_s+ "x \t"+e.definition.name+ " \ta "+e.definition.get_attribute("dynamic_attributes","gewicht",0)+" kg"+"\n"]
         
              end
             
                
          }
      
      
       
         
      

      as long as there is a voyage away, there's always a journey back...

      http://artofseeing.carbonmade.com

      1 Reply Last reply Reply Quote 0
      • C Offline
        cjthompson
        last edited by

        My initial thought would be:

        numSelectedInstances = (e.definition.instances & ss.to_a).length # & intersects two arrays
        

        You'll probably want to stick around and see what the others say.

        1 Reply Last reply Reply Quote 0
        • TIGT Offline
          TIG Moderator
          last edited by

          You want to count the instances in a selection...

          
          counts=[]
          ss.each{|e|counts<< e.definition if e.class==Sketchup;;ComponentInstance}
          countsuniq=counts.uniq
          compocount=[]
          countsuniq.each{|e|
            count=0
            counts.each{|c|count+=1 if c==e}
            compocount<< [e.name, count]
          }
          ### compocount is an array, with each item as an array of the instance's definition.name [you could change it to just the definition itself 'e' ?] and then its number of instances as counted in the selection (ss)...
          
          

          TIG

          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