Jump to content

Stepping thru selection set for a single attribute multiple times.


The Buzzard

Recommended Posts

Hello All,

 

The posted code I have works great, However I seem to find it overkill to step thru a selection set again for the same attribute. I tried a couple of different ways to no avail to edit an attribute multiple times in a single selection set, But could not get it to work correctly. Any guidence would be greatly appreciated.

 

Thanks in advance,

The Buzzard

 

;/////////////////////////////////////////////////////////////////////////////////////////
;
; F06 - Increment Attribute Value.
;
(defun CIT_IAV ()
 (cond
   ((= CIT:IDFS "0")(setq ATAG$ (strcat ""FLRN$"-"BTAG$"-"SEQN$"")))
   ((= CIT:IDFS "1")(setq ATAG$ (strcat ""FLRN$""IDFR$"-"BTAG$"-"SEQN$""))))
 (setq SSET  (ssget "_l" (list (cons 0 "INSERT")(cons 66 1)))
       INDX 0
       ENAM  (ssname SSET INDX)
       ELST (entget ENAM))
 (while
   (/= (cdr (assoc 0 ELST)) "SEQEND")
   (setq ELST (entget ENAM))
   (if
     (= "ID-TAG" (cdr (assoc 2 ELST)))
     (progn
       (entmod (subst (cons 1 ATAG$)(assoc 1 ELST) ELST))
       (entupd ENAM)))
   (setq ENAM (entnext ENAM)))
 (setq INDX (1+ INDX)
       SEQN# (atoi SEQN$)
       SEQN# (+ SEQN# 1)
       SEQN$ (itoa SEQN#)
       SEQN$ (CIT_AT:NumFix SEQN$ 3)
       CIT:SEQN SEQN$)
 (CIT_RA)
 (princ))
;
;/////////////////////////////////////////////////////////////////////////////////////////
;
; F07 - Rotate Attribute.
;
(defun CIT_RA ()
 (setq SSET (ssget "_l" (list (cons 0 "INSERT")(cons 66 1)))
       INDX 0
       ENAM (ssname SSET INDX)
       ELST (entget ENAM))
 (while
   (/= (cdr (assoc 0 ELST)) "SEQEND")
   (setq ELST (entget ENAM))
   (if
     (= "ID-TAG" (cdr (assoc 2 ELST)))
     (progn
       (entmod (subst (cons 50 RAD#)(assoc 50 ELST) ELST))
       (entupd ENAM)))
   (setq ENAM (entnext ENAM)))
 (setq INDX (1+ INDX))
 (princ))
;
;/////////////////////////////////////////////////////////////////////////////////////////
;

Link to comment
Share on other sites

Sorry for posting prematurely, But I figured out another way. In all cases I wanted to increment the attribute value, But not in all cases does the attribute need to be rotated. I was able to combine this into one function, So I am ok with this. I will post a completed code in the near future.

 

Thanks,

The Buzzard

Link to comment
Share on other sites

Buzzard,

 

1 thing I do when I'm dealing with revising multiple attributes, is to set a flag when a match has been found. If the flag is T, then issue (entupd) after the end of the loop of SEQEND. You do need to set the flag nil at the beginning.

 

Another option is not call (entupd) at all, but rather issue a (command "_.REGENALL") at the end of the routine

 

(entupd) can really bog down a large pickset. -David

Link to comment
Share on other sites

Hi RenderMan,

 

I could post what I did, But it would not make sence to anyone without the complete code which I am still working on. As I mentioned I will post that code in the near future which is real soon, But it will be on a completely different thread.

 

Just the same here is what I did. I am using an If statement to avoid rotating the attribute if it does not meet those conditions.

 

Thanks for asking all the same.

;/////////////////////////////////////////////////////////////////////////////////////////
;
; F06 - Edit Attribute Value.
;
(defun CIT_EAV ()
 (cond
   ((= CIT:IDFS "0")(setq ATAG$ (strcat ""FLRN$"-"BTAG$"-"SEQN$"")))
   ((= CIT:IDFS "1")(setq ATAG$ (strcat ""FLRN$""IDFR$"-"BTAG$"-"SEQN$""))))
 (setq SSET  (ssget "_l" (list (cons 0 "INSERT")(cons 66 1)))
       INDX 0
       ENAM  (ssname SSET INDX)
       ELST (entget ENAM))
 (while
   (/= (cdr (assoc 0 ELST)) "SEQEND")
   (setq ELST (entget ENAM))
   (if
     (= "ID-TAG" (cdr (assoc 2 ELST)))
     (progn
       (entmod (subst (cons 1 ATAG$)(assoc 1 ELST) ELST))
       (entupd ENAM)))
   (setq ENAM (entnext ENAM)))
 (setq INDX (1+ INDX)
       SEQN# (atoi SEQN$)
       SEQN# (+ SEQN# 1)
       SEQN$ (itoa SEQN#)
       SEQN$ (CIT_AT:NumFix SEQN$ 3)
       CIT:SEQN SEQN$)
 (if (and (> DEG# 90.0)(<= DEG# 270.0))
   (progn
     (setq RAD# (CIT_DTR (+ DEG# 180.0)))
     (setq SSET (ssget "_l" (list (cons 0 "INSERT")(cons 66 1)))
           INDX 0
           ENAM (ssname SSET INDX)
           ELST (entget ENAM))
     (while
       (/= (cdr (assoc 0 ELST)) "SEQEND")
       (setq ELST (entget ENAM))
       (if
         (= "ID-TAG" (cdr (assoc 2 ELST)))
         (progn
           (entmod (subst (cons 50 RAD#)(assoc 50 ELST) ELST))
           (entupd ENAM)))
       (setq ENAM (entnext ENAM)))
     (setq INDX (1+ INDX))))
 (princ))
;
;/////////////////////////////////////////////////////////////////////////////////////////

Link to comment
Share on other sites

Buzzard,

 

1 thing I do when I'm dealing with revising multiple attributes, is to set a flag when a match has been found. If the flag is T, then issue (entupd) after the end of the loop of SEQEND. You do need to set the flag nil at the beginning.

 

Another option is not call (entupd) at all, but rather issue a (command "_.REGENALL") at the end of the routine

 

(entupd) can really bog down a large pickset. -David

 

Thanks David,

 

Thats good to know, I will give that a try.

Just to mention also this is a single attribute being revised mutiple times if certain conditions are met.

Again Thanks

Link to comment
Share on other sites

I could post what I did, But it would not make sence to anyone without the complete code which I am still working on. As I mentioned I will post that code in the near future which is real soon, But it will be on a completely different thread.

 

 

Sorry about that Buzzard, I must not have read you post completely :oops:. Post deleted, and many thanks.

Link to comment
Share on other sites

David,

 

I am only inserting one block with one attribute at a time through a while loop. As mentioned before in all cases the attribute value will be increment by one. In some cases after the attribute has been incremented it may be rotated depending upon the condition. I am finding that the regenall method seems to be slower in this case although it is somewhat cleaner, But it gives you the indication that the block is being redefined every time although I know thats really not the case as the attribute is being just updated. I think I will stick with the original method until I post the complete code for everyones evaluation to see which method is actually better in this case.

 

Thanks all the same, But I will wait on that one. The methods I am using will be more apparent to you when I post the complete code.

Link to comment
Share on other sites

Yes,

 

But as I said before, I am inserting through a while loop. This program is meant to insert identification labels and increment each time one after ther other. So the while loop will cause this regen each time there is an insert.

Link to comment
Share on other sites

Ok Gotcha -David

 

Thats why I mentioned it would be more apparent when I post the full code later on another thread. I am doing a final cleanup on it and adding a help dialog at this time. I will be posting it soon for comments and suggestions before I finalize anything.

 

As always Thanks

Link to comment
Share on other sites

Hi Buzzard,

 

I've tried not to change too much, just to convey a general idea, but this is perhaps how to perform both changes without iterating twice through the set.

 

;/////////////////////////////////////////////////////////////////////////////////////////
;
; F06 - Edit Attribute Value.

(defun CIT_EAV ( / ss ent elst )
 
 (setq ATAG$
   (cond
     ( (= CIT:IDFS "0")
       (strcat FLRN$ "-" BTAG$ "-" SEQN$)
     )
     ( (= CIT:IDFS "1")
       (strcat FLRN$ IDFR$ "-" BTAG$ "-" SEQN$)
     )
   )
 )

 (if (setq ss (ssget "_L" (list (cons 0 "INSERT") (cons 66 1))))
   (progn
     (setq ent (ssname ss 0))

     (while (not (eq "SEQEND" (cdr (assoc 0 (setq elst (entget (setq ent (entnext ent))))))))

       (if (eq "ID-TAG" (cdr (assoc 2 elst)))
         (entupd
           (cdr
             (assoc -1
               (entmod
                 (subst (cons 1 ATAG$) (assoc 1 elst)
                   (if (and (> DEG# 90.0)(<= DEG# 270.0))
                     (subst (cons 50 (CIT_DTR (+ DEG# 180.0))) (assoc 50 elst) elst)
                     elst
                   )
                 )
               )
             )
           )
         )
       )
     )
   )
 )
)

;/////////////////////////////////////////////////////////////////////////////////////////

Link to comment
Share on other sites

Ok Lee,

 

I see the if at the beginning when getting the selection set and in addition adding the not to the SEQEND.

Thanks I will give that a try. It beats going thru the selection set twice which I said seem to be overkill.

Link to comment
Share on other sites

Lee,

 

I added the code to test and I am not getting any errors, But the attributes are not changing either. I think at this point it would be best if I post the full code before I make any more changes so everyone can see what is suppose to happen. I somewhat got the idea of what you are conveying to me and I know additional adjustments are required, But I am trying now at this point to finish it off so I can post it. It will be alot clearer if its in working order even if it is less concise to your programming methods. At that point we can all take it from there and see how it should get fixed.

 

Thanks

Link to comment
Share on other sites

No worries :)

 

Lee,

 

I have finished editing the code and went back to take another look at your function. I have it working well now. I had a few quirks as to where the local variables should have been localized. Also where I had put the call for incrementing the attribute value was another issue. And finally I was using a variable called INDX for the index number which was adding 1 to the value was not being used in your code, So I hard coded the 1 to be added to the sequence number and all is good now. It is a much smaller function calling the selection set only once which was the goal in mind and I am very happy with it. I will be posting the entire code soon on another thread for it and plan to reference this thread to it as well.

 

Thank you and everyone else that had participated here with help.

The Buzzard

Edited by The Buzzard
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...