frostrap Posted January 29, 2009 Posted January 29, 2009 This one has me scratching my head, so I'm hoping someone here can lead me to a solution. I use a lisp routine here at work for dimensioning pipe. Basically, the program prompts for the user to select two points. It then calculates the distance between those two points, and inserts a block with a dimension formatted at the centerpoint between the two initial points. The program then saves the second point as the first point, then loops and asks for another point to dimension to. The issue is that I would like the program to draw a ghosted ("jigged") line between first point and the cursor while the user is deciding which point to pick next (just like the dist command). Here's the sticking point: I know that the getdistance function will typically handle this for me, but I don't think I can use it. Instead I am calling the getpoint function twice, then calculating the distance between the two points using the distance function. The reason I have to do this is to allow the program to do the looping that I described before. I need to save the second entered point as the first point so the program can loop back near the beginning and ask for a new second point. The getdistance function only returns a number, not a point, so using the get distance function prevents the looping functionality that I need. Here's some pseudo-ish code for ya (the actual program's about 250 lines): (setq point1 (getpoint "select a point")) (while (= 1 1) (setq point2 (getpoint "select another point")) (setq length (distance point1 point2)) (InsertBlockWithLengthBetweenPoints) (setq point1 point2) );while You can see that if I use the getdistance function, I wont be able to loop around in my nifty infinite while loop. I've thought about doing something complicated like using grdraw and grread or grvecs to create the ghosted line, but I can't quite get that to work right since those functions are a bit difficult to use. Maybe there's a visual lisp function I don't know about that could help me out? Any ideas? Quote
lpseifert Posted January 30, 2009 Posted January 30, 2009 Maybe... (setq point2 (getpoint "select another point" point1) Quote
CAB Posted January 30, 2009 Posted January 30, 2009 Something like this? (defun c:test(/ p1 p2) (setvar "errno" 0) ; must pre set the errno to 0 (setq p1 nil) (while (cond ((null p1) (setq p1 (getpoint "\nSelect first point.")) ) ((= (getvar "errno") 52) ; exit if user pressed ENTER nil ; exit loop ) ((setq p2 (getpoint p1 "\nSelect next point.")) ;; do you block insert (setq p1 p2) ) ) ) (princ) ) Quote
frostrap Posted January 30, 2009 Author Posted January 30, 2009 Hah! Of course. I totally forgot that you can specify a base point like that. Thanks guys for the simple answer! 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.