Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

precision distance and slop lisp

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
zasanil
902 Views, 11 Replies

precision distance and slop lisp

Hello,

I'm looking for a lisp file that would perform the same function as the DI (DIST) comand but use the maximum percision autocad can display (16 decimal places?). Is there an easy way to do this?

Thanks,

Dan

Dan Nicholson C.I.D.
PCB Design Engineer
Tags (2)
11 REPLIES 11
Message 2 of 12
marko_ribar
in reply to: zasanil

(defun c:dii ( / p1 p2 )
  (while (not p1) (setq p1 (getpoint "\nPick or specify start point : ")))
  (while (not p2) (setq p2 (getpoint p1 "\nPick or specify end point : ")))
  (princ (rtos (distance p1 p2) 2 50))
  (princ)
)

 HTH, M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 3 of 12
zasanil
in reply to: marko_ribar

Hi Marko,

 

That worked great for a single distance, but would you be able to add all 3 cordinate values and angles from point to point like the DIST command does?

The output it normally gives is like this:

 

Distance = 1.8762,  Angle in XY Plane = 8,  Angle from XY Plane = 0
Delta X = 1.8595,  Delta Y = 0.2499,   Delta Z = 0.0000

 

I would like the same info, but with the max precision for all the values (distance, deltas & angles) like you did with the single value.

 

Thanks!

Dan Nicholson C.I.D.
PCB Design Engineer
Message 4 of 12
marko_ribar
in reply to: zasanil

