Hi everybody. I have a polyline script but when it works it creates a lot of annotation styles. How to edit a script to measure curves and lines and not create more annotation stylesDimClosedPolylines.py (1.7 KB)
rs.AddDimStyle() will add a new style every time. Try looking for your style before creating a new one. Use the FindName function of the document DimStyle table:
def CreateDimStyle(textHeight):
dimStyle_name = "MyDim"
# look for a dimension style of same name
dimStyle = sc.doc.DimStyles.FindName(dimStyle_name)
# if no style with same name then make one
if not dimStyle:
dimStyle = rs.AddDimStyle(dimStyle_name)
rs.DimStyleTextHeight(dimStyle,textHeight)
rs.DimStyleArrowSize(dimStyle,textHeight)
# return the found or new dim style
return dimStyle
Multiple runs of the change above results in only one new dimension style, “MyDim”, to be added to the document.
1 Like
I tried to replace the final code, and an error occurred at the second run of the scriptDimClosedPolylinestest.py (2.2 KB)
Ah, the rs. functions work with strings of the dim style’s name, not the dim style itself, so something like:
def CreateDimStyle(textHeight):
dimStyle_name = "MyDim"
# look for a dimension style of same name
dimStyleObject = sc.doc.DimStyles.FindName(dimStyle_name)
if dimStyleObject:
# get the name of the StyleObject
dimStyle = dimStyleObject.Name
# if no style with same name then make one
else:
dimStyle = rs.AddDimStyle(dimStyle_name)
rs.DimStyleTextHeight(dimStyle,textHeight)
rs.DimStyleArrowSize(dimStyle,textHeight)
# return the name of the found or new dim style
return dimStyle
or slightly more direct:
def CreateDimStyle(textHeight):
dimStyle_name = "MyDim"
# look for a dimension style of same name
dimStyleObject = sc.doc.DimStyles.FindName(dimStyle_name)
if dimStyleObject:
return dimStyle_name
# no style was found with dimStyle_name so make one
dimStyle = rs.AddDimStyle(dimStyle_name)
rs.DimStyleTextHeight(dimStyle,textHeight)
rs.DimStyleArrowSize(dimStyle,textHeight)
return dimStyle
1 Like
thank you. It works very well.