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

Update LISP to copy AS FIELD all matching attributes from one block to another

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
raghood
2902 Views, 6 Replies

Update LISP to copy AS FIELD all matching attributes from one block to another

Hi there, its the first time i am posting though im reviwing posts and much more long time and its really a great place to learn,

 

i am working on an new system to work with plans with pre-custom Blocks & Dynamic Blocks, , as in the finalizing stage, i have this case i need help in,

 

i have a block with multiple attributes , i want to copy the attributes values "AS FIELDS" to another different block, so the second one is always updated when i change the first one values, and i want to do it once,

 

i have a LISP that copy content as field but i have to click each attritube , and i have another LISP that copy all attributes with same tags from a block to another once and its perfect,but unfortiontly dont copy as fields value, just copy all once.

 

is there a way to combine these lisps or if simpler update the LISP that copy all block attributes to be copy as field all block attributes once

 

im attaching LISPS with all respect to whom wrote these lisps, and the cad file with both blocks i need to copy as field between,

I need to copy from the "DATA BLOCK" to the "DOORS" Dynamic block as fields all matching attributes,

Kindly and please assist me in these as i am still a junior in the LISPS functions and modifications

 

 

6 REPLIES 6
Message 2 of 7
pbejse
in reply to: raghood


@raghood wrote:

Hi there, its the first time i am posting though im reviwing posts and much more long time and its really a great place to learn,

.....

I need to copy from the "DATA BLOCK" to the "DOORS" Dynamic block as fields all matching attributes,

Kindly and please assist me in these as i am still a junior in the LISPS functions and modifications

 

 


Welcome to Autodesk Lisp Forum raghood. Try this 

 

(defun C:MTB2 (/  ename enam data ss)
;;;	pBe Dec2014					;;;
  (while (not
	   (progn
	     (prompt "\nSelect Source Block:")
	     (setq ename (ssget "_:S:E" '((0 . "INSERT") (66 . 1))))
	   )
	 )
    (princ "\nInvalid or null selection")
  )
  (cond
    ((and
       (setq enam (ssname ename 0))
       (setq data (_FieldsVal enam t nil));<-- Get Mode & Fields mode
       (prompt "\n<<<Select blocks to process>>>")
       (setq ss (ssget "_:L" '((0 . "INSERT") (66 . 1))))
       (repeat (setq i (sslength ss))
	 (_FieldsVal (ssname ss (setq i (1- i))) nil data);<-- Set Mode 
       )
     )
    )
  )
  (vla-regen (vla-get-ActiveDocument (vlax-get-acad-object))
	     acActiveViewport
  )
  (princ)
)
   

;;;		    <<< pBe >>>				;;;
;;; 	Subfunction to Attribute Set/Get Fields/TEXT	;;;
;;;	blk = The attribute block			;;;
;;;	mode 	= T for Field Values			;;;
;;;  		= nil for String Values			;;;
;;;	lst	= If supplied, function in Set Mode 	;;;
;;;		= nil for Get Mode			;;;
  
  (defun _FieldsVal (blk mode lst / m f)
    (setq f (if	mode
	      (lambda (e)
		(strcat "%<\\AcObjProp Object(%<\\_ObjId "
			(itoa (vla-get-ObjectId e))
			">%).TextString>%")
	      )
	      (lambda (e) (vla-get-textstring e))
	    )
    )
    (mapcar '(lambda (at)
	       (if lst
		 (if (setq m (assoc (vla-get-tagstring at) lst))
		   (vla-put-textstring at (cadr m))
		 )
		 (list (vla-get-tagstring at) (f at))
	       )
	       )
	    (vlax-invoke (vlax-ename->vla-object blk) 'Getattributes)
    )
  )
;;;		End of _FieldsVal			;;;

(vl-load-com)

 

command: MTB2

 

You can use the sunfuction _FieldsVal even to get non field value.

 

(setq data (_FieldsVal enam nil nil));<-- that will give you the literal textsring value

 

HTH

 

Message 3 of 7
raghood
in reply to: pbejse

Hi Pbejse,

Thanks alot & appreciate your quick reply and time given,

i tried to test the lisp but it keep showing this text and stops the command

 

" Command: MTB2
Select Source Block:
Select objects:
<<<Select blocks to process>>>Regenerating model.
Command:  "

 

as if it jumps to other second command before i select any,

is it something i did wrong or it need to be modified ?

 

thanks again for your cooperation with me

 

i am attaching the LISP you sent to check,

 

 

Message 4 of 7
pbejse
in reply to: raghood


@raghood wrote:

Hi Pbejse,

Thanks alot & appreciate your quick reply and time given,

i tried to test the lisp but it keep showing this text and stops the command

 

" Command: MTB2
Select Source Block:
Select objects:
<<<Select blocks to process>>>Regenerating model.
Command:  "

 

as if it jumps to other second command before i select any,

is it something i did wrong or it need to be modified ?

 

thanks again for your cooperation with me

 

i am attaching the LISP you sent to check,

 

 


My bad dude,

 

change

(prompt "\n<<<Select blocks to process>>>")

 

to

(princ "\n<<<Select blocks to process>>>")

 prompt evaluates to nil.

 

HTh

 

Message 5 of 7
raghood
in reply to: pbejse

it is great now, it works perfectly and works just as i wanted and searched for it long time ! Smiley LOL

appreciated and many thanks

 

any advice from where i can start to study/understand lisp language,

i am able to do some tiny changes to writen ones not yet the whole text,

 

i am attaching the final lisp to share with others,

Thanks !

Message 6 of 7
pbejse
in reply to: raghood


@raghood wrote:

it is great now, it works perfectly and works just as i wanted and searched for it long time ! Smiley LOL

appreciated and many thanks

 

any advice from where i can start to study/understand lisp language,

i am able to do some tiny changes to writen ones not yet the whole text,

 

i am attaching the final lisp to share with others,

Thanks !


You are welcome raghood, I'm happy to help 🙂

 

As for the advice, just practice, practice, practice.... and read, read, read some more. it all starts with YOU, dont find time, make time. and ask questions here, forum members are more than happy to help you with your study.

 

I personally started here --> Afralisp

 

pBe

 

Message 7 of 7
pessi.symb
in reply to: raghood

Hi I have almost the same situation but in my case, I need to select a Room number from an xref'd file and paste the value as field to my room tag.

 

Can the lisp CopyAsField be modified so that when I changed the room number in the xref, the tag also changes...

 

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

Post to forums  

”Boost