(defun c:dii ( / p1 p2 d dx dy dz v dxw dyw dzw w ax vprim vprimd axy )
  (while (not p1) (setq p1 (getpoint "\nPick or specify start point : ")))
  (while (not p2) (setq p2 (getpoint p1 "\nPick or specify end point : ")))
  (setq d (distance p1 p2))
  (setq dx (car (setq v (mapcar '- p2 p1))))
  (setq dy (cadr v))
  (setq dz (caddr v))
  (setq dxw (car (setq w (mapcar '- (trans p2 1 0) (trans p1 1 0)))))
  (setq dyw (cadr w))
  (setq dzw (caddr w))
  (setq ax (cvunit (atan dy dx) "radians" "degrees"))
  (setq vprim (list (car v) (cadr v) 0.0))
  (setq vprimd (distance '(0.0 0.0 0.0) vprim))
  (setq axy (cvunit (atan (caddr v) vprimd) "radians" "degrees"))
  (prompt "\nDistance : ")(princ (rtos d 2 50))
  (prompt "\n\nDX in UCS : ")(princ (rtos dx 2 50))
  (prompt "\nDY in UCS : ")(princ (rtos dy 2 50))
  (prompt "\nDZ in UCS : ")(princ (rtos dz 2 50))
  (prompt "\n\nDX in WCS : ")(princ (rtos dxw 2 50))
  (prompt "\nDY in WCS : ")(princ (rtos dyw 2 50))
  (prompt "\nDZ in WCS : ")(princ (rtos dzw 2 50))
  (prompt "\n\nAngle around Z axis from X axis as 0.0 degree reference : ")(princ (rtos ax 2 50))(prompt " degrees")
  (prompt "\nAngle of picked points vector to XY plane : ")(princ (rtos axy 2 50))(prompt " degrees")
  (princ)
)

 HTH, M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 5 of 12
Lee_Mac
in reply to: zasanil

Here's another way to write it:

 

(defun c:dd ( / atos ntos p q v )
    (setq ntos (lambda ( x ) (rtos   x (getvar 'lunits) 16))
          atos (lambda ( x ) (angtos x (getvar 'aunits) 16))
    )
    (if (and (setq p (getpoint "\nSpecify 1st point: "))
             (setq q (getpoint "\nSpecify 2nd point: " p))
             (setq v (mapcar '- q p))
        )
        (prompt
            (strcat
                "\nDistance = "            (ntos (distance p q))
                ", Angle in XY Plane = "   (atos (angle p q))
                ", Angle from XY Plane = " (atos (atan (last v) (distance '(0.0 0.0) v)))
                "\nDelta X = " (ntos (car v)) ", Delta Y = " (ntos (cadr v)) ", Delta Z = " (ntos (caddr v))
            )
        )
    )
    (princ)
)

 

Message 6 of 12
stevor
in reply to: zasanil

From Ribar's start, adding old code, try this.

Remove commented lines,or others,

change AngToS  to RTOS, reolutions,

make variables local, etc, as needed.

 

 (defun c:dii ( / os) ; Marko Ribar 10-04-2014, +  p1 p2
  (setq RSD 16  ; 50  Real To String Dimension  000 000 000 000 000
        osm (getvar 'osmode)) (princ " Osnap: ")(prin1 osm)
  (while (not p1) (setq p1 (getpoint "\nPick or specify start point : ")))
  (while (not p2) (setq p2 (getpoint p1 "\nPick or specify end point : ")))
 ;(or (and (setq p1 (get_P P1 "\n Start pt: "))
 ;  (setq p2 (get_P P2 "\n End pt: "))) (EXIT_S"\n NO Pts "))
  (setq p1x (car p1)  p1y (cadr p1)  p1z (caddr p1))  ;
  (setq p2x (car p2)  p2y (cadr p2)  p2z (caddr p2))  ;
  (setq dx (- p2x p1x)  dy (- p2y p1y)  dz (- p2z p1z) )  ; 2-1,
  ; (princ"\n P1: ")(prin1 P1) (princ",  P2: ")(prin1 P2)
  (redraw) (grdraw p1 (list p2x p1y p1z) 1)
  (grdraw (list p2x p1y p1z) (list p2x p2y p1z) 2)
  (grdraw (list p2x p2y p1z) p2 3)
  ; Angle in XY:  resolve sine DY/DX for X=0, let Acad do it
  (setq Axy (angle '(0 0 0) (list dx dy 0 )))
  ; same if DX=0 and DY=0
  (SETQ DXY (DISTANCE '(0 0) (list dx dy)) )   
  (setq Az (angle '(0 0) (list DXY dz )) )
  ;
  (princ"\n Dist: ")(princ (rtos (distance p1 p2) 2 RSD))
  ;(princ",  Axy: ")(princ (rtos Axy 2 RSD))
  ;(princ",  Az: ")(princ (rtos Az 2 RSD))  (princ " radians ")
  (princ",  Axy: ")(princ (ANGtos Axy 0 RSD))
  (princ",  Az: ")(princ (ANGtos Az 0 RSD)) (princ " degrees ")
  (princ"\n DX: ")(princ (rtos DX 2 RSD))
  (princ",  DY: ")(princ (rtos DY 2 RSD))
  (princ",  DZ: ")(princ (rtos DZ 2 RSD))
  (princ) ) ; def

S
Message 7 of 12
zasanil
in reply to: zasanil

Thank you all! These solutions all work great.

/cheers

Dan Nicholson C.I.D.
PCB Design Engineer
Message 8 of 12
marko_ribar
in reply to: zasanil

 

Lee, this line of your code is wrong...

 

  ", Angle from XY Plane = " (atos (atan (last v) (distance '(0.0 0.0) v)))

 

It should be :

 

 ", Angle from XY Plane = " (atos (atan (last v) (distance '(0.0 0.0) (list (car v) (cadr v)))))

 

Regards, M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 9 of 12
Lee_Mac
in reply to: marko_ribar

marko_ribar wrote:

 

Lee, this line of your code is wrong...

 

  ", Angle from XY Plane = " (atos (atan (last v) (distance '(0.0 0.0) v)))

 

It should be :

 

 ", Angle from XY Plane = " (atos (atan (last v) (distance '(0.0 0.0) (list (car v) (cadr v)))))

 

 

No, the line is correct as it is.

 

Lee

Message 10 of 12
marko_ribar
in reply to: Lee_Mac

So if one point is specified as 2D, distance will calculate 2D distance... You are right, but my observation was more apparent...

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 11 of 12
zasanil
in reply to: zasanil

I have a related question about a keyboard shortcut for this lisp. I created a keyboard shortcut in the CUI window and assigned a keyboard shortcut of SHIFT-D to the command with a macro of ^c^cdii. When I'm in the main window and hit the SHIFT-D to activate the lisp, it pops up the window to ask for the first point, but the focus is moved from the cursor to the textbox where you can type in the point coords. In that textbox it writes the letter D. How do I make it switch focus back to the cursor where I can pick a point with the mouse automatically? Do I have to change the macro command somehow?

Thanks,

 

edited to fix typos

Dan Nicholson C.I.D.
PCB Design Engineer
Message 12 of 12
stevor
in reply to: zasanil

Since all the examples seem to use getpoint, try bypassing the Shift-D thing, and use the defined command symbols: C:DDI or C:DD.
S

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost