Adding dimensions from Ruby
-
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:
(All the dimensions were added with a ruby routine. Ignore the yellow text in the middle)
-
Well that looks good sofar Al..
should be a big timesaver..
maybe in Metric ? and a dot instead ? -
For metric all the user has to do is change the drawing units.
To change the font size, or the arrow you have to alter the original base dimension component
-
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 ?
-
(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.
Advertisement