• Login
sketchucation logo sketchucation
  • Login
⚠️ Libfredo 15.4b | Minor release with bugfixes and improvements Update

Count instances correctly

Scheduled Pinned Locked Moved Developers' Forum
3 Posts 2 Posters 275 Views 2 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.
  • D Offline
    dacastror
    last edited by 18 Mar 2014, 18:46

    ins
    hi all, I would like to know how to count the number of instances of a definition, the "Entity Info" window appears correctly but definition.count_instances do not, is there anything in the API or somewhere to get this information? attached skp file with which I am doing tests

    instances.skp
    thank you very much in advance for the help
    (google translator)

    1 Reply Last reply Reply Quote 0
    • D Offline
      Dan Rathbun
      last edited by 18 Mar 2014, 19:23

      See how I did it in this plugin I wrote for Ash Scott:
      [Plugin] Multiple Component Edit Warning

      💭

      I'm not here much anymore.

      1 Reply Last reply Reply Quote 0
      • D Offline
        dacastror
        last edited by 18 Mar 2014, 23:22

        Thanks Dan, this can give me a hint, I'm testing with the definition given there, but in my testing model (instances.skp) gives me a wrong number of instances, sometimes less or sometimes more, I do not know if I'm misapplying the definition count_instances ()

        # you must have a selected instance
        def count_instances()
          num = 0
          if @editpath.size == 1
            i = @editpath.last
          else
            revpath = @editpath.reverse
            i = revpath.shift
          end
          if i.is_a?(Sketchup;;ComponentInstance)
            num = i.definition.instances.size
          elsif i.is_a?(Sketchup;;Group)
            num = i.entities.parent.instances.size
          end
          if @editpath.size > 1
            revpath.each {|i|
              if i.is_a?(Sketchup;;ComponentInstance)
                num = num * i.definition.instances.size
              elsif i.is_a?(Sketchup;;Group)
                num = num * i.entities.parent.instances.size
              end
            }
          end
          return num
        end
        
        mod = Sketchup.active_model 
        sel = mod.selection
        
        ruta = mod.active_path
        (ruta) ? (ruta[ruta.size] = sel[0]) ; (ruta = []; ruta[0] = sel[0])
        @editpath = ruta
        count_instances()
        
        1 Reply Last reply Reply Quote 0
        • 1 / 1
        1 / 1
        • First post
          1/3
          Last post
        Buy SketchPlus
        Buy SUbD
        Buy WrapR
        Buy eBook
        Buy Modelur
        Buy Vertex Tools
        Buy SketchCuisine
        Buy FormFonts

        Advertisement