Reactor question, it reacts to the PLOT command and updates block attributes

Discussion in 'AutoCAD' started by Tomdum, Dec 15, 2004.

  1. Tomdum

    Tomdum Guest

    Hope you guys can help me out.
    I'm writing a routine that will run when the PLOT command is run. It will run before PLOT and will search the drawing for blocks with a specific attribute then edit them with the drawing location. I have copied and edited two routines from the forum here, one that reacts to plot and one that searches then edits the attributes. They both work great, the problem is when I put them together.
    When I run plot I get this error as many as 15 times:

    error: An error has occurred inside the
    *error* functioninvalid AutoCAD command: nil

    Here is the code I also attached it. Anyone know what I'm doing wrong?

    ;*****************Start Recactor Code*******************

    (vl-load-com)

    ;*******************************************************

    (vlr-command-reactor

    "Run Before Plot" '(:)vlr-commandWillStart . startPlot)))

    ;*******************************************************

    (defun startPlot (calling-reactor endcommandInfo /

    thecommandend)

    (setq thecommandend (nth 0 endcommandInfo)
    thetime 100)

    (if (= thecommandend "PLOT")

    (progn

    ;List of commands to run when PLOT is called.

    (location-update)

    );progn

    );if

    (princ)

    );defun

    ;*******************End Recactor Code*****************

    (defun location-update (/)
    ;; Program to find a given Attribute Tag, and place drawing name in it.
    ;;
    (setq tag_name "DRAWING_LOCATION"); Tag Name to search for..
    (setq dwgname (substr (strcat (getvar "DWGPREFIX")(getvar "DWGNAME")) (+ 3 (vl-string-search "\\J\\" (strcat (getvar "DWGPREFIX")(getvar "DWGNAME"))))))
    (setq nstr dwgname)
    ;;
    ;; Define DXF function
    ;;
    (defun dxf (code elist)
    (cdr (assoc code elist))
    ); end function dxf
    ;;
    ;; Local Function to replace attribute Value
    ;;
    (defun rep_txt ()
    (if (and (/= ostr nil)(/= nstr nil)(/= txt nil))
    (entmod (setq txt (subst (cons 1 nstr)(cons 1 ostr) txt)))
    ); end if
    ); end function rep_txt
    ;;
    (setq A (ssget "X" '((0 . "INSERT") (2 . "br-dwg_location") (66 . 1))));(ssget "X")); get ALL
    (if (/= A nil); IF A is nil, do nothing.
    (setq B (sslength A)); check number of members in 'A' selection set.
    ); end if
    ;;
    ;; A = selection set of entities
    ;; B = sslength of A
    ;; C = Counter for number of entities found
    ;;
    (if (> B 0); -- Must be something to look at in selection set..
    (progn
    (prompt "\nChecking Drawing..Please wait..")
    (setq C 0 E 1); C = entity selecter, starts at 0, goes 1,2,3..
    (repeat B
    (setq D (ssname A C)); get entity name from 'A', if no name, D is nil.
    (if (/= D nil); found something ?
    (progn
    (setq chk (entget D)); chk used to hold each entity 'list' item.
    ;;
    ;; Check out BLOCKS
    ;;
    (if (and
    (= "INSERT" (cdr (assoc 0 chk))) ; case of BLOCKS
    (/= (cdr (assoc 66 chk)) nil); with Attrib's following
    ); end and
    (progn
    (setq av nil CX 1); init inside loop
    (while (> CX 0)
    (setq en (entget (entnext (dxf -1 chk)))); sub-entity
    (setq abn (cdr (assoc 0 en))); name of item
    (setq chk en); swap to next Attrib
    (if (or (= "INSERT" abn)(= "SEQEND" abn))
    (setq CX 0)
    ); end if
    ;; - if not at end of Attributes, keep going
    (if (= "ATTRIB" abn)
    (progn
    (setq av (cdr (assoc 1 en))); get the attrib value
    (setq tn (cdr (assoc 2 en))); get 'tag' name
    (if (= tn tag_name)
    (progn
    (setq ostr av)
    (setq txt en); temp - swap to txt entity
    (rep_txt); replace the (attribute) text strings
    (setq txt nil); and cancel txt entity
    ); end progn
    ); end if
    ); end progn
    ); end if
    ); end while CX > 1
    ); end progn
    ); end if INSERT
    ); end progn
    ); end if D /= nil
    (setq C (+ C 1)); ratchet counter C to get next entity.
    (setq D nil av nil); reset D - for IF above.
    ); end repeat B
    ); end progn
    ); end if B > 0
    ;;
    ;; Cleanup and exit
    ;;
    (command "_regen")
    ;;
    (setq AA nil BB nil A nil B nil C nil D nil E nil F nil G nil Z nil NF nil)
    (setq av nil CX nil txt nil en nil abn nil)
    (setq ostr nil nstr nil sstr nil rstr nil)
    (princ)

    );defun

    ;*********************************************************

    (princ)
     
    Tomdum, Dec 15, 2004
    #1
  2. Tomdum

    Matt W Guest

    Why not just use RTEXT or a FIELD to hold the drawing location?
     
    Matt W, Dec 15, 2004
    #2
  3. Tomdum

    Tomdum Guest

    Not sure what you mean?
    Can you explain or give me an example?
     
    Tomdum, Dec 15, 2004
    #3
  4. Tomdum

    Tomdum Guest

    It seems to run the command more than once. Forexample, if I put (alert "test") in place of the attribute edit code it pops up 10 or more times.

    ;*****************Start Recactor Code*******************

    (vl-load-com)

    ;************************** *****************************

    (vlr-command-reactor

    "Run Before Plot" '(:)vlr-commandWillStart . startPlot)))

    ;*******************************************************

    (defun startPlot (calling-reactor endcommandInfo /

    thecommandend)

    (setq thecommandend (nth 0 endcommandInfo))

    (if (= thecommandend "PLOT")

    (progn

    ;List of commands to run when PLOT is called.

    (alert "test")

    );progn

    );if

    (princ)

    );defun

    ;*******************End Recactor Code*****************
     
    Tomdum, Dec 15, 2004
    #4
  5. Tomdum

    Matt W Guest

    RTEXT is an express tool command and uses a diesel expression such as the
    following:
    $(edtime, $(getvar,date),MO"/"DD"/"YY HH:MM:SSAM/PM)
    $(getvar,dwgprefix)$(getvar,dwgname) which would show on the screen as

    12/15/04 03:00:46 PM C:\Temp\Test File.dwg

    ....and a FIELD is new to 2005 which is kinda like the same thing except that
    you don't have to type anything and you have more control over how and what
    is displayed.
     
    Matt W, Dec 15, 2004
    #5
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.