(entprior e); opposite of (entnext e)

(entprior e); opposite of (entnext e)

Anonymous
Not applicable
878 Views
4 Replies
Message 1 of 5

(entprior e); opposite of (entnext e)

Anonymous
Not applicable

I'm writing aid function for some other coding and found I need to see the chain of entities and their properties one at a time.    [Single picks using only (car(entsel)).    Not using ssget.]

Easy enough iterating forward with (entnext e).  But sometimes I need to step back up the list in the  same way.

I combed manuals and forums but didn't find a solution.  Couldn't even find a question like this.

So I wrote the following...

 

(defun entprior (e / i e-all)
   (setq e-all (ssget "x")

         index 0 )
   (while (/= (cdr (assoc -1 (entget(ssname e-all i))))

              (cdr (assoc -1 (entget e))))
    (setq i (+ i 1)) ); while
  (setq e (ssname e-all (- i 1)))  );func

 

I feel like I just reinvented the stick.

Is there a simpler or more obvious function out there or maybe a vlx I missed?

 

Regards,

B.

0 Likes
Accepted solutions (1)
879 Views
4 Replies
Replies (4)
Message 2 of 5

Kent1Cooper
Consultant
Consultant

I can think of an approach....  I believe entity handles  [which are strings representing hexadecimal numbers] are always assigned in ever-ascending values.  There isn't always every value represented, especially if things get Erased, etc., but the order of those that exist should be the drawing order.  So if you get the handle from an entity, convert it to a base-10 integer, then count that number downward, converting each back to hexadecimal to see whether (handent) returns an entity, the first one that "hits" should be the prior entity.

 

It would take a lot more code than yours, because it needs to have the converters in both directions [but I have code to do those].  But since it doesn't have to deal with everything in the entire drawing, it could well be faster most of the time.  Is that worth pursuing?

Kent Cooper, AIA
Message 3 of 5

marko_ribar
Advisor
Advisor
Accepted solution

Study this topic entirely...

 

http://www.theswamp.org/index.php?topic=45732.0

 

Regards, M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 4 of 5

Anonymous
Not applicable

It's done it again.  Got back to check this forum saw your replies. Now Cyberspace says " ...Oh! So THAT's what you meant."  I know I used the right queries.  Enough of that.

 

So much for simple.  Thanks for reminding about the handles.  The function wouldn't run at all till I changed the test to (assoc 5...) 

 

It serves its purpose for the moment but you and others are right; its not robust.

marko_ribar sent a link http://www.theswamp.org/index.php?topic=45732.0  which has some of what you described.

 

thank you,

b

0 Likes
Message 5 of 5

Anonymous
Not applicable

Well that nailed it.  Figured on using a rope and you deliver a scissor lift.  Just the mention of extended entities told me I was oversimplifying what I needed.

0 Likes