I’m working on an extension that manipulates dimensions. One thing I would like to do is to be able to identify whether a DimensionRadial is a diameter or radius type, and to change it back and forth. Sort of like the “Type” context menu for these dimensions does.
Nothing I could find in the Ruby API docs says how to do this. Is there some sort of “off menu” method for this?
I don’t think you can change via Ruby directly, I guess it is not there (?)
Basically, when you create it, It depends on the arc_curve object to which this dimension is attached.
__
Two methods come to mind to examine if it is already there.
The first one examines the #text (String) associated with the dimension - it may be language-dependent, or it may have been changed manually - so it’s not very certain.
If the string starts with “R” then it is radius if start with “DIA” it is Diameter.
The second examines the #arc_curve (ArcCurve object) to which this dimension is attached.
Check if the ArcCurve is circle or not. After SU2023.1 you can use: #circular? method. The dim is diameter if it is circle otherwise radius.
Perhaps you need to combine them…
_
To change it you may need to do a “hack”, I mean “extend” or “reduce” the associated arc curve to full circle or vice-versa, and redraw the dim by the Entities #add_dimension_radial method… so, it will create a R if non full circle, and DIA if it is full.
Yes, I’m using the ‘text’ method now, though I don’t much like it for the reasons you state.
And ‘circular’ is sort of helpful, but you CAN have a radius dimension on a circle, so it doesn’t cover every possible case.
I may also experiment with the dimension’s bounding box, see if that can yield something useful…
Really, the dimension type should be accessible from the API. It’s a pretty major attribute after all!
So I figured out how to tell them apart, but not how to change them from one to the other.
If anybody’s interested, here’s how to tell them apart:
A diameter type dimension touches the arc at two points, the ‘attach point’ and the ‘opposite point’. A radius type dimension only touches the arc at its attach point. It has an opposite point, but it doesn’t use it.
This means that the opposite point will always be at one corner of a diameter dimension’s bounding box, and virtually never for a radius dimension.
Now, if I could only figure out how to change one type to the other…
FYI: There is a lack of parity here.
The C API has both a setter and getter for the diameter | radius state.
Thanks, Dan!
I guess there’s another feature request for the Ruby API…
Last night I checked for a send_action automation integer, but realized that it is only going to be active (usable) when that specific context submenu is being displayed. (I.e., the command ID is generated “on-the-fly” when the context submenu is opened.)
The fastest way to toggle between the states, is to select a radial dimension, open the Preferences dialog, switch to the Shortcuts panel, then filter by "Type"
and assign a shortcut to each type. (This cannot be done with an extension as it is a user preference.)
But once a shortcut is assigned and extension can send keystrokes to the system to fire a shortcut.
I’ve posted many times in this category how to use the WSH’s SendKeys
method.
Here is one …
Use the ruby code to simulate a mouse click on the sub-menu in menu - #7 by DanRathbun
.. and another …
How's possible to minimize an extension window? - #2 by DanRathbun
For now, … if you are coding toolbar buttons, your extension would need to tell the user to assign shortcuts, and then you’d either have them enter the shortcuts into an inputbox
or see if you can snag it thusly …
def find_dim_shortcut(type)
shortcuts = Sketchup.get_shortcuts
shortcut = shortcuts.find {|combo| combo =~ /Edit\/Item\/Type\/#{type}\Z/ }
return nil unless shortcut
keychord = shortcut.split("\t").first
end
Ie …
dia = find_dim_shortcut('Diameter')
#=> "Ctrl+F12"
I as a test assigned “Diameter” to CTRL+F12.
So, for my machine to toggle to Diameter:
shell.SendKeys("^{F12}")`
Once you get the keychords, depending upon platform you can convert them to what is needed for SendKeys
on Windows or perhaps an AppleScript command via system()
. I remember that @john_drivenupthewall was very fond of using cliclick
utility on Mac. There is also supposed to be a sendkeys-macos
utility. Neither are likely to be natively installed. So AppleScript may be the best.