Lisp routine will not continue...

Lisp routine will not continue...

Anonymous
Not applicable
1,648 Views
11 Replies
Message 1 of 12

Lisp routine will not continue...

Anonymous
Not applicable

I have written a basic lisp routine. The object of this routine is to search for a block "revision" if it is found run a set of commands to change some attributes in this block and two others. If it is not found, I have another routine, "bre" that is being called in, that I got from someone else, to replace certain blocks with the revision block. Then continue on to change the attributes in the blocks as described above. When I run the routine, it goes through the block replace with no problem but then throws this error:

                                                                                          Duplicate definition of layer state "STOCK" ignored.
                                                                                          No unreferenced blocks found.

Any help on this would be greatly appreciated. Please see the attached file for the lisp routines that I am using.

0 Likes
Accepted solutions (1)
1,649 Views
11 Replies
Replies (11)
Message 2 of 12

ВeekeeCZ
Consultant
Consultant
Did you check your preplacing block to see if there is the STOCK layer state and delete that if possible?
0 Likes
Message 3 of 12

Anonymous
Not applicable

I just did. I no longer get the layer state message. Now I am only getting the "No unreferenced blocks found." Message and it kicks out before doing any of the attribute changing.

0 Likes
Message 4 of 12

ВeekeeCZ
Consultant
Consultant

That's PURGE's report message. Do you mind so much? There is no easy way to suppress that.

 

(defun c:BRE (/ BLK pre nb ss i en ed)
(setvar "cmdecho" 0)
 
(setq pt (cadr(entsel"\nSelect Block:")))
 
(setq e1 (ssget pt))
 
(setq e2 (entget (ssname e1 0)))
 
(setq BLK (cdr(assoc 2 e2)))
(while (or (not pre)
           (not (snvalid pre)))
  (setq pre BLK))
  (while (not nb)
    (setq nb (getstring "\nNew BLOCK Name:   "))
    (cond ((not (snvalid nb))
           (setq nb nil))
          ((tblsearch "BLOCK" nb))
          ((findfile (strcat nb ".DWG"))
           (command "_.INSERT" nb)(command))
          (T (setq nb nil))))

  (command "-purge" "B" pre "N") ; <- This reports message "No unreferenced blocks found"

  (and (setq ss (ssget "X" (list (cons 0 "INSERT")(cons 2 (strcat pre "*")))))
       (setq i (sslength ss))
       (while (not (minusp (setq i (1- i))))
         (setq en (ssname ss i)
               ed (entget en))(entmod (subst (cons 2 nb) (assoc 2 ed) ed))
         (entupd en)))

(princ)
)

 

 

0 Likes
Message 5 of 12

Anonymous
Not applicable

No, I really don't mind that. The issue though is that the lisp won't continue past that point. Such as once the block replace occurs, continue on to where it runs the attribute changes on the new blocks that have been placed in. If that makes sense.

0 Likes
Message 6 of 12

ВeekeeCZ
Consultant
Consultant

Post me some test drawing and some new block and description if needed that I can replicate your workflow.

0 Likes
Message 7 of 12

Anonymous
Not applicable

So within the snapshots:

    Test.png - The rev triangle should be replaced with the "revision" block and the attribute should change to the new number

    Test2.png - The circled number should change to the new number that is typed with the lisp

    Test3.png - The circled number should change to the new number that is typed in the lisp

So when I run the lisp, it automatically asks to select an object (which is what I have it set to do if the "revision" block is not found). Once that is selected it asks to enter the new block name (here I enter "revision"). At this point with the way it is written right now, this is where the program cuts out. The attached is a simple test drawing with the different parts that I want to be changed and adjusted with the lisp. I also have the "revision" block attached. Let me know if there is anything else that you need that will help with this.

0 Likes
Message 8 of 12

Anonymous
Not applicable

here are the rest of the attachments

0 Likes
Message 9 of 12

ВeekeeCZ
Consultant
Consultant
Accepted solution

I guess that routine should replace the rev block if needed (= does not exist yet in the drawing). Then it changes some attributes no matter whether the rev block was replaced or not. The following code was adjusted that way.

 

(DEFUN C:REVCH ( / ts rev rev1)

  (if (not (TBLSEARCH "BLOCK" "REVISION"))
    (c:BRE))

  (SETQ REV (GETSTRING T "\nEXISTING REV NUMBER: "))
  (SETQ REV1 (GETSTRING T "\nNEW REV NUMBER: "))
         
         (COMMAND "-ATTEDIT"
                  "N"
                  "N"
                  "REVISION"
                  "1"
                  REV
                  REV
                  REV1
                  )
         (COMMAND "-ATTEDIT"
                  "N"
                  "N"
                  "REV-36"
                  "REVNO"
                  REV
                  REV
                  REV1
                  )
         (COMMAND "-ATTEDIT"
                  "N"
                  "N"
                  "TBLK-36"
                  "REV"
                  REV
                  REV
                  REV1
                  )
  (PRINC)
  )
Message 10 of 12

Anonymous
Not applicable

That works perfectly, thank you for all the help. 

0 Likes
Message 11 of 12

ВeekeeCZ
Consultant
Consultant

You're welcome. I own some explanation why your cond function was wrong.

 

(cond ((= condition 1)
       (command 1)
       )
      
      ((= condition 2)
       (command 2)
       )

      ((= condition 3)
       (command 3)
       )
      ) ; cond

The conditions are tested one after another untill some is True. Then it process its and only that command. Then it leaves the cond function. So even if more the 1 might became True, just the first one is processed.

 

0 Likes
Message 12 of 12

Anonymous
Not applicable

Okay that makes a lot more sense. I never realized that, guess I only wrote conditionals with two conditions.

0 Likes