• Login
sketchucation logo sketchucation
  • Login
ℹ️ GoFundMe | Our friend Gus Robatto needs some help in a challenging time Learn More

Adding dimensions from Ruby

Scheduled Pinned Locked Moved Developers' Forum
5 Posts 3 Posters 804 Views
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.
  • A Offline
    Al Hart
    last edited by 17 Feb 2008, 20:51

    I could swear I found this idea as part of another thread, but now I can't find it.

    The idea was to add dimensions to a model in Ruby by creating a component with a dimension in it and scaling it into place.

    The query in the "ghost" thread, was worrying about whether the arrows and leader lines would transform as well, and therefore you might need a few base dimension components so you wouldn't have to scale them too much.

    After some testing, and using a transform in the X-axis only:

     transformation = Geom;;Transformation.scaling(ploc, len/clen, 1, 1)
    
    (clen was then length of the dimension in the component)
    

    I found that I only needed one base component.

    This worked pretty well:

    dimensions.jpg

    (All the dimensions were added with a ruby routine. Ignore the yellow text in the middle)

    Al Hart

    http://wiki.renderplus.com/images/e/ef/Render_plus_colored30x30%29.PNG
    IRender nXt from Render Plus

    1 Reply Last reply Reply Quote 0
    • A Offline
      alexander
      last edited by 17 Feb 2008, 21:12

      Well that looks good sofar Al..
      should be a big timesaver..
      maybe in Metric ? and a dot instead ?

      1 Reply Last reply Reply Quote 0
      • A Offline
        Al Hart
        last edited by 17 Feb 2008, 21:54

        For metric all the user has to do is change the drawing units.

        dimensions2.jpg

        To change the font size, or the arrow you have to alter the original base dimension component

        Al Hart

        http://wiki.renderplus.com/images/e/ef/Render_plus_colored30x30%29.PNG
        IRender nXt from Render Plus

        1 Reply Last reply Reply Quote 0
        • T Offline
          TIG Moderator
          last edited by 17 Feb 2008, 22:31

          I think that was partially my idea... http://groups.google.com/group/Ruby-API/browse_thread/thread/ac8c752034f58b62/7a98e0e3acc3aae1?lnk=gst&q=dimension#7a98e0e3acc3aae1
          Well done to develop on it... it's only taken 'us' nearly two years !!!

          Is it to become a useful bit of code ?

          TIG

          1 Reply Last reply Reply Quote 0
          • A Offline
            Al Hart
            last edited by 18 Feb 2008, 01:18

            (I think that was the thread I was thinking of...)

            It doesn't qualify as a Ruby script because it depends on two pre-made components - one for horizontal dimensioning and one for vertical (you could rotate for the vertical, but I chose to place the vertical dimensioning outside the lines.)

            Also, the .rb files assume another routine to locate components. ($component_folder)

            But I will share the code if any other ruby developers want to use it.

            
            	def hdim(ploc, len)
            		model = Sketchup.active_model
            		entities = model.active_entities
            		sname = "CS_hdim-240"
            		clen = 240 # size of component in inches
            
            		# see if we have already loaded the component
            		definition = model.definitions[sname]
            		if (definition == nil)
            			skp_name = sprintf("%s\\%s.skp",$component_folder,sname)
            			definition = model.definitions.load(skp_name)
            		end#def
            		instance = entities.add_instance(definition, ploc)
            		transformation = Geom;;Transformation.scaling(ploc, len/clen, 1, 1)
            		instance.transform!(transformation)
            	end#def
            	
            	def vdim(ploc, len)
            		model = Sketchup.active_model
            		entities = model.active_entities
            		sname = "CS_vdim-240"
            		clen = 240 # size of component in inches
            
            		# see if we have already loaded the component
            		definition = model.definitions[sname]
            		if (definition == nil)
            			skp_name = sprintf("%s\\%s.skp",$component_folder,sname)
            			definition = model.definitions.load(skp_name)
            		end#def
            		instance = entities.add_instance(definition, ploc)
            		transformation = Geom;;Transformation.scaling(ploc, 1, len/clen, 1)
            		instance.transform!(transformation)
            	end#def
            
            

            Let me know if you want to components as well. They both have the dimension lines pointing to 0,0.

            Al Hart

            http://wiki.renderplus.com/images/e/ef/Render_plus_colored30x30%29.PNG
            IRender nXt from Render Plus

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

            Advertisement