Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Autolisp not entering if-statement correctly

Status
Not open for further replies.

jkusnick

Programmer
Jun 21, 2007
5
US
Hello,
I am writing a routine to compare two selection sets that each contain multiple blocks. There is an if-statement, and it is as follows:

(if (and (= entname entname2) (= inspoint inspoint2))
(progn
(entdel bLock)
(entdel bLock2)
)
)

The program will not enter this if-statement. I have verified through the AutoCAD command line that entname does equal entname2, and inspoint does equal inspoint2. The inspoint variable is the insertion point for a block, and is attained through:

(setq inspoint (cdr (assoc 10 (entget bLock))))

The if-statement will work if I remove the inspoint=inspoint2 requirement, but not if I remove the entname = entname2 part and just leave the inspoint part. Is there a problem in autolisp with comparing insertion points like this?

Any help would be very appreciated. Thank you.
 
Nevermind. The problem turned out to be in the code that acquired the insertion point. While "cdr" worked for the block name (entname), "cadr" was required for the insertion point:

(setq inspoint (cadr (assoc 10 (entget bLock))))

Now the if-statement works fine.
 
No, cadr is not correct. (assoc 10 ...) will give you a list like (10 2.0 4.6 0.0), and 'cadr gives you the second item on the list, the x value of the point. For comparing pointt coordinates, which are lists, I believe you should use (if (equal inspoint inspoint2) -that is, the function 'equal' instead of '='

Hope this helps!

 
Thank you very much, CarlAK. You are absolutely correct and that is exactly what I was looking for.

I also have another question, and if you have any input it would be greatly appreciated. I have the code that compares two selection sets within one drawing, and deletes any duplicate blocks (blocks with the same insertion point and block name). The code works in one drawing, but when I try to hard-code it to open a second drawing and create the second selection set there, it starts the first command and then produces the error "Can't reenter LISP." I have "lispinit" set to zero, so I know that is not the problem. The second part of the code that opens the drawing looks like this:

Code:
(command "_open" "C:/test_comp.dwg")
(setq s1 (getcorner (setq f1 (getpoint "Specify first corner: "))"Specify opposite corner: "))
  (setq f1 (getpoint "\nSpecify first corner: "))
  (setq s1 (getcorner f1 "\nSpecify opposite corner: "))
  (Command "_Zoom" "_W" f1 s1)
  (Setq ss2 (ssget "_w" f1 s1))

When I run this, in the second drawing (test_comp.dwg), the command line reads: "Command: Specify first corner:
Can't reenter LISP.
Invalid point."

Any help would be appreciated. Thanks again.

-Josh
 
You're welcome.

I think the problem is with the second & third lines - you have lisp expressions inside a "getcorner" function which isn't allowed. In fact you don't need those lines, the 2 lines before the "command" line give you the f1 & s1 values you need. You don't need the "zoom" line for the ssget to work properly since 'getcorner' handled that.
HTH!
 
Sorry, the second and third lines in the code I entered above were test lines; they were eliminated when I ran the code, but that did not fix the problem. I also tried your suggestion of removing the zoom line, but still the same error occurs:

"Specify first corner:
Can't reenter LISP.
Invalid point."

The program does not proceed to any code below it, so I still think the problem is somewhere within the following:
Code:
(command "_open" "C:/test_comp.dwg")
(setq f1 (getpoint "\nSpecify first corner: "))
  (setq s1 (getcorner f1 "\nSpecify opposite corner: "))
  (Setq ss2 (ssget "_w" f1 s1))

The only other thing I can think of is that the program initially sets "SDI" to "1" so that another drawing can be opened and the lisp routine continues, but I have done this in many other programs and it has never caused this issue. Any insight would be appreciated. Thanks again.
-Josh
 
Do you have any routines that run on opening a drawing, such as in Startup Suite or acad.lsp, acaddoc.lsp, abcad.mnl, etc? If so, try disabling those.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top