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

Retrieving # of entities in a dynamic block ?

4 REPLIES 4
Reply
Message 1 of 5
royboy666
544 Views, 4 Replies

Retrieving # of entities in a dynamic block ?

I am modifying stuff in a dynamic block insert entitity. There is no "endblk" entity at the end of these definitions and I need to cycle through every entity within the block definition. When it gets to the last entity,  I get an error because you cannot entnext passed the last entity. There are 2 things I could use help with:

 

1. How to retrieve the # of entities in a block without cycling through it.

 

Or

 

2. A quick lesson in the *error* function, I cannot figure out how to implement this. I basically want to to say:

(if (entnext myent)) returns a error, don't abort & continue on.

 

Is this possible ?

 

Thanks

4 REPLIES 4
Message 2 of 5
jsowinski
in reply to: royboy666

Here is one way to get the number of entities in a dynamic block. You can easily add your code to this. "cnt" is your entity count.  Note that there isn't any error code.

 

(defun c:entcount (/ doc ent cnt)
(vl-load-com)
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(setq ent (vlax-ename->vla-object (car (entsel))))
(setq cnt (vla-get-count (vla-item (vla-get-blocks doc)(vla-get-EffectiveName ent))))
)

 

Message 3 of 5
royboy666
in reply to: royboy666

That is awsome, thanks. I have been inserting a "point" entitiy within my blocks as the last thing I do, trying to get it as the last item in the block, when the code entnexted through the definition if it hit a "point" entity it would stop the loop. Most of the time it worked well.

 

Its weird how autocad designed these dynamic blocks, seems that only the entities that have a dynamic parameter on them are put into an additional anonymous block, I guess when the program looks at the block, it gathers the info from the insert entity, then continues to the actual block definition for the rest of the block where the "endblk" listing is.

 

Thanks again

Message 4 of 5
jsowinski
in reply to: royboy666

I'm glad it worked!
Message 5 of 5
royboy666
in reply to: jsowinski

Yes it did, perfectly. I need to pay more attention to the visual lisp stuff, Im working my way up there.

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

Post to forums  

Autodesk Design & Make Report

”Boost