Jump to content

Replicate the Dist command's ghosted line functionality without using getdistance?


Recommended Posts

Posted

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?

Posted

Maybe...

(setq point2 (getpoint "select another point" point1)

Posted

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)
)

Posted

Hah! Of course. I totally forgot that you can specify a base point like that.

 

Thanks guys for the simple answer!

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...