lisp routine error with dimstyle already existing?

Posted on 2005-04-29
Last Modified: 2008-02-01
I have a lisp routine that setup units, ltscale, dim variables, text style and makes the dimension styles. But when I try to run this
setup to reset some variables I get Invalid option keyword; error: function cancelled; that name is already in use, redefine it?  It is saying that the dimstyle is already exist do you want to redefine it. I want
this to do it automaticly with out asking me to redefine it. Any suggestions?
Question by:stephenlecomptejr
    LVL 1

    Author Comment

    (defun c:newsetup (/ RPT1 RPT2 RPT3 RPT4 x y z)
            (setvar "CMDECHO" 0)
            (Setq tmode (getvar "tilemode"))
            (command "tilemode" 1)
          (setq x sizex)            ;;;VALUE SET IN MNC
          (setq y sizey)            ;;;VALUE SET IN MNC
            (setq z (atof scalez))
            (setq txsty (atof txstyle))
          (setq #dwgsc2 z)      ;;;VALUE SET IN MNL
          (setq xscale (* x #dwgsc2))
          (setq yscale (* y #dwgsc2))
          (setq uplim (list xscale yscale))
          (command "limits" "" uplim)
          (command "ltscale" "1")
          (command "ltscale" (* 1 #dwgsc2))
           (command "insert" "c:/fkpuds/blocks/fkp" ^c^C)
           (command "insert" "c:/fkpuds/blocks/AROBC" ^c^C)

       (defun scale1_32 ()
          (prompt "\nYOU HAVE SET YOUR FKP SCALE TO 1/32\"  ")(PRINC)
       ); end defun

       (defun scale1_16 ()
          (prompt "\nYOU HAVE SET YOUR FKP SCALE TO 1/16\"  ")(PRINC)
       ); end defun

       (defun scale3_32 ()
          (prompt "\nYOU HAVE SET YOUR FKP SCALE TO 3/32\"  ")(PRINC)
       ); end defun

       (defun scale1_8 ()
          (prompt "\nYOU HAVE SET YOUR FKP SCALE TO 1/8\"  ")(PRINC)
       ); end defun

       (defun scale3_16 ()
          (prompt "\nYOU HAVE SET YOUR FKP SCALE TO 3/16\"  ")(PRINC)
       ); end defun

       (defun scale1_4 ()
          (prompt "\nYOU HAVE SET YOUR FKP SCALE TO 1/4\"  ")(PRINC)
       ); end defun

       (defun scale3_8 ()
          (prompt "\nYOU HAVE SET YOUR FKP SCALE TO 3/8\"  ")(PRINC)
       ); end defun

       (defun scale1_2 ()
          (prompt "\nYOU HAVE SET YOUR FKP SCALE TO 1/2\"  ")(PRINC)
       ); end defun

       (defun scale3_4 ()
          (prompt "\nYOU HAVE SET YOUR FKP SCALE TO 3/4\"  ")(PRINC)
       ); end defun

       (defun scale1 ()
          (prompt "\nYOU HAVE SET YOUR FKP SCALE TO 1\"  ")(PRINC)
       ); end defun

       (defun scale1-1_2 ()
          (prompt "\nYOU HAVE SET YOUR FKP SCALE TO 1 1/2\"  ")(PRINC)
       ); end defun

       (defun scale3 ()
          (prompt "\nYOU HAVE SET YOUR FKP SCALE TO 3\"  ")(PRINC)
       ); end defun

       (defun scale6 ()
          (prompt "\nYOU HAVE SET YOUR FKP SCALE TO 6\"  ")(PRINC)
       ); end defun

       (defun scalefull ()
          (prompt "\nYOU HAVE SET YOUR FKP SCALE TO fullscale  ")(PRINC)
       ); end defun

       (defun scale10 ()
          (prompt "\nYOU HAVE SET YOUR FKP SCALE TO 1:10  ")(PRINC)
       ); end defun

       (defun scale20 ()
          (prompt "\nYOU HAVE SET YOUR FKP SCALE TO 1:20  ")(PRINC)
       ); end defun

       (defun scale30 ()
          (prompt "\nYOU HAVE SET YOUR FKP SCALE TO 1:30  ")(PRINC)
       ); end defun

       (defun scale40 ()
          (prompt "\nYOU HAVE SET YOUR FKP SCALE TO 1:40  ")(PRINC)
       ); end defun

       (defun scale50 ()
          (prompt "\nYOU HAVE SET YOUR FKP SCALE TO 1:50  ")(PRINC)
       ); end defun

       (defun scale60 ()
          (prompt "\nYOU HAVE SET YOUR FKP SCALE TO 1:60  ")(PRINC)
       ); end defun

       (defun scale80 ()
          (prompt "\nYOU HAVE SET YOUR FKP SCALE TO 1:80  ")(PRINC)
       ); end defun

       (defun scale100 ()
          (prompt "\nYOU HAVE SET YOUR FKP SCALE TO 1:100  ")(PRINC)
       ); end defun

          (command "filedia" 1)
          (command "attdia" 1)
          (command "cmddia" 1)
          (command "elevation" 0)
          (command "thickness" 0)
          (command "lunits" 4)
          (command "limcheck" 0)
          (command "textfill" 1)
          (command "INSUNITS" 1)
          (command "ucsicon" "off")

                (command "DIM")
          (command "dimasz" (/ #dwgsc2 16))
          (command "dimexo" (/ #dwgsc2 12))
          (command "dimexe" (/ #dwgsc2 12))
          (command "dimscale" 1)
          (command "DIMBLK1" "fkp")
          (command "DIMBLK2" "fkp")
          (command "DIMLDRBLK" "AROBC")
          (command "dimclrd" "bylayer")
          (command "dimclre" "bylayer")
          (command "dimclrt" "bylayer")
          (command "dimtsz" (/ #dwgsc2 12))
          (command "dimtol" 0)
          (command "dimtolf" "off")
          (command "dimdli" 0)
          (command "dimlim" 0)
          (command "dimtih" 0)
          (command "dimtoh" 0)
          (command "dimgap" (/ #dwgsc2 12))
          (COMMAND "DIMADEC" "0")
          (command "dimtad" 1)
          (command "dimzin" 3)DEC
          (command "dimaso" 1)
          (command "dimsho" 0)
          (command "dimtvp" 1)
          (command "dimlunit" 4)
          (command "dimfit" 5)
          (command "DIMTXSTY" "med")
           (command "DIMTP" "1/32")
             (command "DIMSE1" "OFF")
              (command "DIMSE2" "OFF")
              (command "SAVE" "Fkp")                  ;Saves Dimension style FKP
          (command "exit")
    (COMMAND "DIM" "restore" "fkp" "exit")
    (Setvar "Expert" 0)
    (command "regenauto" "on")


               (command "style" "lar" "" (* txsty 2)"" "" "" "" "")
               (command "style" "sma" "" (/ txsty 2) "" "" "" "" "")
          (command "style" "med" "" txsty "" "" "" "" "")


      (cond ((= #dwgsc2 2.16) (scalenone));;none
             ((= #dwgsc2 96) (scale1_8));;;1/8
             ((= #dwgsc2 64) (scale3_16));;;3/16
             ((= #dwgsc2 48) (scale1_4));;;1/4
             ((equal #dwgsc2 128) (scale3_32));;;3/32
             ((= #dwgsc2 192) (scale1_16));;;1/16
             ((= #dwgsc2 384) (scale1_32));;;1/32
             ((equal #dwgsc2 32) (scale3_8));;;3/8
             ((= #dwgsc2 24) (scale1_2));;;1/2
             ((equal #dwgsc2 16) (scale3_4));;;3/4
             ((= #dwgsc2 12) (scale1));;;1
             ((equal #dwgsc2 8) (scale1-1_2));;;1 1/2
             ((equal #dwgsc2 4) (scale3));;;3
             ((equal #dwgsc2 2) (scale6));;;6
             ((equal #dwgsc2 1) (scalefull));;;full
             ((= #dwgsc2 120) (scale10));;;10
             ((= #dwgsc2 240) (scale20));;;20
             ((= #dwgsc2 360) (scale30));;;30
             ((= #dwgsc2 480) (scale40));;;40
             ((= #dwgsc2 600) (scale50));;;50
             ((= #dwgsc2 720) (scale60));;;60
             ((= #dwgsc2 960) (scale80));;;80
             ((= #dwgsc2 1200) (scale100));;;100
          (setq RPT1 (getvar "Limmin")
                RPT3 (getvar "Limmax"))
            (setq RPT2 (list (car RPT3) (cadr RPT1) 0.0))
            (setq RPT4 (list (car RPT1) (cadr RPT3) 0.0))
          (setq templayer (getvar "clayer"))
          (command "_-layer" "make" "defpoints" "")(princ)
            (command "._pline" RPT1 "W" "0" "0" RPT2 RPT3 RPT4 "C")
          (setvar "clayer" templayer)
          (setvar "tilemode" tmode)
          (command "zoom" "all")
    (prompt "\n... Drawing Units set...")
    (prompt "\n... Drawing Scale set...")
    (prompt "\n... Linetype Scale set...")
    (prompt "\n... Standard Dim and Text styles are loaded...")

    this lisp routine saves dimension styles and works on the first try.
    But when you run it again I want it to automatically re-define that dimension style FKP instead of telling you that it already exists?
    LVL 1

    Author Comment

    IT PAUSES ON (command "dim" "save" "fkp" "ext"
    LVL 17

    Expert Comment

    After all your DIM variables are set - put a line like this in your routine:

    (command "dimstyle" "save" "[STYLE NAME]")  - note STYLE NAME is your choice but avoid proper words or AutoCAD variables

    they  may be rejected.

    LVL 17

    Expert Comment

    Sorry, I meant to tell you to leave off the brackets around STYLE NAME.  Some of the things you mentioned like LTSCALE are not part of a dimstyle.  Try this - on the command line: type in 'setvar' enter, '?' enter, then, *dim* enter - all the dimension variables and their values will be listed out.

    Hope this helps, dhs
    LVL 1

    Author Comment

    it didn't work - still getting error - seems to make the dim sytle read-only - how do I get the read-only part off?
    LVL 17

    Expert Comment

    I am not sure if you can.  I don't use dimensions very much.  I am thinking you just remake the style as needed.  Try making your dimstyle current in the dialog box and see if there are any options there.

    BTW: What AutoCAD program are you using?  I will try looking over your routine and maybe trying it at work - first of the week.
    LVL 17

    Assisted Solution

    See below - from the program help files - DIMSTYLE is a read only system variable.  What that means is you cannot change it using SETVAR command directly - you have to change it using the DIMSTYLE command.

    use - (command "dimstyle" "save" "STEVE_DIMS") - to create the style and follow it with
            (command "dimstyle" "restore" "STEVE_DIMS") - to make it active from within the lisp routine.

    Or put it all in one line -

            (command "dimstyle" "s" "STEVE_DIMS" "r" "STEVE_DIMS")

    There are many other read only variables in AutoCAD that must be changed in a dialog or menu.  In the later versions you can type a hyphen in front of the command to run the command line version.  On the command line type DIMSTYLE you get the dialog box but type in -DIMSTYLE you get the command line version (a lot of clues for writing routines).


    DIMSTYLE System Variable  

    Type: String
    Saved in: Drawing

    DIMSTYLE is both a command and a system variable. The DIMSTYLE system variable shows the current
    dimension style. To display the DIMSTYLE system variable, use the SETVAR command. The DIMSTYLE
    system variable is read-only; you cannot change its value on the command line. To change the current
    dimension style, use the DIMSTYLE command.
    LVL 3

    Accepted Solution

    Use this code snippet in place of your "save" snippet and you will have no more problems.


       (if (tblsearch "dimstyle" "Fkp")
             (command "SAVE" "Fkp" "Y")
             (command "SAVE" "Fkp")


    Cheers ...
    For more information on lisp programming as well as lots of help for users, visit
    LVL 1

    Author Comment

    thank you all for your replies.
    LVL 1

    Author Comment

    Actually the following worked for us... But we used the above to figure it out:
    (if (tblsearch "dimstyle" "Fkp")
             (command "dimstyle" "SAVE" "Fkp" "Y")
             (command "dimstyle" "SAVE" "Fkp")


    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Following a number of instances of re-installing Solidworks I thought that it may be a  good idea to detail the procedure that I follow each time to ensure a good stable install. Backup: Backup your system.  It goes without saying that this i…
    Our company has proprietary drawing files that we do not give to our customers for final documentation. Our customers now require that we give them these drawings. They understand that they are proprietary and do not require them to be in AutoCAD bu…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now