Mason
May 28, 2019, 8:38pm
1
Is there a command to run or script that will automatically flip the “fit text” of a dimension from auto to either left or right so it doesnt interfere with adjacent dimensions. Due to the way Rhino6 now displays dimensions, all of our annotation styles have had to be rewritten and now it either overlaps adjacent dimensions or when it pulls the dim from a command, it drops arbitrarily to either side. I have to then select each dim and scroll down in the properties panel and change the text fit on each dim.
If there is a command associated with this property, it could be written into a macro to change the property on multiple selections.
pascal
(Pascal Golay)
May 28, 2019, 9:00pm
2
Hello - here is a quick script that may do what you want-
import rhinoscriptsyntax as rs
import Rhino
import scriptcontext as sc
def DimForceLeft():
def dim_filter(rhino_object, geometry, component_index):
if isinstance(rhino_object, Rhino.DocObjects.LinearDimensionObject):
return True
return False
id = rs.GetObject("Select a dimemsion to force left", filter = 512, preselect=True , custom_filter = dim_filter)
obj = rs.coercerhinoobject(id)
geo = obj.Geometry
geo.ForceTextPosition = Rhino.Geometry.Dimension.ForceText.Left
obj.CommitChanges()
sc.doc.Views.Redraw()
pass
if __name__ == '__main__':DimForceLeft()
To use the Python script use RunPythonScript
, or a macro:
_-RunPythonScript "Full path to py file inside double-quotes"
If you change the ‘Left’ where ever it turns up to ‘Right’ or ‘Auto’ you can make the orthers - shout if you need help with that…
Mason
May 28, 2019, 9:14pm
3
can you run a check in Python to see if a dim has been pulled out to the side and would need to be forced left or right?
In R5, the dimension style would pull our small fractional dimensions inside the arrows, and then above. Is there a way to script this?
pascal
(Pascal Golay)
May 28, 2019, 9:20pm
4
Hello - DimRecenterText
may help - resets a moved dimension text - but I am not sure I know what you mean.
-Pascal
Mason
September 19, 2019, 7:54pm
5
this is what i get when i try to use this code in a python script after copy/paste into a new .py file.
any idea what i need to add to the code to fix?
pascal
(Pascal Golay)
September 19, 2019, 7:58pm
6
Hello - I edited the snippet above - it needed some import statements at the top
import rhinoscriptsyntax as rs
import Rhino
import scriptcontext as sc
-Pascal
Mason
November 14, 2019, 2:22pm
7
@pascal
With one of the recent release candidate updates, this script seems to be broken.
When running the script, it doesnt give an error but it has no effect on the selected dimension.
Also, is there a way to have 1 script with directional subfunctions ( L for Left, R for Right, A for Auto, I for Inside, etc.) ?
pascal
(Pascal Golay)
December 23, 2019, 4:44pm
9
Hello - I see - it looks like some functions changed with 6.20… see how this one works
import rhinoscriptsyntax as rs
import Rhino
import scriptcontext as sc
def DimForcer():
settingList = ['Auto', 'Left','Right', 'Inside']
fitList = [Rhino.DocObjects.DimensionStyle.TextFit.Auto,
Rhino.DocObjects.DimensionStyle.TextFit.TextLeft,
Rhino.DocObjects.DimensionStyle.TextFit.TextRight,
Rhino.DocObjects.DimensionStyle.TextFit.TextInside]
def dim_filter(rhino_object, geometry, component_index):
if isinstance(rhino_object, Rhino.DocObjects.LinearDimensionObject):
return True
return False
while True:
idx = 0
if sc.sticky.has_key('DIM_FORCE'):
idx = sc.sticky['DIM_FORCE']
go = Rhino.Input.Custom.GetObject()
go.SetCustomGeometryFilter (dim_filter)
go.AddOptionList("Force", settingList, idx)
go.EnablePreSelect(False, False)
go.SetCommandPrompt("Select a linear dimension")
rc = go.Get()
if go.CommandResult()!=Rhino.Commands.Result.Success:
return
if rc == Rhino.Input.GetResult.Object:
obj = go.Object(0)
if rc == Rhino.Input.GetResult.Option:
idx= go.Option().CurrentListOptionIndex
sc.sticky['DIM_FORCE']= idx
continue
rObj = obj.Object()
geo = rObj.Geometry
geo.TextFit = fitList[idx]
rObj.CommitChanges()
sc.doc.Views.Redraw()
if __name__ == '__main__':DimForcer()
-Pascal
Mason
May 11, 2020, 1:09pm
10
I think something else changed in the most recent update, this script had been working fine up until the latest update candidate, but now,
thanks for anything you can do.
pascal
(Pascal Golay)
May 11, 2020, 3:20pm
11
Hello - it looks like maybe you accidentally added a “\” character to the beginning of the script - if you take that out in a text editor or EditPythonScript, or just grab the code again from above, I think it ought to work.
-Pascal