quick lisp query

David Bethel

Usenet Archive
Joined
Nov 22, 2001
Messages
135
Reaction score
0
Step thru the insert & attrib definitions until SEQEND

SEQEND -2 points to the main insert ename.

-David
 
I have a routine that uses nentsel t9o pick an attribute within a block, I now wish to change the layer of the block that contains this attribute:

I could do a ssget through the insertion point of the attribute if there was an entprev I could step backwards and obtain the block name What is the best way to handle this using plain vanilla lisp?

Thanks

Jamie Duncan

Consulting - If you're not part of the solution, there's good money in prolonging the problem.
 
; [ename] - attrib entity name
; return: insert entity name in which [ename] is defined ; (attribInsert (car (nentsel "\nselect an attribute: "))) (defun attribInsert (ename / data) (while (and (setq ename (entnext ename)) (setq data (entget ename)) (/= "SEQEND" (cdr (assoc 0 data))) ) ) (cdr (assoc -2 data))
)
 
Jason,
thanks for correction,
just checked - for ALL insert if You DO NOT pick attribute uu
 
Jamie,
Here is a function that returns the insert without having to cycle through all the entities in the block. It takes one argument, either an entity name for an attribute object, or an active-x attribute object. The return value will be an ename if the argument was an ename, otherwise a vla-object IAcadBlockReference is returned:

(defun AttToBlockRef( ;Given an attribute entity, returns the block reference objAtt ;attribute entity or object / objAtt WasEname OwnerID objDoc objOwner ) (if (= 'ENAME (type objatt)) (setq objAtt (vlax-ename->vla-object objAtt) WasEname T ) ) (setq OwnerId (vla-get-ownerid objAtt) objDoc (vla-get-document objAtt) objOwner (vlax-invoke-method objDoc 'ObjectIDToObject OwnerId) ) (if WasEname (vlax-vla-object->ename objOwner) objOwner)
)

Mike Weaver
 
Jamie,
Another technique is to use ssget on the pick point returned by nentsel as the 2nd element of the return list:
(setq block_ename (ssname (ssget (cadr (nentsel "\nSelect attribute: "))) 0))

Of course you would have to handle errors in case the user failed to select anything or did not select an attribute. Something like the following c:test which returns the ename of the block or nil with messages.

I can't imagine a situation where ssget would not return the correct block(but my imagination is not what it used to be :-) Jason's function would be foolproof if there was a check to determine: 1) that anything had been selected and 2) the entity was an ATTRIB before proceeding to the search for the SEQEND.

(defun c:test
(COND
((not (setq nent (nentsel "\nSelect attribute: ")))
(princ "\nNo object selected: "))
((/= (CDR(ASSOC 0 (setq attrib_data (entget (car nent))))) "ATTRIB") (princ "\nAttribute selected was not an attribute: ")) (t (ssname (ssget (cadr nent)) 0)))
)
 
That is just one of those "mean and lean" toolbox type thingies. Any other checking, IMO, should be done by the calling subr.
 
It is - and I got the same answer from anither news griuo - so easy if you look under blocks in the dxf section as opposed to attribs.

Thanks Herman.
 

Latest threads

Back
Top