Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: LISP NEEDED - Copy attribute and paste as single line text

  1. #1
    Member
    Join Date
    2013-01
    Posts
    11
    Login to Give a bone
    0

    Talking LISP NEEDED - Copy attribute and paste as single line text

    Hi Guys,

    Just need some help with a lisp routine. I have honestly no idea of how to start one but i am able to modify what is made.
    Basically, what i need is a routine the copy's the value of the attribute then pastes the value as a (separate) single line text next to it. Simple routine though some of you guys are there are wizards at this stuff.....

    Thanks!

    Rico

  2. #2
    Member
    Join Date
    2013-03
    Posts
    3
    Login to Give a bone
    0

    Default Re: LISP NEEDED - Copy attribute and paste as single line text

    Not exactly what you asked for but closest thing I have. This will copy from an attribute to existing single line text or vice versa or text to text or att to att - doesn.'t care but both have to be existing. You could tweak it to create the new line of text though pretty easily.

    Code:
    ;Command Name Is TXTCOPY
    (defun c:txtcopy ( / PRM1 PRM2  TCF TCT TMP)
    	(alpha)
                  (setq TMP '("TEXT" "ATTRIB")
                           PRM1 "\nSelect text to copy from: "
                           PRM2 "\nINVALID: Entity selected must be an attribute or single line text!"
                  )
    	(while t
    		(while (not (member (ecinf (setq TCF (car (nentsel PRM1))) 0) TMP))
    			(prompt PRM2)
    		)
    		(while (not (member (ecinf (setq TCT (car (nentsel PRM1))) 0) TMP))
    			(prompt PRM2)
    		)
    		(modent TCT 1 (ecinf TCF 1))
    		(if (= (ecinf TCT 0) "ATTRIB") (attupd TCT))
    	)
    	(omega))
    
    
    ;This is a set of standard routines I use A LOT.
    
    ;ALPHA sets a couple of variables and sets the error to run OMEGA if the command is canceled.
    (defun ALPHA ()
    	(defun *error* (MSG)
    		(if (/= MSG "Function cancelled")
    			(princ (strcat "\nerror: " MSG))
    		)
    		(omega)
    	)
    	(sv '("cmdecho" "attdia") 0 t)
    )
    
    ;ECINF just gets the entity code info needed
    (defun ECINF (EN EC)
    	(if (= (type EN) 'ENAME)
    		(cdr (assoc EC (entget EN)))
    		(cdr (assoc EC EN))
    )	)
    
    'MODENT modifys the entity code
    (defun MODENT (EN EC EV)
    	(entmod (subst (cons EC EV) (assoc EC (entget EN)) (entget EN)))
    )
    
    ;SV is a standard routine that saves the current setting of variables to a list for resetting with OMEGA and sets them per ALPHA
    (defun SV (VN V? AL / CV)
    	(while VN
    		(if (and	 (not (member (setq CV (car VN)) VL))	 (= AL t))
    			(setq VL (append VL (list CV (getvar CV))))
    		)
    		(setvar CV V?)
    		(setq VN (cdr VN))
    )	)
    
    ;OMEGA resets all the variables set by SV
    (defun OMEGA ()
    	(while VL (setvar (car VL) (cadr VL)) (setq VL (cddr VL)))
    		(setq CMMAND nil)
    	)
    (princ))

    Rick France
    Solutions Engineer
    Hagerman & Company
    Last edited by rfrance366550; 2013-03-21 at 06:50 PM.

  3. #3
    All AUGI, all the time
    Join Date
    2010-10
    Posts
    535
    Login to Give a bone
    0

    Default Re: LISP NEEDED - Copy attribute and paste as single line text

    Quote Originally Posted by ECASAOL350033 View Post
    Hi Guys,
    what i need is a routine the copy's the value of the attribute then pastes the value as a (separate) single line text next to it.....

    Thanks!

    Rico
    A simple solution:

    Code:
    (defun c:demo ()
    (vl-load-com)  
      	(if (and (setq att (Car (nentselp "\nSelect Attribute: ")))
                    (eq (cdr (Assoc 0 (setq en (entget att)))) "ATTRIB"))
    	(progn
              	(Setq data (cons '(0 . "TEXT") (vl-remove-if-not '(lambda (x)
                                         	(member (car x) '( 1 10 7 8  41 40 50))) en)))
              	(entmakex data)
              (command "_move" (entlast) "" "_non" (Cdr (caddr data)) pause)
              )))

  4. #4
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,269
    Login to Give a bone
    0

    Default Re: LISP NEEDED - Copy attribute and paste as single line text

    Awesome,
    Kind regards,

  5. #5
    Member
    Join Date
    2012-05
    Location
    Planet Earth
    Posts
    10
    Login to Give a bone
    0

    Default Re: LISP NEEDED - Copy attribute and paste as single line text

    Quote Originally Posted by pbejse View Post
    A simple solution:

    Code:
    (defun c:demo ()
    (vl-load-com)  
      	(if (and (setq att (Car (nentselp "\nSelect Attribute: ")))
                    (eq (cdr (Assoc 0 (setq en (entget att)))) "ATTRIB"))
    	(progn
              	(Setq data (cons '(0 . "TEXT") (vl-remove-if-not '(lambda (x)
                                         	(member (car x) '( 1 10 7 8  41 40 50))) en)))
              	(entmakex data)
              (command "_move" (entlast) "" "_non" (Cdr (caddr data)) pause)
              )))

    Can it be customised in a way to let user select multiple attributes at the same time (from several blocks maybe) ?

  6. #6
    All AUGI, all the time
    Join Date
    2010-10
    Posts
    535
    Login to Give a bone
    0

    Default Re: LISP NEEDED - Copy attribute and paste as single line text

    Quote Originally Posted by fixo View Post
    Awesome,
    Kind regards,
    Thank you Oleg

    Quote Originally Posted by Bababarghi View Post
    Can it be customised in a way to let user select multiple attributes at the same time (from several blocks maybe) ?
    Yes, it can be done.

  7. #7
    Member
    Join Date
    2012-05
    Location
    Planet Earth
    Posts
    10
    Login to Give a bone
    0

    Default Re: LISP NEEDED - Copy attribute and paste as single line text

    Quote Originally Posted by pbejse View Post
    Yes, it can be done.
    I actually meant 'how' ?!

  8. #8
    All AUGI, all the time
    Join Date
    2010-10
    Posts
    535
    Login to Give a bone
    0

    Default Re: LISP NEEDED - Copy attribute and paste as single line text

    Quote Originally Posted by Bababarghi View Post
    I actually meant 'how' ?!
    I know that Bababarghi
    Here's "How"

    - wrap the nentselp prompt inside a while function
    - process each item of selected ATTRIB with foreach using the method on the previous code
    - change the (enlast) to a selection set <from the process> on the move command

    Will that work for you?


    As for the CODE: I would want you to try and figure it out from the "how" statement above before you take a peek at the code below [Don't scroll down <Spoiler>]
    Code:
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    (defun c:demo (/ attr_ att data en)
      (vl-load-com)
      (setq attr_ nil)
      (while
        (and (princ	(strcat	"\nCurrent number of selected attribute: "
    			(itoa (length attr_))
    		)
    	 )
    	 (setq att (Car (nentselp "\nSelect Attribute: ")))
    	 (eq (cdr (Assoc 0 (setq en (entget att)))) "ATTRIB")
        )
         (setq attr_ (cons en attr_))
      )
      (if attr_
        (progn
          (setq attrss (ssadd))
          (foreach _att attr_
    	(Setq data (cons '(0 . "TEXT")
    			 (vl-remove-if-not
    			   '(lambda (x)
    			      (member (car x) '(1 10 7 8 41 40 50))
    			    )
    			   _att
    			 )
    		   )
    	)
    	(ssadd (entmakex data) attrss)
          )
          (command "_move" attrss "" "_non" (Cdr (caddr data)) pause)
        )
      )
      (princ)
    )
    Last edited by pbejse; 2014-02-07 at 06:15 AM.

  9. #9
    Member
    Join Date
    2012-05
    Location
    Planet Earth
    Posts
    10
    Login to Give a bone
    0

    Default Re: LISP NEEDED - Copy attribute and paste as single line text

    Quote Originally Posted by pbejse View Post
    I know that Bababarghi
    Here's "How"

    - wrap the nentselp prompt inside a while function
    - process each item of selected ATTRIB with foreach using the method on the previous code
    - change the (enlast) to a selection set <from the process> on the move command

    Will that work for you?


    As for the CODE: I would want you to try and figure it out from the "how" statement above before you take a peek at the code below [Don't scroll down <Spoiler>]
    Thanks PMpbejse. I liked your approach. I reckon you are, or have been, a teacher - at least at some stages of your career !

    I am so-called an absolute 'beginner' when it comes to LSP programming but I am sure I can handle it soon or late.

    Just one more massage request for the code: How can I select my desired attributes by a crossing window?

  10. #10
    All AUGI, all the time
    Join Date
    2010-10
    Posts
    535
    Login to Give a bone
    0

    Default Re: LISP NEEDED - Copy attribute and paste as single line text

    Quote Originally Posted by Bababarghi View Post
    Thanks PMpbejse
    Just one more massage request for the code: How can I select my desired attributes by a crossing window?
    To be on the clear, you are wanting to select a specific attribute in a block with as "crossing window" but not necessarily ALL the attdefs on that block?

    Code:
    (Defun c:CAt (/ attr_ ss e n data attrss)
    ;;;	pBeFeb2014	;;;
      (if (setq attr_ nil
    	    ss	  (ssget '((0 . "INSERT") (66 . 1)))
          )
        (progn
          (repeat (setq i (sslength ss))
    	(setq n (entnext (ssname ss (setq i (1- i)))))
    	(while (not (eq (cdr (assoc 0 (setq e (entget n)))) "SEQEND"))
    	  (if (/= (cdr (assoc 1 e)) "")
    	    (setq attr_ (cons e attr_))
    	  )
    	  (setq n (entnext n))
    	)
          )
          (if attr_
    	(progn
    	  (setq attrss (ssadd))
    	  (foreach _att	attr_
    	    (Setq
    	      data (cons '(0 . "TEXT")
    			 (vl-remove-if-not
    			   '(lambda (x)
    			      (member (car x) '(1 10 7 8 41 40 50))
    			    )
    			   _att
    			 )
    		   )
    	    )
    	    (ssadd (entmakex data) attrss)
    	  )
    	  (command "_move" attrss "" "_non" (Cdr (caddr data)) pause)
    	)
          )
        )
      )
      (princ)
    )
    Last edited by pbejse; 2014-02-10 at 09:56 AM.

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 3
    Last Post: 2012-01-19, 05:59 PM
  2. Replies: 0
    Last Post: 2011-09-23, 07:21 PM
  3. 2011: LISP, script or action recorder to copy-and-paste text into attributes?
    By simon.bannister in forum AutoCAD General
    Replies: 3
    Last Post: 2011-03-23, 11:55 AM
  4. turn single line of attribute text into two lines
    By JRBOURNE in forum Dynamic Blocks - Technical
    Replies: 4
    Last Post: 2009-12-23, 04:40 PM
  5. AutoCAPS for Single Line and Attribute Text
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 3
    Last Post: 2007-11-09, 06:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •