saim Posted July 26, 2019 Posted July 26, 2019 I have this goal: Draw, in a 3D view, a line from a point (given by the user) to the ground (Z = 0) and, on the ground, draw a red "x", with the lines intercepting on the edge of the first line. Should be simple. In fact, it was, here, let me show what I did: (defun c:gline( / p1); (setq p1 (getpoint "\nPick a point")); (drawxis p1); (drawgline p1); ) (defun drawxis(pg / x1 y1); (setq x1 (car pg)); (setq y1 (cadr pg)); (command "line" (list (- x1 2) y1 0) (list (+ x1 2) y1 0) ""); (command "chprop" "last" "" "color" "1" ""); (command "line" (list x1 (- y1 2) 0) (list x1 (+ y1 2) 0) ""); (command "chprop" "last" "" "color" "1" ""); ) (defun drawgline(pg / x1 y1); (setq x1 (car pg)); (setq y1 (cadr pg)); (command "line" (list x1 y1 (caddr p1)) (list x1 y1 0) ""); ) It works more often than not, but sometimes the lines go crazy - and I only did a few tests. The lines don't end up aligned as simply as I would expect, they slitghtly diverge on one or another axis (all lines, all axis, never too much). I thought it might because of a "relative" coordinate entrance, but that would ALWAYS be a problem, not occasionally. Any thoughts on why this is happening and how to fix it? Quote
dlanorh Posted July 26, 2019 Posted July 26, 2019 (edited) 43 minutes ago, saim said: I have this goal: Draw, in a 3D view, a line from a point (given by the user) to the ground (Z = 0) and, on the ground, draw a red "x", with the lines intercepting on the edge of the first line. Should be simple. In fact, it was, here, let me show what I did: (defun c:gline( / p1); (setq p1 (getpoint "\nPick a point")); (drawxis p1); (drawgline p1); ) (defun drawxis(pg / x1 y1); (setq x1 (car pg)); (setq y1 (cadr pg)); (command "line" (list (- x1 2) y1 0) (list (+ x1 2) y1 0) ""); (command "chprop" "last" "" "color" "1" ""); (command "line" (list x1 (- y1 2) 0) (list x1 (+ y1 2) 0) ""); (command "chprop" "last" "" "color" "1" ""); ) (defun drawgline(pg / x1 y1); (setq x1 (car pg)); (setq y1 (cadr pg)); (command "line" (list x1 y1 (caddr p1)) (list x1 y1 0) ""); ) It works more often than not, but sometimes the lines go crazy - and I only did a few tests. The lines don't end up aligned as simply as I would expect, they slitghtly diverge on one or another axis (all lines, all axis, never too much). I thought it might because of a "relative" coordinate entrance, but that would ALWAYS be a problem, not occasionally. Any thoughts on why this is happening and how to fix it? Perhaps this line (command "line" (list x1 y1 (caddr p1)) (list x1 y1 0) ""); Should be (command "line" (list x1 y1 (caddr pg)) (list x1 y1 0.0) ""); Since p1 when passed in becomes pg, and IMHO reals should always be reals and not integers Edited July 26, 2019 by dlanorh 1 Quote
Tharwat Posted July 26, 2019 Posted July 26, 2019 Hi, One of the most important things when you intend to use commands is that to disable the system variable OSMODE then reset back once your program finishes or ends. 1 Quote
saim Posted July 26, 2019 Author Posted July 26, 2019 (edited) That's it!!! First, I really missed that "p1/pg" part. I use different variable names just to make sure the variable is being passed correctly (otherwise, the program should crash when running). I probably made some tests where I defined "p1" as global and then, the problem got masked out. AND yes, setting osmode to 0 fixed the other lines. Didn't think that even when i input the values the snapping would snap, but it did. Thanks, guys! Btw: is 0 readed as an integer? I thought that all numbers were trated as reals, regardless how you putted them on code. Edited July 26, 2019 by saim Quote
Tharwat Posted July 26, 2019 Posted July 26, 2019 1 hour ago, saim said: Btw: is 0 readed as an integer? I thought that all numbers were trated as reals, regardless how you putted them on code. Using either of the two forms 0 or 0.0 would be the same in coordinates so you can pick the one you desire in this case. Quote
BIGAL Posted July 27, 2019 Posted July 27, 2019 (edited) Saim Be careful in math functions 3 is different to 3.0 you will find that using an integer with a real can end up with an integer answer ie no decimals. (/ 16 3) 5 (/ 16 3.0) 5.33333333333333 Edited July 27, 2019 by BIGAL Quote
Recommended Posts
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.