Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LISP to copy attribute value within a block to another attribute - help please

5 REPLIES 5
Reply
Message 1 of 6
Anonymous
5013 Views, 5 Replies

LISP to copy attribute value within a block to another attribute - help please

Hello all. I'm trying to write a LISP routine and I'm not very good at it. I was wondering if I could ask for help.

I'm trying to write a LISP that will copy the value from one attribute to another, all within the same block. I've found a LISP similar online, but it uses screen clicks. I want to use this in a script so the LISP has to use command prompts. I'd like the command line prompts to go like this:

1. Block name?

2. FROM attribute tag?

3. TO attribute tag?

 

I've attached a copy of the code. I don't know where I'm going wrong. Can someone take a look at it? Thanks.

-Justin

5 REPLIES 5
Message 2 of 6
mid-awe
in reply to: Anonymous


@Anonymous wrote:

Hello all. I'm trying to write a LISP routine and I'm not very good at it. I was wondering if I could ask for help.

I'm trying to write a LISP that will copy the value from one attribute to another, all within the same block. I've found a LISP similar online, but it uses screen clicks. I want to use this in a script so the LISP has to use command prompts. I'd like the command line prompts to go like this:

1. Block name?

2. FROM attribute tag?

3. TO attribute tag?

 

I've attached a copy of the code. I don't know where I'm going wrong. Can someone take a look at it? Thanks.

-Justin


Ok, this has very little error catching and even less testing, but it should work as requested.

 

(DEFUN GET-ATT (tag blk / val enx) ; Thank you Lee Mac
  (SETQ blk (SSNAME (SSGET "x" (LIST '(0 . "INSERT") (CONS 2 blk) (CONS 410 (GETVAR 'ctab)))) 0))
  (WHILE
    (AND
      (NULL val)
      (= "ATTRIB" (CDR (ASSOC 0 (SETQ enx (ENTGET (SETQ blk (ENTNEXT blk)))))))
    )
     (IF (= (STRCASE tag) (STRCASE (CDR (ASSOC 2 enx))))
       (SETQ val (CDR (ASSOC 1 enx)))
     )
  )
)

(DEFUN PUT-ATT (blk tag val / end enx) ; Again, thank you Lee Mac
  (SETQ blk (SSNAME (SSGET "x" (LIST '(0 . "INSERT") (CONS 2 blk) (CONS 410 (GETVAR 'ctab)))) 0))
  (WHILE (AND (NULL end) (= "ATTRIB" (CDR (ASSOC 0 (SETQ enx (ENTGET (SETQ blk (ENTNEXT blk))))))))
    (IF	(= (STRCASE tag) (STRCASE (CDR (ASSOC 2 enx))))
      (IF (ENTMOD (SUBST (CONS 1 val) (ASSOC 1 enx) enx))
	(PROGN (ENTUPD blk) (SETQ end val))
      )
    )
  )
)

(DEFUN COPY-ATT	(BLOCKNAME FROMatt TOatt / VALUE) ; You mentioned scripting and so I put a function.
  (SETQ VALUE (GET-ATT FROMatt BLOCKNAME))
  (PUT-ATT BLOCKNAME TOatt VALUE)
)

(DEFUN C:COPY-ATT (/ BLOCKNAME FROMatt TOatt) ; The main command :: uses the function.
  (SETQ	BLOCKNAME (GETSTRING "\n\t=> Block name? ")
	FROMatt	  (GETSTRING "\n\t=> FROM attribute tag? ")
	TOatt	  (GETSTRING "\n\t=> TO attribute tag? ")
  )
  (IF (TBLSEARCH "BLOCK" BLOCKNAME) (COPY-ATT BLOCKNAME FROMatt TOatt) (PRINC "\n BLOCK NOT FOUND"))
)

 

(By The Way the borrowed functions from Lee Mac can be found on his website HERE:-> http://www.lee-mac.com/attributefunctions.html )

 

Message 3 of 6
mid-awe
in reply to: mid-awe
Message 4 of 6
Anonymous
in reply to: mid-awe

You sir, are awesome. Thanks for putting that together. Works great. I see that it doesn't find multiple instances of the same blocks though. In my original code you can see a repeat loop in there to go through every found block name. But this works fantastic. I think I can modify it to take care of multiple blocks. And thanks for the website link. Very useful.

Message 5 of 6
mid-awe
in reply to: Anonymous

"You sir, are awesome. Thanks for putting that together. Works great."

You are welcome. I am glad to help.

"thanks for the website link. Very useful"

Lee Mac's website is a treasure trove. Much to learn there. Lee also frequently visits here and is always generous.
Message 6 of 6
Anonymous
in reply to: mid-awe

mid-awe, thanks again for your help.

I've modified the code you gave me to update all blocks in the drawing with the same name. I've attached it to this post so others can use it.

Your original code will find the first instance of the block and modify it (useful for something like a titleblock because there really shouldn't be more than 1 titleblock in a drawing.)

The attached code will find all instances of the block name in the drawing and update all of them, even across model space and layouts.

This way, one can pick which lisp works best for them. Always good to have choices.

Have a great day.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost