Author Topic: GetDistance & GetPoint simultaneously  (Read 2613 times)

0 Members and 1 Guest are viewing this topic.

Kheilmann

  • Guest
GetDistance & GetPoint simultaneously
« on: April 01, 2006, 01:01:39 AM »
Based on my understanding of the GetDistance utility you can not get the distance of two known points..
ie. 
CurDist = GetDistance(PointA,PointB)
Apparently you can only use one known point and you either have to Pick the next point or type something in....

The picking of the 2nd point is not a big deal except for the fact that I have to use that same point for 2 purposes, (getting distance and getting a  point for inserting). 

So, is there a way to utilize the GetDistance & Getpoint utilities within only one step??

I hope this makes sense...

Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
Re: GetDistance & GetPoint simultaneously
« Reply #1 on: April 01, 2006, 04:34:59 AM »
Hi Kevin

You can do something like this:
Code: [Select]
Public Function MeGetPointOrDistance() As Variant

  Dim aFstPnt As Variant
  Dim aNxtPnt As Variant

  On Error Resume Next
 
  With ThisDrawing.Utility
    aFstPnt = .GetPoint(, vbCrLf & "Select first point: ")
    If Err.Number <> 0 Then
      Err.Clear
      Exit Function
    End If
    aNxtPnt = .GetPoint(aFstPnt, vbCrLf & "Select next point/enter distance <point only> : ")
    If Err.Number <> 0 Then
      Err.Clear
      TestPnt = aFstPnt
    Else
      TestPnt = Sqr(((aFstPnt(0) - aNxtPnt(0)) ^ 2) + _
                    ((aFstPnt(1) - aNxtPnt(1)) ^ 2) + _
                    ((aFstPnt(2) - aNxtPnt(2)) ^ 2))
    End If
  End With
 
End Function

Use:
Dim vRetVal As Variant
vRetVal = MeGetPointOrDistance()
Select Case VarType(RetVal)
  Case vbEmpty
    'User pressed enter - do nothing
  Case vbDouble
    'User had enter a distance
  Case Else
    'User had enter a point
End Select
A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k16... A2k24 - Start R2.18

RbtDanforth

  • Guest
Re: GetDistance & GetPoint simultaneously
« Reply #2 on: April 01, 2006, 10:44:07 AM »
Not sure If I understand your problem but the last point picked is stored in the "lastpoint" system variable or if the two points are set to variable then the variable is available for anything else.
Code: [Select]
(defun C:DS (/ A B)
              (PROMPT (STRCAT(RTOS (CAR(SETQ A(GETPOINT "START\t")))3 10)
                             "   "(RTOS (CADR A)3 10)
                             "   "(RTOS (CADDR A)3 10)"\n"
              ))
              (PROMPT(RTOS (DISTANCE A (SETQ B(GETPOINT A "TO\n") ))3 10))
              (PROMPT(STRCAT "\tX="(RTOS (SETQ DX(CAR(MAPCAR '- B A)))3 10)"\tor X="(RTOS (SETQ DX(CAR(MAPCAR '- B A)))2 10)
                   "\tY="  (RTOS (SETQ DY(CADR(MAPCAR '- B A)))3 10)"\tor Y="  (RTOS (SETQ DY(CADR(MAPCAR '- B A)))2 10)
                   "\tZ="  (RTOS (SETQ DZ(CADDR(MAPCAR '- B A)))3 10)
                     )) (PRINC (DISTANCE A B))
(command "insert" (getstring "blockname") "s" 1 "r" 0 B)
(terpri)
     )

Bryco

  • Water Moccasin
  • Posts: 1883
Re: GetDistance & GetPoint simultaneously
« Reply #3 on: April 01, 2006, 08:51:52 PM »
Rbt I think it's not too hard to do the vba way.
Jürg btw it's faster to use x*x than x^2

RbtDanforth

  • Guest
Re: GetDistance & GetPoint simultaneously
« Reply #4 on: April 02, 2006, 01:04:59 AM »
Quote
btw it's faster to use x*x than x^2

Not if the rule is "no variables", I was racking my brain to find the way to square the single object, but others pointed the way first.