Long time ago I got help here for importing dimstyle.
I now find AutoCAD will be crashed when I apply the imported dimstyle to a new dimension.
Here is a simplified version.
Your helps is much appreciated.
Code:
(defun c:DimStyleImport (/ currentDimStyle DimStyle_ID DimStyleList
DimStyle_Name fqnName fqnTemp myAcad dbxName myDb
sourceDimStyle targetDimStyle)
(setvar "cmdecho" 0)
(setq currentDimStyle (getvar "dimstyle"))
(setq DimStyle_ID (getstring "\nEnter a DimStyle ID: "))
(setq DimStyleList
(list (cons "1-1" "STD 1-1"); this is the dimstyle to be imported.
(cons "1-2" "STD 1-2"); this is the dimstyle to be imported.
(cons "1-5" "STD 1-5"); this is the dimstyle to be imported.
(cons "1-10" "STD 1-10"); this is the dimstyle to be imported.
(cons "1-20" "STD 1-20"); this is the dimstyle to be imported.
(cons "1-50" "STD 1-50"); this is the dimstyle to be imported.
(cons "1-100" "STD 1-100"); this is the dimstyle to be imported.
(cons "1-200" "STD 1-200"); this is the dimstyle to be imported.
(cons "1-500" "STD 1-500"); this is the dimstyle to be imported.
(cons "1-1000" "STD 1-1000"); this is the dimstyle to be imported.
); end of list
); end of setq
(setq DimStyle_Name
(cdr (assoc DimStyle_ID DimStyleList))
); end of setq
(if (tblsearch "dimstyle" DimStyle_Name)
(progn (prompt (strcat "\nDimStyle " DimStyle_Name " has already existed."))
(command "._-dimstyle" "restore" DimStyle_Name)
(exit)
); end of progn
); end of if
(setq fqnName "C:\\Standard.dwt"); your standard drawing template
(findfile fqnName)
(setq fqnTemp
(vl-filename-mktemp "Dims" (getenv "Temp") ".dwt")
); end of setq
(vl-file-copy fqnName fqnTemp)
(setq myAcad
(vlax-Get-Acad-Object)
); end of setq
(setq dbxName
(strcat "ObjectDBX.AxDbDocument." (itoa (atoi (getvar 'AcadVer))))
); end of setq
(setq myDb
(vla-GetInterfaceObject myAcad dbxName)
); end of setq
(progn (vla-Open myDb fqnTemp) 'T)
(not (vl-catch-all-error-p
(vl-catch-all-apply
(function (lambda ()
(setq sourceDimStyle
(vla-Item (vla-Get-DimStyles myDb) DimStyle_Name))
); end of lambda
); end of function
); end of vl
); end of vl
); end of not
(setq targetDimStyle
(vla-Add (vla-Get-DimStyles (vla-Get-ActiveDocument myAcad))
DimStyle_Name)
); end of setq
(progn (vla-CopyFrom targetDimStyle sourceDimStyle) T)
(vlax-Release-Object myDb)
(vl-file-delete fqnTemp)
(command "._-dimstyle" "restore" currentDimStyle)
(setvar "cmdecho" 1)
(princ)
); end of Routine