AutoLisp IF statement just not working as it should?

AutoLisp IF statement just not working as it should?

mkh94
Explorer Explorer
922 Views
7 Replies
Message 1 of 8

AutoLisp IF statement just not working as it should?

mkh94
Explorer
Explorer

Yes, the title as confusing as it sounds, the code I have wrote, does not work. 

 

A quick background so you can understand the code, I am a Land Surveyor and I have made a code where when we use a 3D delivery, we can use this code. When we have the exact cover level, it extracts the z-value of that and allows the user to enter the pipe depth and reduces the z-value of that pipe line to its new.

 

(I decided to reduce it to a AutoLisp code because otherwise you will have to go through ID the pipe line and knowing which point (start or end) it is then using a calculator to work out the pipe line new z-value and then going into properties and changing it)

 

The problem is that the AutoLisp routine does not work as it should, my main two lines that are not working are lines 19 and 31 where it starts with the If statements and its condition, the condition output is 'nil'. I have even put in the command prompt in AutoCAD: (= var1 var2) (using the respected variables) and the output is still 'nil'. Every other line works, and the code within the 'if' routine works too when entered one by one manually, however, its just that the 'if' statement does not trigger. 

 

I have attached the file below, the command won't present 'nil' anymore when you are running the code as I have put a "Not a start/end" point prompt, but after running the code, type in the command line in AutoCAD: (= pt spoint) <or> (= pt epoint)  where you will see the error. I might have a rough idea of what it can be, could it be the way I am getting the variables that the spoint/epoint variable are a different type compared to the pt  as I used the (getpoint) for one and the (entget) for another? No idea, just throwing my thoughts that I can't seem to solve.

 

Thank you!

0 Likes
Accepted solutions (2)
923 Views
7 Replies
Replies (7)
Message 2 of 8

hak_vz
Advisor
Advisor
Accepted solution

To compare two lists use function equal instead of =

 

(if (equal pt spoint).......)

 

 

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 3 of 8

mkh94
Explorer
Explorer

Just tried that, and same result, pops up as nil.

0 Likes
Message 4 of 8

hak_vz
Advisor
Advisor
Accepted solution

Yes because you are comparing real numbers inside lists, so you have to use some tolerance

Command: (SETQ A (GETPOINT "/nPOINT >") > (321.784 385.992 0.0)
Command: (setq B (mapcar '+ a '(0.0001 0.0001 0.0001)))  > (321.784 385.992 0.0001)
Command: (apply '= (mapcar '(lambda (x y) (equal x y 1e-4)) a b))
T

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 5 of 8

mkh94
Explorer
Explorer

Thank you so much!

 

One more thing, my AutoLisp picks points at 1 decimal place, how did you get it to pick 3 decimal place. 

 

0 Likes
Message 6 of 8

hak_vz
Advisor
Advisor

Check how LUPREC variable is set at your side

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 7 of 8

mkh94
Explorer
Explorer
I've tried that but didn't help the AutoLisp command. It only helps with the AutoCAD commands itself. When I use the command entget or getpoint or something similar, it only gives me the precision upto 1 decimal point, even the 1 decimal point it's still at (x.0 x.0 x.0)
0 Likes
Message 8 of 8

Kent1Cooper
Consultant
Consultant

The (rtos) function can take mode and precision arguments.  If you want to see 3 decimal places, change

(rtos newZvalue)

to

(rtos newZvalue 2 3)

[The 2 is for decimal mode.  Read about the function in the AutoLisp Reference.]

The DIMZIN System Variable setting controls whether leading and/or trailing Zeroes are shown.  [It's named for application in DIMensions, and whether Zero INches are shown when in feet-and-inches mode, but it applies to (rtos) returns also -- read about that, too.]

Kent Cooper, AIA
0 Likes