Link to home
Start Free TrialLog in
Avatar of stephenlecomptejr
stephenlecomptejrFlag for United States of America

asked on

lisp routine error with dimstyle already existing?

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?
Avatar of stephenlecomptejr
stephenlecomptejr
Flag of United States of America image

ASKER

(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)
(command
    "-Units"
      "4"
      "32"
      "1"
      "4"
      "0"
      "n"
)




   (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")

;;;;;;;;;;;;;;;;;;;;;;;text
size;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


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


;;;;;;;;;;;;;;;;;;;;;;Message;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;

  (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...")
(princ)
)


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?
IT PAUSES ON (command "dim" "save" "fkp" "ext"
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.

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
it didn't work - still getting error - seems to make the dim sytle read-only - how do I get the read-only part off?
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.
SOLUTION
Avatar of dhsindy
dhsindy
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thank you all for your replies.
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")
   )