• Login
sketchucation logo sketchucation
  • Login
๐Ÿค‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

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 24 Apr 2016, 14:26

    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
    • T Offline
      TIG Moderator
      last edited by 24 Apr 2016, 17:29

      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 24 Apr 2016, 18:03

        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
        • R Offline
          Rich O Brien Moderator
          last edited by 24 Apr 2016, 19:27

          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 24 Apr 2016, 20:26

            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 24 Apr 2016, 22:04

              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 25 Apr 2016, 09:08

                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
                • T Offline
                  TIG Moderator
                  last edited by 25 Apr 2016, 09:48

                  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 25 Apr 2016, 11:34

                    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
                    • T Offline
                      TIG Moderator
                      last edited by 25 Apr 2016, 15:36

                      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 25 Apr 2016, 16:05

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

                        Advertisement