import rhinoscriptsyntax as rs
import scriptcontext
def CopyScaleDimstyle2():
ds=scriptcontext.doc.DimStyles
dsCount=scriptcontext.doc.DimStyles.Count
dsDict={scriptcontext.doc.DimStyles[n].Name : n for n in range(dsCount)}
title="Copy/Scale Dimension Style"
choice=rs.ListBox(dsDict.keys(),"Pick a dim style to copy and scale",title)
if choice is None: return
n=dsDict[choice]
nameOK=False
while nameOK==False:
newName=rs.StringBox("Name must be unique!",choice+"-1","Enter new style name")
if newName is None: return
if newName in dsDict:
rs.MessageBox("Name already exists - please choose another!")
else:
nameOK=True
sf=rs.RealBox("Scale factor?",2,"Scale factor")
if sf is None: return
if sf<=0:
print "Scale factor must be greater than 0"
return
rs.AddDimStyle(newName)
#assume new style is added to end of list, dsCount should now be dsCount+1
#apply scale to the different fields
ds[dsCount].Name=newName
ds[dsCount].TextHeight=ds[n].TextHeight*sf
ds[dsCount].TextGap=ds[n].TextGap*sf
ds[dsCount].ExtensionLineExtension=ds[n].ExtensionLineExtension*sf
ds[dsCount].ExtensionLineOffset=ds[n].ExtensionLineOffset*sf
#the following property is missing... :-(
#ds[dsCount].DimensionLineExtension=ds[n].DimensionLineExtension*sf
ds[dsCount].CenterMarkSize=ds[n].CenterMarkSize*sf
ds[dsCount].ArrowLength=ds[n].ArrowLength*sf
ds[dsCount].LeaderArrowLength=ds[n].LeaderArrowLength*sf
#Apply changes to new style
ds[dsCount].CommmitChanges()
#Below gives no error message but does nothing
#scriptcontext.doc.DimStyles[dsCount].CommitChanges
CopyScaleDimstyle2()