Search code examples
stylesautocaddimensionsautocad-pluginautolisp

Use AutoLISP to Generate New Dimension Style


I would like an AutoLISP routine that automatically creates a new dimension style with my custom settings. I know it is possible to copy dimension styles from one drawing to another, but it is tedious and time-consuming to have to do this each time.

I have compiled a list of the variables that I would like to have for my most commonly used style, but ideally I would like to be able to add or remove variables from this list.

The process to do this manually is to set each variable in the command line, then use the "-DIMSTYLE SAVE" command to save it with a custom name. I attempted to tackle this project myself, but being relatively inexperienced in AutoLISP I quickly realized that I do not quite have the knowledge to do this properly.

Here is the list of variables that matter for creating most new styles for me:

DIMALTD 4

DIMAPOST    [null]

DIMALTF 1

DIMALTTD    4

DIMALTU 4

DIMADEC 1

DIMAZIN 0

DIMARCSYM   1

DIMBLK  ClosedFilled

DIMBLK1 ClosedFilled

DIMBLK2 ClosedFilled

DIMASZ  1

DIMCEN  0

DIMCLRD 3

DIMDLE  0

DIMLTYPE    BYBLOCK

DIMLWD  -2

DIMDLI  4

DIMLTEX1    BYBLOCK

DIMLTEX2    BYBLOCK

DIMCLRE 3

DIMEXE  0.5

DIMLWE  -2

DIMEXO  0.75

DIMFRAC 0

DIMJOGANG   45

DIMLDRBLK   ClosedFilled

DIMLUNIT    5

DIMSCALE    1

DIMRND  0

DIMSAH  Off

DIMCLRT 3

DIMTXT  1.5

DIMTIH  On

DIMGAP  0.1

DIMTOH  On

DIMTAD  0

DIMTXSTY    Standard

DIMTM   0

DIMTP   0

DIMTFAC 1

DIMTZIN 0

DIMZIN  0

Solution

  • Thanks, CAD Developer. That got me started. Here is the code I ended up using. AutoCAD did not like the text value variables, so I just removed them as they are not important for me.

    ;automatically create new dimension style
    (defun c:jeff ()
        (setvar "DIMALTD" 4)
        (setvar "DIMALTF" 1)
        (setvar "DIMALTTD" 4)
        (setvar "DIMALTU" 4)
        (setvar "DIMADEC" 1)
        (setvar "DIMAZIN" 0)
        (setvar "DIMARCSYM" 1)
        (setvar "DIMASZ" 1)
        (setvar "DIMCEN" 0)
        (setvar "DIMCLRD" 3)
        (setvar "DIMDLE" 0)
        (setvar "DIMLWD" -2)
        (setvar "DIMDLI" 4)
        (setvar "DIMCLRE" 3)
        (setvar "DIMEXE" 0.5)
        (setvar "DIMLWE" -2)
        (setvar "DIMEXO" 0.75)
        (setvar "DIMFRAC" 0)
        (setvar "DIMLUNIT" 5)
        (setvar "DIMSCALE" 1)
        (setvar "DIMRND" 0)
        (setvar "DIMCLRT" 3)
        (setvar "DIMTXT" 1.5)
        (setvar "DIMGAP" 0.1)
        (setvar "DIMTAD" 0)
        (setvar "DIMTM" 0)
        (setvar "DIMTP" 0)
        (setvar "DIMTFAC" 1)
        (setvar "DIMTZIN" 0)
        (setvar "DIMZIN" 0)
    
        (command "dimstyle" "s" "Jeff")
    
        (princ)
    )