Macro Conundrum

Discussion in 'AutoCAD' started by Patrick Haydon, Apr 3, 2005.

  1. I am looking for a way to program dimension buttons to access a variable layer within the file, and if the variable layer is not in the file, a dimension layer would be inserted. I would then like for the drawing to go back to the previous layer.

    I am making architectural drawings and already have a menu that runs lisp routines to set up the drawing (text, dimensions, and standard annotation layers such as a-anno-dim-VARIABLE and a-anno-symb-VARIABLE.) There is also a menu of standard annotations that are inserted and scaled according to the style set by the style menu, which run on lisp routines as well.

    So, basically I would like to be able to select the 048 style which sets up the drawing for ¼â€=1’-0†and then use a dimension button which would put the dimension on the a-anno-dim-048 layer and go back to the previous layer. But if the 048 lisp routine hasn’t run, then the dimension defaults to a generic dimension layer a-anno-dim.

    Below is the lisp routine that sets all the variables for the ¼â€=1’-0†drawing style. If any body has a clue about how i might achieve this please let me know.. I am not a customizing expert but feel like this would be achievable somewhat painlessly..


    (defun c:`1 ()

    (setq old_cmdecho (getvar "cmdecho"))
    (setvar "cmdecho" 0)
    (setq actual_scale (strcat "1'-0'' = 1'-0'' "))
    (setq scale_factor (strcat "001"))
    (setq text_layername (strcat "a-anno-text-" scale_factor))
    (setq dims_layername (strcat "a-anno-dims-" scale_factor))
    (setq symb_layername (strcat "a-anno-symb-" scale_factor))
    (setq door_layername (strcat "a-door-iden-" scale_factor))
    (setq flor_layername (strcat "a-flor-iden-" scale_factor))
    (setq glaz_layername (strcat "a-glaz-iden-" scale_factor))
    (setq lite_layername (strcat "a-lite-iden-" scale_factor))
    (setq grid_layername (strcat "a-grid-iden-" scale_factor))
    (setq wall_layername (strcat "a-wall-iden-" scale_factor))
    (setq dim_name (strcat scale_factor "_DIM"))
    (setq dim_namelc (strcat scale_factor "_dim"))
    (setq stylename (strcat scale_factor "_NOTES"))
    (setq old_regenmode (getvar "regenmode"))
    (setvar "regenmode" 1)
    (if (/= (strcat dims_layername) (cdr (assoc 2 (tblsearch "layer" dims_layername))))
    (command "layer" "m" dims_layername "c" "4" "" "")
    )

    (if (/= (strcat symb_layername) (cdr (assoc 2 (tblsearch "layer" symb_layername))))
    (command "layer" "m" symb_layername "c" "4" "" "")
    )

    (if (/= (strcat door_layername) (cdr (assoc 2 (tblsearch "layer" door_layername))))
    (command "layer" "m" door_layername "c" "4" "" "")
    )

    (if (/= (strcat flor_layername) (cdr (assoc 2 (tblsearch "layer" flor_layername))))
    (command "layer" "m" flor_layername "c" "4" "" "")
    )

    (if (/= (strcat glaz_layername) (cdr (assoc 2 (tblsearch "layer" glaz_layername))))
    (command "layer" "m" glaz_layername "c" "4" "" "")
    )

    (if (/= (strcat lite_layername) (cdr (assoc 2 (tblsearch "layer" lite_layername))))
    (command "layer" "m" lite_layername "c" "4" "" "")
    )

    (if (/= (strcat grid_layername) (cdr (assoc 2 (tblsearch "layer" grid_layername))))
    (command "layer" "m" grid_layername "c" "4" "" "")
    )

    (if (/= (strcat wall_layername) (cdr (assoc 2 (tblsearch "layer" wall_layername))))
    (command "layer" "m" wall_layername "c" "4" "" "")
    )


    (if
    (and
    (= (strcat text_layername) (cdr (assoc 2 (tblsearch "layer" text_layername)))
    )
    (/= 0 (cdr (assoc 70 (tblsearch "layer" text_layername)))
    )
    ) (command "layer" "t" text_layername "")
    )
    (command "layer" "m" text_layername "c" "4" "" "")

    (command "-style" stylename "romans.shx" (* (atof scale_factor) 0.09375) ".85" "0" "n" "n" "n")

    (setvar "DIMADEC" 0)
    (setvar "DIMALT" 0)
    (setvar "DIMALTD" 3)
    (setvar "DIMALTF" 25.4000)
    (setvar "DIMALTRND" 0)
    (setvar "DIMALTTD" 3)
    (setvar "DIMALTTZ" 0)
    (setvar "DIMALTU" 4)
    (setvar "DIMALTZ" 0)
    (setvar "DIMASO" 1)
    (setvar "DIMASZ" 0.09375)
    (setvar "DIMATFIT" 3)
    (setvar "DIMAUNIT" 0)
    (setvar "DIMAZIN" 0)
    (setvar "DIMCEN" 0.0625)
    (setvar "DIMCLRD" 1)
    (setvar "DIMCLRE" 1)
    (setvar "DIMCLRT" 0)
    (setvar "DIMDEC" 3)
    (setvar "DIMDLE" 0.0625)
    (setvar "DIMDLI" 0.0625)
    (setvar "DIMEXE" 0.0625)
    (setvar "DIMEXO" 0.0625)
    (setvar "DIMFIT" 5)
    (setvar "DIMFRAC" 1)
    (setvar "DIMGAP" 0.0625)
    (setvar "DIMJUST" 0)
    (setvar "DIMLFAC" 1.0000)
    (setvar "DIMLIM" 0)
    (setvar "DIMLUNIT" 4)
    (setvar "DIMLWD" -2)
    (setvar "DIMLWE" -2)
    (setvar "DIMRND" 0)
    (setvar "DIMSAH" 0)
    (setvar "DIMSCALE" (atof scale_factor))
    (setvar "DIMSD1" 0)
    (setvar "DIMSD2" 0)
    (setvar "DIMSE1" 0)
    (setvar "DIMSE2" 0)
    (setvar "DIMSHO" 1)
    (setvar "DIMSOXD" 0)
    (setvar "DIMTAD" 1)
    (setvar "DIMTDEC" 3)
    (setvar "DIMTFAC" 0.85)
    (setvar "DIMTIH" 0)
    (setvar "DIMTIX" 0)
    (setvar "DIMTM" 0)
    (setvar "DIMTMOVE" 2)
    (setvar "DIMTOFL" 0)
    (setvar "DIMTOH" 0)
    (setvar "DIMTOL" 0)
    (setvar "DIMTOLJ" 1)
    (setvar "DIMTP" 0)
    (setvar "DIMTSZ" 0)
    (setvar "DIMTVP" 0)
    (setvar "DIMTXT" 0.09375)
    (setvar "DIMTZIN" 0)
    (setvar "DIMUNIT" 6)
    (setvar "DIMUPT" 0)
    (setvar "DIMZIN" 3)
    (command "DIMTXSTY" stylename)
    (command "DIMPOST" ".")
    (command "DIMLDRBLK" ".")
    (command "DIMDSEP" ".")
    (command "DIMBLK" "ArchTick")
    (command "DIMBLK1" ".")
    (command "DIMBLK2" ".")
    (command "DIMLDRBLK" ".")
    (command "DIMAPOST" ".")
    (if
    (or
    (= (strcat dim_name) (cdr (assoc 2 (tblsearch "dimstyle" dim_name)))
    )
    (= (strcat dim_namelc) (cdr (assoc 2 (tblsearch "dimstyle" dim_name)))
    )
    ) (command "-DIMSTYLE" "S" dim_name "y")
    )

    (if
    (and
    (/= (strcat dim_name) (cdr (assoc 2 (tblsearch "dimstyle" dim_name)))
    )
    (/= (strcat dim_namelc) (cdr (assoc 2 (tblsearch "dimstyle" dim_name)))
    )
    ) (command "-DIMSTYLE" "S" dim_name)
    )


    (setvar "regenmode" old_regenmode)
    (setvar "cmdecho" old_cmdecho)
    (setvar "modemacro" actual_scale)
    (if (= (getvar "tilemode") 0)(setvar "ltscale" 0.5))
    (if (= (getvar "tilemode") 1)(setvar "ltscale" (/ (getvar"dimscale") 2)))
    (terpri)
    (princ "The Drawing Style is now set to: ") (princ (strcat actual_scale))
    (alert (strcat "The Drawing Style is now set to: " actual_scale))
    (princ)

    )
     
    Patrick Haydon, Apr 3, 2005
    #1
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.