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

edit geometric attvalues in a template block

7 REPLIES 7
Reply
Message 1 of 8
anct
154 Views, 7 Replies

edit geometric attvalues in a template block

Dear sirs,
I'm working on a routine wich could extract area and perimeter values from a polyline, and than assign them to a specific existing block by simply picking it.

At the moment I've managed to select the poly, extract and setq the area and perimeter values, select the block... but how to identify the attribute values nested in a block, in order to edit them?

thank you for your time
7 REPLIES 7
Message 2 of 8
EC-CAD
in reply to: anct

anct,
Attached should do the trick.
Cheers

Bob
Message 3 of 8
Anonymous
in reply to: anct

Hello, Please have a look at the free downloads area on our web-site (See TechCenter URL - www.4d-technologies.com/techcenter) The Blocks library provides a number of functions to easily process blocks and attributes. In particular, the functions that you would find useful are: (BL_WriteAttr ...) (BL_WriteAttrNo ...) (BL_ReadAttr ...) (BL_ReadAttrNo ...) In addition, you may find a lot of other useful tools for working with other AutoCAD objects. Regards Rakesh anct wrote: > Dear sirs, > I'm working on a routine wich could extract area and perimeter values from a polyline, and than assign them to a specific existing block by simply picking it. > > At the moment I've managed to select the poly, extract and setq the area and perimeter values, select the block... but how to identify the attribute values nested in a block, in order to edit them? > > thank you for your time > > > ------------------------------------------------------------------------ > > (defun C:UPDAP (/ A P obj) > > ;;;****************EXTRACTS AREA AND PERIMETER FROM POLYLINES > (command "area" "object" (setq obj (entsel))) > ;ENTER TO EXIT LOOP. ERRNO 52? > > (if (= (getvar "errno") 0) > > (progn > (setq A (rtos (getvar "area") 2 0)) > (setq P (rtos (getvar "perimeter") 2 0)) > (princ "\nArea: ") > (princ A) > (princ "\nPerimeter: ") > (princ P) > (princ) > (BLKSEL) > ) > > (progn > (princ "pick!!") > (setvar "errno" 0) > ) ;end progn > > > ) ;end if > ) > ;;end defun > ;;;***************SELECTS OUR ALREADY PLACED BLOCK > (defun BLKSEL (/ BSEL BGET) > (while > (OR (NULL BSEL) > (/= (cdr (assoc 2 BGET)) "Ourblock") > ) > (progn > (setq BSEL (ENTSEL "\nSelect one of ourBlocks:")) > (setq BGET (entget (CAR BSEL))) > > ) > > ) > (BLKMOD BSEL A P) > ) > ;;;***********************SHOULD FIND THE CURRENT VALUES OF AREA AND PERIMETER AND UPDATE THEM WITH THE NEW A AND P VALUES > ;;;***********************ATTRIBUTE TAGS ARE "AA" AND "PP" > (defun BLKMOD (BSEL A P / SUBENT SUBGET ATTTAG SUBLIST) > > (setq SUBENT (entnext (car BSEL)));;;car BSLEL acquires entity code, without the selecting point info > (princ "step-1, ok") > > ;;;***********************THAT'S SOMETHING I HOPLESSY TRIED > > > > (while (or (= (cdr (assoc 0 SUBGET)) "ATTRIB") (NULL subget)) > (setq SUBGET (entget SUBENT)) > (setq ATTTAG (cdr (assoc 2 SUBGET))) > (if (= ATTTAG "AA") > (entmod (subst A (cdr (assoc 1 SUBGET)) SUBGET)) > > ;;; (entmod SUBGET) > > > > ) > ;;end if > (setq SUBENT (entnext SUBENT)) > > ;;; (if (= ATTTAG "PP") > ;;; (setq SUBENT (subst (cons "0" P) > ;;; (cdr (assoc 1 SUBENT)) > ;;; SUBENT > ;;; ) > ;;; ;;end subst > ;;; ) > ;;; ;;end setq > ;;; );;end if > > > > )(princ "done") > ;;end while > ) > > > ;;;************************************************************************************************************* > (alert > "\n\tLoaded A-P LISP. Type UPDAP to begin." > ) > (princ) -- Please email me your replies. I may not always be observing the posts here. AutoCAD customization for Engineering/Mapping/GIS Get GeoTools @ http://www.4d-technologies.com/geotools Build MyGeoTools @ http://www.4d-technologies.com/geotools/my_geotools.htm FREE downloads : http://www.4d-technologies.com/techcenter
Message 4 of 8
anct
in reply to: anct

Thank you for your amazing and prompt work.
I've tried the routine, and it seems to stop one step away from editing the attvalues.
I'm going to study it anyway, but since I will need some time, I'll try to ask you some check, and attach the template block.

I'll just add:
1-A (to me) seemingly inconsistent BGET variable in the block selection routine
2-Since the indicator blocks are linked to an unique poly, a one-pick entsel style selection is to be preferred. (it's assured I'll make use of the ssget formula anyway : ))

Andrea
Message 5 of 8
anct
in reply to: anct

I' m checking... they seem perfect.
I think I'll get trough by myself.
Thank you
Message 6 of 8
EC-CAD
in reply to: anct

Andrea,
A couple of typos in my last post.
Replace function blkmod with:

(defun BLKMOD (BSEL A P / ssl c d chk av cx tname en)
(setq ssl (sslength BSEL)); selection set length..
(setq C 0); C = entity selecter, starts at 0, goes 1,2,3..
(repeat ssl
(setq D (ssname BSEL C)); get entity name from 'ss', if no name, D is nil.
(if (/= D nil); found something ?
(progn
(setq chk (entget D)); chk used to hold each entity 'list' item.
(if (and
(= "INSERT" (cdr (assoc 0 chk))) ; case of BLOCKS
(/= (cdr (assoc 66 chk)) nil); with Attrib's following
); end and
(progn
(setq av nil CX 1); init inside loop
(while (> CX 0)
(setq en (entget (entnext (dxf -1 chk)))); sub-entity
(setq abn (cdr (assoc 0 en))); name of item
(setq chk en); swap to next Attrib
(if (or (= "INSERT" abn)(= "SEQEND" abn))
(setq CX 0)
); end if
;; - if not at end of Attributes, keep going
(if (= "ATTRIB" abn)
(progn
(setq av (cdr (assoc 1 en))); get the attrib value - not used
(setq tag (strcase (cdr (assoc 2 en)))); get the attrib tag name
(if (= tag "AA")
(progn
(entmod (setq en (subst (cons 1 A)(assoc 1 en) en)))
(entupd D)
); end progn
); end if
(if (= tag "PP")
(progn
(entmod (setq en (subst (cons 1 P)(assoc 1 en) en)))
(entupd D)
); end progn
); end if
); end progn
); end if
); end while CX > 1
); end progn
); end if INSERT
); end progn
); end if D /= nil
(setq C (+ C 1)); ratchet counter C to get next entity.
); end repeat ssl
;;
(princ "done")
);end function

Bob
Message 7 of 8
EC-CAD
in reply to: anct

Andrea,
Attached is latest. Had to explode the block, to get
into 'insert' attributes...
Cheers.

Bob
Message 8 of 8
anct
in reply to: anct

Your routine works to perfection.
The nested block...it was a terrible oversight of mine...
I've therefore edited your routine and safely cut away the "expolde" part.
I'm Sorry for the unnecessary overload.
Thanks a lot.
Andrea

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

Post to forums  

Autodesk Design & Make Report

”Boost