• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Ruby Script for Adding up length of Edges

Scheduled Pinned Locked Moved Developers' Forum
5 Posts 3 Posters 378 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.
  • D Offline
    digitecture
    last edited by 1 Aug 2013, 14:07

    I write a script to display the sum of a set of edges that a user has selected. I understand how to use ruby to get access to the selection set. I have not yet figured out how to get this sum of lengths. I would like to create in script a component that I can pass this value to that the user does not see in the viewport for listing through the SketchUp Generate report command.

    Any help will be appreciated thank you!

    One last question, is it possible to parse a layer for a specific set of entities like edges and the do the same as I described above?

    I have not found any ruby commands for parsing a specific layer for all edges contained in that set.

    Thank you,

    1 Reply Last reply Reply Quote 0
    • T Offline
      th3lurker
      last edited by 1 Aug 2013, 14:17

      Haven't rubied'in a while, so i'll have to remember the syntax, but until then:

      For each entity in selection array, if it's a sketchup edge, totalLength = totalLength + edge.length ?

      1 Reply Last reply Reply Quote 0
      • T Offline
        TIG Moderator
        last edited by 1 Aug 2013, 16:18

        You can only really parse through entities 'collections': model.entities/model.active_entities and group.entities/definition.entities AND model.selection...

        However, once you have a collected set from that, you can parse that set to find just the things on a certain layer, with a certain material etc...

        Recently the use of 'grep' has been found to speed up entity parsing significantly, I recommend you try it...
        So to find all groups in a selection use:
        gps=model.selection.grep(Sketchup::Group)
        Now 'gps' is an array of all groups in the current selection.
        To find every selected group that's assigned layer 'XXX' use
        xxx=[]; gps.each{|gp| xxx << gp if gp.layer.name=='XXX' }

        If you want to find absolutely everything in the model using that layer, then:
        gps=model.entities.grep(Sketchup::Group)
        and process 'gps'...

        To get matches within a group use:
        gps=group.entities.grep(Sketchup::Group)
        and process 'gps'...

        To find everything in the model using a certain layer try:
        xxx=[]; model.entities.each{|e| xxx << e if e.layer.name=='XXX' }

        There are several alternative methods, like 'collect', but here I just show you make an empty array 'xxx=[]' and then we add to it using 'push' [<<] when we get a match...

        TIG

        1 Reply Last reply Reply Quote 0
        • D Offline
          digitecture
          last edited by 2 Aug 2013, 17:59

          @th3lurker said:

          Haven't rubied'in a while, so i'll have to remember the syntax, but until then:

          For each entity in selection array, if it's a sketchup edge, totalLength = totalLength + edge.length ?

          Thank you for this bit of information - as I get this project rolling - I will post here the development of it.

          1 Reply Last reply Reply Quote 0
          • D Offline
            digitecture
            last edited by 2 Aug 2013, 18:13

            @tig said:

            You can only really parse through entities 'collections': model.entities/model.active_entities and group.entities/definition.entities AND model.selection...

            However, once you have a collected set from that, you can parse that set to find just the things on a certain layer, with a certain material etc...

            Recently the use of 'grep' has been found to speed up entity parsing significantly, I recommend you try it...
            So to find all groups in a selection use:
            gps=model.selection.grep(Sketchup::Group)
            Now 'gps' is an array of all groups in the current selection.
            To find every selected group that's assigned layer 'XXX' use
            xxx=[]; gps.each{|gp| xxx << gp if gp.layer.name=='XXX' }

            If you want to find absolutely everything in the model using that layer, then:
            gps=model.entities.grep(Sketchup::Group)
            and process 'gps'...

            To get matches within a group use:
            gps=group.entities.grep(Sketchup::Group)
            and process 'gps'...

            To find everything in the model using a certain layer try:
            xxx=[]; model.entities.each{|e| xxx << e if e.layer.name=='XXX' }

            There are several alternative methods, like 'collect', but here I just show you make an empty array 'xxx=[]' and then we add to it using 'push' [<<] when we get a match...

            Hello TIG,

            This is once again very helpful. I think I understand your examples to experiment a bit and report back what I develop using this information.

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            1 / 1
            • First post
              5/5
              Last post
            Buy SketchPlus
            Buy SUbD
            Buy WrapR
            Buy eBook
            Buy Modelur
            Buy Vertex Tools
            Buy SketchCuisine
            Buy FormFonts

            Advertisement