Author Topic: help modifying loginname portion of a lisp  (Read 2503 times)

0 Members and 1 Guest are viewing this topic.

ELOQUINTET

  • Guest
help modifying loginname portion of a lisp
« on: January 03, 2008, 09:05:52 AM »
Hey guys,

Someone wrote this lisp for me here which changes the attributed initials for who did the revision in our title block. It works great but only for me. My initials are hard coded into it and I would like to allow for others to enter theirs. How hard would this be to incorporate into it. Thanks in advance.

Code: [Select]
;-------------------------------------------------------------------------------
; c:Rev1NAME - Updates the date attributes on all tabs
;-------------------------------------------------------------------------------
(defun c:Rev1NAME (/ Ctab$ Layout$)
  (setq Ctab$ (getvar "CTAB"))
  (foreach Layout$ (layoutlist)
    (command "LAYOUT" "S" Layout$)
    ;Replace the following with your blocknames and attribute tags
    (PutBlkAttrib "Revtitle" "NAME" "D.K.")
    );foreach
  (setvar "CTAB" Ctab$)
  (princ)
);defun c:Rev1NAME
;-------------------------------------------------------------------------------
; PutBlkAttrib - Put Block Attribute value
; Arguments: 3
;   BlkOrEntity = Block or entity name
;   AttrTag$ = Tag label of attribute
;   AttrVal$ = New Value for attribute
; Returns: Changes attribute value.
; If BlkOrEntity is a block name, it changes only the first block found.
;-------------------------------------------------------------------------------
(defun PutBlkAttrib (BlkOrEntity AttrTag$ AttrVal$ / EntAttr$ EntList@ EntName^
  EntTag$ EntType$ First Passed SS&)
  (if (= (type BlkOrEntity) 'ENAME)
    (progn
      (setq EntName^ BlkOrEntity
            EntList@ (entget EntName^)
            EntType$ (cdr (assoc 0 EntList@))
      );setq
      (if (and (= EntType$ "INSERT") (assoc 66 EntList@))
        (setq Passed t First t)
      );if
    );progn
    (if (setq SS& (ssget "x" (list '(-4 . "<AND")'(0 . "INSERT")'(66 . 1)(cons 2 BlkOrEntity)(cons 410 (getvar "CTAB"))'(-4 . "AND>"))))
      (setq EntName^ (ssname SS& (1- (sslength SS&)))
            EntList@ (entget EntName^)
            Passed t First t
      );setq
    );if
  );if
  (if Passed
    (while (/= (cdr (assoc 0 EntList@)) "SEQEND")
      (setq EntList@ (entget EntName^)
            EntType$ (cdr (assoc 0 EntList@))
            EntTag$  (cdr (assoc 2 EntList@))
      );setq
      (if (= EntType$ "ATTRIB")
        (if (and (= EntTag$ (strcase AttrTag$)) First)
          (progn
            (entmod (subst (cons 1 AttrVal$) (assoc 1 EntList@) EntList@))
            (entupd EntName^)
            (setq First nil)
          );progn
        );if
      );if
      (setq EntName^ (entnext EntName^))
    );while
  );if
  (princ)
);defun PutBlkAttrib
;-------------------------------------------------------------------------------
; GetBlkAttrib - Get Block Attribute value
; Arguments: 2
;   BlkOrEntity = Block or entity name
;   AttrTag$ = Tag label of attribute
; Returns: Attribute value
; If BlkOrEntity is a block name, it gets the attribute of the first block found.
;-------------------------------------------------------------------------------
(defun GetBlkAttrib (BlkOrEntity AttrTag$ / AttrVal$ EntAttr$ EntList@ EntName^
  EntTag$ EntType$ Passed SS&)
  (if (= (type BlkOrEntity) 'ENAME)
    (progn
      (setq EntName^ BlkOrEntity
            EntList@ (entget EntName^)
            EntType$ (cdr (assoc 0 EntList@))
      );setq
      (if (and (= EntType$ "INSERT") (assoc 66 EntList@))
        (setq Passed t)
      );if
    );progn
    (if (setq SS& (ssget "x" (list '(-4 . "<AND")'(0 . "INSERT")'(66 . 1)(cons 2 BlkOrEntity)(cons 410 (getvar "CTAB"))'(-4 . "AND>"))))
      (setq EntName^ (ssname SS& (1- (sslength SS&)))
            EntList@ (entget EntName^)
            Passed t
      );setq
    );if
  );if
  (if Passed
    (while (/= (cdr (assoc 0 EntList@)) "SEQEND")
      (setq EntList@ (entget EntName^)
            EntType$ (cdr (assoc 0 EntList@))
            EntAttr$ (cdr (assoc 1 EntList@))
            EntTag$  (cdr (assoc 2 EntList@))
      );setq
      (if (= EntType$ "ATTRIB")
        (if (= EntTag$ (strcase AttrTag$)) (setq AttrVal$ EntAttr$))
      );if
      (setq EntName^ (entnext EntName^))
    );while
  );if
  AttrVal$
);defun GetBlkAttrib
« Last Edit: January 03, 2008, 09:34:36 AM by Daron »

daron

  • Guest
Re: help modifying loginname portion of a lisp
« Reply #1 on: January 03, 2008, 09:33:10 AM »
Code: [Select]
;-------------------------------------------------------------------------------
; c:Rev1NAME - Updates the date attributes on all tabs
;-------------------------------------------------------------------------------
(defun c:Rev1NAME (/ Ctab$ Layout$)
  (setq Ctab$ (getvar "CTAB"))
  (foreach Layout$ (layoutlist)
    (command "LAYOUT" "S" Layout$)
    ;Replace the following with your blocknames and attribute tags
    (PutBlkAttrib "Revtitle" "NAME" "D.K.")
    );foreach
  (setvar "CTAB" Ctab$)
  (princ)
);defun c:Rev1NAME
One way to do it would be to get user login information. Let's say your users logins are DKing or DanielK or DanielKing. If it's the first two, you can use getvar, substr, strcase and strlen functions to create a login based function and replace the "D.K." above with your new function. However, if you want something simpler, because of the third condition or lack of consistency in login name convention, you can create a function with a list of user login names and initials, then still have the computer read the login name through getvar and set the initials from that. Something like:
(list (cons "DanielKing" "D.K.")
 (cons "JoeW" "J.W.")
 (cons "TBerns" "T.B.")
)
Try it out.

ELOQUINTET

  • Guest
Re: help modifying loginname portion of a lisp
« Reply #2 on: January 03, 2008, 09:49:30 AM »
i was thinking that i may have a situation where i will have multiple users with the same initials so am not sure aquiring the info from login name would be the best way. If I am to use the list method you showed where do i put this in the code? Thanks for your help

ELOQUINTET

  • Guest
Re: help modifying loginname portion of a lisp
« Reply #3 on: January 03, 2008, 10:05:39 AM »
OK I tried to put something together but as usual went wrong somwhere. I'm getting malformed list and don't I need to get the login name beforehand. Need some help

 
Code: [Select]
(defun c:Rev1NAME (/ Ctab$ Layout$)
  (setq Ctab$ (getvar "CTAB"))
  (foreach Layout$ (layoutlist)
    (command "LAYOUT" "S" Layout$)
    ;Replace the following with your blocknames and attribute tags
    (PutBlkAttrib "Revtitle" "NAME"
     (list(cons "Danielk" "D.K.")
     (cons "Joser" "J.J.R.")
     (cons "Levk" "L.K.")
     (cons "Yasminc" "Y.C.")
     (cons "Dinam" "D.M.")
     (cons "Karlac" "K.C.")
     (cons "Malaikah" "M.H.")
     (cons "Guillerminab" "G.B.")
     (cons "Meghanp" "M.E.P.")
     (cons "Kerwinb" "K.B.")
     (cons "Salwam" "S.M.")
     (cons "Zoyad" "Z.D.")
     )
    );foreach
  (setvar "CTAB" Ctab$)
  (princ)
);defun c:Rev1NAME

terrycadd

  • Guest
Re: help modifying loginname portion of a lisp
« Reply #4 on: January 03, 2008, 10:16:31 AM »
I thought that code looked familiar. Here is the format that you need. Note that you can use all lower case, but here I chose to use all capitals.
Terry Cadd

;-------------------------------------------------------------------------------
; c:Rev1NAME - Updates the NAME attributes on all tabs
;-------------------------------------------------------------------------------
(defun c:Rev1NAME (/ Ctab$ Initials$ Layout$ Login$ LoginInitials@)
  (setq Ctab$ (getvar "CTAB"))
  (foreach Layout$ (layoutlist)
    (command "LAYOUT" "S" Layout$)
    ;Put the login names in all capitals, as some users
    ;mix the case of their login name from time to time.
    (setq LoginInitials@ (list
      (cons "DANIELKING" "D.K.")
      (cons "JOEW" "J.W.")
      (cons "TBERNS" "T.B.")
      (cons "TERRY" "T.M.")
    ));list;setq
    (setq Login$ (strcase (getvar "LOGINNAME")))
    (setq Initials$ (cdr (assoc Login$ LoginInitials@)))
    (if (not Initials$);If it's not in the list just use their login name.
      (setq Initials$ Login$)
    );if
    ;Replace the following with your blocknames and attribute tags
    (PutBlkAttrib "Revtitle" "NAME" Initials$)
  );foreach
  (setvar "CTAB" Ctab$)
  (princ)
);defun c:Rev1NAME
;-------------------------------------------------------------------------------

ELOQUINTET

  • Guest
Re: help modifying loginname portion of a lisp
« Reply #5 on: January 03, 2008, 10:57:46 AM »
I'm sorry I didn't give you credit Terry, good job. It works great exactly what I wanted. I will do some more testing and let you know if I encounter any problems. Thanks a bunch