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

    Need help with specific dimension plugin

    Scheduled Pinned Locked Moved Developers' Forum
    11 Posts 5 Posters 1.1k Views 5 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.
    • K Offline
      Ka6a
      last edited by

      Hi all.

      I'm not a Ruby programmer and having a headache with one simple question:
      Is it possible to create a plugin for making numbers of dimensions instead measurements?
      For examle: D1, D2, D3... etc

      Asking for help.
      Thanks in advance

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

        First add the dimension initially:
        http://www.sketchup.com/intl/en/developer/docs/ourdoc/entities#add_dimension_linear
        Or to modify an existing dim:
        http://www.sketchup.com/intl/en/developer/docs/ourdoc/dimensionlinear
        Then use:
        http://www.sketchup.com/intl/en/developer/docs/ourdoc/dimension#text=
        to edit what that dim's text actually says...

        TIG

        1 Reply Last reply Reply Quote 0
        • G Offline
          Garry K
          last edited by

          You can also do this with your text override.

          dimension.png

          dim.text = "D1\n<>"

          \n = means newline and puts the dimension on a second line
          <> = means include the model's units in with the dimension

          1 Reply Last reply Reply Quote 0
          • Rich O BrienR Offline
            Rich O Brien Moderator
            last edited by

            I like that tip Garry!

            Download the free D'oh Book for SketchUp 📖

            1 Reply Last reply Reply Quote 0
            • K Offline
              Ka6a
              last edited by

              Thank you guys for replying
              So, after titanic labour I have produced this:

              
              require 'sketchup.rb'
              SKETCHUP_CONSOLE.show
              UI.menu("Plugins").add_item("DimPlugin") {addim}
              def addim
                entities = Sketchup.active_model.entities
                dim = entities.add_dimension_linear [50, 10, 0], [100, 10, 0], [0, 20, 0]
               dim.text = "D1"
              end
              
              

              And questions:

              1. How can I choose points for a new dimension (like basic sketchup tool "Dimension" does)?
              2. How can I create multiple dimensions (D1, D2, D3... etc)?

              Thanks again...

              1 Reply Last reply Reply Quote 0
              • D Offline
                driven
                last edited by

                dimension first then try

                dims = Sketchup.active_model.entities.grep(Sketchup;;Dimension)
                i = 0
                dims.each do |d|
                i+=1
                d.text = "D#{i}"
                end
                

                it hard to do a sort, but maybe the order of dimensioning will be honoured...

                john

                learn from the mistakes of others, you may not live long enough to make them all yourself...

                1 Reply Last reply Reply Quote 0
                • K Offline
                  Ka6a
                  last edited by

                  Thank you! It works much better!

                  But I still need a way to pick two dimension's points.
                  Or another decision (if it easier):
                  I could make dimensions by default Sketchup tool, but then I would to replace all of them by my plugin.

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

                    You need to make a "Tool" in Ruby code.
                    This then allows you to pick two or three points etc.
                    http://www.sketchup.com/intl/en/developer/docs/ourdoc/tool

                    Look at the code in my 2dTools to make a Rectangle.
                    Points 1 and 2 would be the dimension start and end and point 3 could set the offset etc.
                    Obviously you don't use the add_line() method, you need this:
                    http://www.sketchup.com/intl/en/developer/docs/ourdoc/entities#add_dimension_linear

                    TIG

                    1 Reply Last reply Reply Quote 0
                    • K Offline
                      Ka6a
                      last edited by

                      Thanks for advice, TIG, but I already tried it... It's too hard code for my low programming skill.
                      Could you answer me:
                      Where can I find sketchup dimension tool code for try to edit it? (Is it possible?)
                      Or how could I solve my problem another way (maybe by replacing text in existing dimensions)?

                      My current "frankenstein"-code 😕 :

                      require 'sketchup.rb'
                      SKETCHUP_CONSOLE.show
                      UI.menu("Plugins").add_item("DimPlugin") {addim}
                      
                      def addim
                      entities = Sketchup.active_model.entities
                      dim = entities.add_dimension_linear [50, 10, 0], [100, 10, 0], [0, 20, 0]
                      dims = Sketchup.active_model.entities.grep(Sketchup;;Dimension)
                      i = 0
                      dims.each do |d|
                      i+=1
                      d.text = "D#{i}"
                      end
                      end
                      

                      Thanks again

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

                        You can't do much with native tools, except activate them using Sketchup.send_action()
                        To mimic the native tools you must use the Ruby API.
                        There are many methods.
                        Using the methods I suggested would allow you to make a tool of your own which placed dimensions by picking points etc...

                        @driven already gave you a way of editing existing dimensions' text...
                        http://sketchucation.com/forums/viewtopic.php?p=594206#p594206
                        It is applied to all available dimensions in the model, or could be adjusted to process just the selected ones...

                        TIG

                        1 Reply Last reply Reply Quote 0
                        • K Offline
                          Ka6a
                          last edited by

                          Oh, my! It works! Thank you guys so so much!
                          TIG you are a Ruby wizard! Thank you for your patience

                          So, here is my final result:

                          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