sketchucation logo sketchucation
    • Login
    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!
    ⚠️ Important | Libfredo 15.6b introduces important bugfixes for Fredo's Extensions Update

    Count instances correctly

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 2 Posters 303 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

      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
      • Dan RathbunD Offline
        Dan Rathbun
        last edited by

        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

          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
          • First post
            Last post
          Buy SketchPlus
          Buy SUbD
          Buy WrapR
          Buy eBook
          Buy Modelur
          Buy Vertex Tools
          Buy SketchCuisine
          Buy FormFonts

          Advertisement