looking for help in fields

Discussion in 'AutoCAD' started by rats, Feb 10, 2005.

  1. rats

    rats Guest

    I'm trying to find a way in which i can put an automatic number that will update by 1 each time a drawing is plotted. The date and time are no problem but this one still alludes me. basically I want to be able to write to a field (hopefully within the drawing) that with each plot will overright it with a sequential number each time. Hopefully someone out there has done this before and put my feet on the right road before I go barmy.

    Cheers
     
    rats, Feb 10, 2005
    #1
  2. rats

    Jürg Menzi Guest

    Hi rats

    A command reactor can do this. You need a block with an Attribute to write
    the numbers of plots. See also comments in the MePlotCount function.
    Code:
    ;
    ; == AcadDoc.lsp ==============================================================
    ; Initialize a Command Reactor to control a Plot counter.
    ; Copyright:
    ;   ©2005 MENZI ENGINEERING GmbH, Switzerland
    ; Notes:
    ;   - None
    ;
    ; - Initialize ActiveX support
    (vl-load-com)
    ;
    ; - Reactors ------------------------------------------------------------------
    ;
    ; - If not set, initialize DocManager-Reactor
    (or Me:ReaDma
    (setq Me:ReaDma (VLR-DocManager-Reactor
    nil
    '(
    (:VLR-documentToBeDestroyed . MeDocToBeDestroyedCallbacks)
    )
    )
    )
    )
    ; - If not set, initialize Command-Reactor
    (or Me:ReaCom
    (setq Me:ReaCom (VLR-Command-Reactor
    nil
    '(
    (:VLR-commandEnded . MeCommandEndedCallbacks)
    )
    )
    )
    )
    ;
    ; - Notifications -------------------------------------------------------------
    ;
    ; - CommandEnded notifications
    (defun MeCommandEndedCallbacks (Rea Arg)
    (MeDoCmdEndedStuff Arg)
    ;other functions...
    (princ)
    )
    ; - DocToBeDestroyed notifications
    (defun MeDocToBeDestroyedCallbacks (Rea Arg)
    ;other functions...
    (MeDoCloseStuff)
    (princ)
    )
    ;
    ; - Subs ----------------------------------------------------------------------
    ;
    ; - Command ended function
    (defun MeDoCmdEndedStuff (Arg / CurCmd)
    (setq CurCmd (strcase (car Arg)))
    (cond
    ((wcmatch CurCmd "*PLOT")
    (MePlotCount)
    )
    ;;; other command dependent functions
    )
    (princ)
    )
    ; - Reactor cleanup function
    (defun MeDoCloseStuff ( / VarLst)
    (setq VarLst (MeGetReaVars))
    (mapcar 'VLR-remove (mapcar 'eval VarLst))
    (mapcar '(lambda (l) (set l nil)) VarLst)
    (princ)
    )
    ; - Collect global reactor variables
    (defun MeGetReaVars ( / RetVal)
    (foreach memb (atoms-family 1)
    (if (wcmatch (strcase memb) "ME:REA*")
    (setq RetVal (cons memb RetVal))
    )
    )
    (mapcar 'read RetVal)
    )
    ; - Plot numbering function
    (defun MePlotCount ( / AttNme AttVal BlkNme BlkObj CurSet)
    (setq BlkNme "MyPlotBlock"			;Change to your Block and
    AttNme "MYCOUNTERATTRIBUT"		;Attribute Tag name
    CurSet (ssget "X" (list '(0 . "INSERT") (cons 2 BlkNme)))
    )
    (if CurSet
    (progn
    (setq BlkObj (vlax-ename->vla-object (ssname CurSet 0))
    AttVal (1+ (atoi (cdr (assoc AttNme (MeGetAtts BlkObj)))))
    )
    (MeSetAtts BlkObj (list (cons AttNme (itoa AttVal))))
    )
    )
    (princ)
    )
    ; - Read all attribute values from a block
    (defun MeGetAtts (Obj)
    (mapcar
    '(lambda (Att)
    (cons (vla-get-TagString Att)
    (vla-get-TextString Att)
    )
    )
    (vlax-invoke Obj 'GetAttributes)
    )
    )
    ; - Sets attribute value(s) to block
    (defun MeSetAtts (Obj Lst / AttVal)
    (mapcar
    '(lambda (Att)
    (if (setq AttVal (cdr (assoc (vla-get-TagString Att) Lst)))
    (vla-put-TextString Att AttVal)
    )
    )
    (vlax-invoke Obj 'GetAttributes)
    )
    (vla-update Obj)
    (princ)
    )
    
    (princ)
    ;
    ; == End AcadDoc.lsp ==========================================================
    
    Cheers
     
    Jürg Menzi, Feb 10, 2005
    #2
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.