PDA

View Full Version : Editing Attributes Through LISP


mraafateg
2006-11-02, 04:56 PM
Hi,
How can I edit an attribute within a block through AutoLISP?
In addition, how can I check whether a selection set contains objects through AutoLISP?
Thanks!

Mike.Perry
2006-11-03, 08:41 AM
Hi "mraafateg" ( Sorry, I do not know your real name )

Please note I have *moved* this thread from the AutoCAD Customization (http://forums.augi.com/forumdisplay.php?f=118) forum to this one, as I believe it will be better served here.

Thanks, Mike

Forum Moderator

kennet.sjoberg
2006-11-03, 09:14 AM
How can I edit an attribute within a block through AutoLISP? . . .
To edit an attribute within a block through AutoLISP you must first select the block it belongs to
after that you must iterate trough all attributes "entnext" to find the "TAG" you search for
then you must modify "subst" the attributes dxf code "entget"
and then update the code "entmod" and the block "entupd".

Check this LINK (http://forums.augi.com/showthread.php?t=47670#post572465)

In addition, how can I check whether a selection set contains objects through AutoLISP? . . .

To find out if a selection set contains objects through AutoLISP is more easy
the selectionset is nil if there is no objects
"sslength" shows how many objects it contains
"ssname" take one of the objects in the selectionset.

Example:
(setq SelSet (ssget) ) ; --> <Selection set: 8>
(sslength SelSet ) ; --> 5
(ssname SelSet 2 ) ; --> <Entity name: 40077f40> third object in SelSet ( 0 is first )


: ) Happy Computing !

kennet

kpblc2000
2006-11-03, 09:27 AM
To check selection set try to use this:
(if (setq selset (ssget))
(progn
;; Some objects selected
)
(alert "Nothing selected!")
)
To edit attribute in block you can use something like this:
;|
* Returns list of vla-pointers to attributes of block reference.
* block contains no attributes -> nil
* block contains no attributes with mask -> nil
* any else -> list of attributes
* Call samples:
(_kpblc-block-attr-get-pointer-mask (car (entsel)) "*")
; returns something like this:
; '(#<VLA-OBJECT IAcadAttributeReference 091ec904>) ; (only one attribute)
|;
(defun _kpblc-block-attr-get-pointer-mask (blk mask / res)
(setq blk (cond
((= (type blk) 'vla-object) blk)
((= (type blk) 'ename) (vlax-ename->vla-object blk))
(t nil)
) ;_ end of cond
) ;_ end of setq
(if (and blk
(= (strcase (vla-get-objectname blk) t) "acdbblockreference")
(>= (vlax-safearray-get-u-bound
(vlax-variant-value (vla-getattributes blk))
1
) ;_ end of vlax-safearray-get-u-bound
0
) ;_ end of >
) ;_ end of and
(setq res
(vl-sort
(vl-remove-if-not
'(lambda (x)
(wcmatch (strcase (vla-get-tagstring x)) (strcase mask))
) ;_ end of LAMBDA
(vlax-safearray->list (vlax-variant-value (vla-getattributes blk)))
) ;_ end of vl-remove-if-not
'(lambda (a b)
(< (strcase (vla-get-tagstring a)) (strcase (vla-get-tagstring b)))
) ;_ end of LAMBDA
) ;_ end of vl-sort
) ;_ end of setq
) ;_ end of if
res
) ;_ end of defun
Using sample:
(mapcar
'(lambda (x)
(vl-catch-all-apply
'(lambda ()
(vla-put-textstring
(_kpblc-block-attr-get-pointer-mask (car (entsel)) "MyAttTag")
) ;_ end of vla-put-textstring
) ;_ end of lambda
) ;_ end of vl-catch-all-apply
) ;_ end of lambda
) ;_ end of mapcar

kennet.sjoberg
2006-11-03, 09:44 AM
?
Hi,
How can I . . . through AutoLISP?

: ) Happy Computing !

kennet

kpblc2000
2006-11-03, 09:57 AM
Does the code not AutoLISP? It uses activex-functions but it still autolisp (i hope).

kennet.sjoberg
2006-11-03, 10:08 AM
Does the code not AutoLISP? It uses activex-functions but it still autolisp (i hope).
I would say that you can run AutoLISP in all versions of AutoCAD.

You can use Visual LISP to access AxtiveX objects from AutoLISP code
and attach reactors to entities, but not in AutoCAD below R2000.

: ) Happy Computing !

kennet

mraafateg
2006-11-08, 10:37 AM
Thanks everyone!
I was out of the office for a few days and only just got to see your replies.
Thank you all!