Hello!
I measure a distance in my lisp routine as follow:
(command "dist" p c)
Can i have it show in a message box to make it more noticeable instead of the command prompt area that disappears soon after?
Thanks for your help.
Solved! Go to Solution.
Or...
(set_tile "Distance" (rtos (distance p c) 2 3)) where "Distance" is the key name of your edit_box tile, or text tile or text_part tile.
John F. Uhden
Hi John and Ajilal, thanks for the tip.
i tried:
(alert (strcat "Max heigth is : "(rtos (distance p c) 2 3)))
and it shows a completely different number than if i use
(command "dist" p c) which shows the right distance. i think is the different way DIST and DISTANCE work.
Can i use the command DIST in your alert code?
Hello,
As long as the supplied variables ( p & c ) holds the same point value, DISTANCE and DIST should give the same result.
I don't think you can use alert and command together.
davidelipera wrote:
(alert (strcat "Max heigth is : "(rtos (distance p c) 2 3)))
and it shows a completely different number than if i use
(command "dist" p c) which shows the right distance.
Can you share an example of the different output or please share your code to check.
thanks for the reply.
i think it is the way the points are created. one is done with the command GEOMARKLATLONG and the other one is selected by the LASTPOINT command after impringont a solid with a line.
Here is my code, i hope you can help:
(defun C:DAVIDE(/ var val p c solidSS ent linevar)
(setq var '("Osmode" "Expert")
val (mapcar 'getvar var))
(mapcar 'setvar var '(0 1))
; TURN OFF SOLID LAYER
(command "_.-layer" "OFF" "IMAGINARY SURFACE" "" "")
; ENTER LAT, LON OF THE POINT OF INTEREST
(command "geomarklatlong" PAUSE PAUSE " ")
; SELECT NODE JUST CREATED
(setq p (cdr (assoc 10 (entget(ENTLAST)))))
; DRAW LINE 200 UNITS TALL ORTHO TO XY FROM NODE
(command "_.line" p (list (car p) (cadr p) (+ (caddr p) 200)) "")
(setq linevar (ssget "_L"))
(mapcar 'setvar var val)
; TURN ON SOLID LAYER
(command "_.-layer" "ON" "IMAGINARY SURFACE" "")
; IMPRINT LINE WITH SOLID
(setq solidSS (ssget "X" (list '(0 . "3DSOLID")(cons 8 "IMAGINARY SURFACE")))) ; this will get you a selection set containing the solid
(setq ent (ssname solidSS 0)) ; retrieve first entity in the list (there should be only 1)
(command "_.imprint" ent linevar "_Y" "")
; SELECT IMPRINTED POINT
(setq c (getvar "lastpoint"))
; CALCULATE DISTANCE FROM ORIGINAL POINT TO THE IMPRINTED POINT
(command "dist" p c) ;THIS SHOWS THE RIGHT DISTANCE BUT I NEED IT IN THE MESSAGE BOX
; (alert (strcat "Max heigth is : "(rtos (distance p c) 2 3)))
(princ)
)
Strangely i'm just now noticing that the distance command always show me 200 which is the lenght of the line imprinting the solid (the solid's max height is 152!)
Can i store the distance with the DIST command in a variable then put the variable in the alert code?
@Anonymous wrote:
thanks for the reply.
i think it is the way the points are created. one is done with the command GEOMARKLATLONG and the other one is selected by the LASTPOINT command after impringont a solid with a line.
Here is my code, i hope you can help:
(defun C:DAVIDE(/ var val p c solidSS ent linevar)
(setq var '("Osmode" "Expert")
val (mapcar 'getvar var))
(mapcar 'setvar var '(0 1))
; TURN OFF SOLID LAYER
(command "_.-layer" "OFF" "IMAGINARY SURFACE" "" "")
; ENTER LAT, LON OF THE POINT OF INTEREST
(command "geomarklatlong" PAUSE PAUSE " ")
; SELECT NODE JUST CREATED
(setq p (cdr (assoc 10 (entget(ENTLAST)))))
; DRAW LINE 200 UNITS TALL ORTHO TO XY FROM NODE
(command "_.line" p (list (car p) (cadr p) (+ (caddr p) 200)) "")
(setq linevar (ssget "_L"))
(mapcar 'setvar var val)
; TURN ON SOLID LAYER
(command "_.-layer" "ON" "IMAGINARY SURFACE" "")
; IMPRINT LINE WITH SOLID
(setq solidSS (ssget "X" (list '(0 . "3DSOLID")(cons 8 "IMAGINARY SURFACE")))) ; this will get you a selection set containing the solid
(setq ent (ssname solidSS 0)) ; retrieve first entity in the list (there should be only 1)
(command "_.imprint" ent linevar "_Y" "")
; SELECT IMPRINTED POINT
(setq c (getvar "lastpoint"))
; CALCULATE DISTANCE FROM ORIGINAL POINT TO THE IMPRINTED POINT
(command "dist" p c) ;THIS SHOWS THE RIGHT DISTANCE BUT I NEED IT IN THE MESSAGE BOX
; (alert (strcat "Max heigth is : "(rtos (distance p c) 2 3)))
(princ)
)
DIST command may be effected by osnaps...
You can use this, but its really ugly code...
(alert (strcat "Distance is "(rtos (progn (command "_.dist" "_none" p "_none" c) (getvar 'distance)) 2 3)))
I think maybe that when you
(setq c (getvar "lastpoint"))
you are retrieving the point at the end of your line command, which by your design is 200 units from its first point, p.
That being the case, why do you need to ask for the distance; it's 200, right?
The only other thing for which you need to watch out is running object snaps picking up a point on some other nearby object. I think @ВeekeeCZ demonstrated the use of "_non" which is a good habit. That or turning off OSMODE.
There is no difference in the results of the DIST command vs. the distance function, except that both are real numbers that may display differently. due to luprec. Observe...
Command: (setq p1 (getpoint) p2 (getpoint p1)) (733.461 140.416 0.0) Command: dist Specify first point: !p1 (643.982 71.4946 0.0) Specify second point: !p2 (733.461 140.416 0.0) Distance = 112.94477, Angle in XY Plane = 38d, Angle from XY Plane = 0d Delta X = 89.47868, Delta Y = 68.92088, Delta Z = 0.00000 ;; BTW, my LUPREC was 5. Command: (distance p1 p2) 112.945 Command: (rtos (distance p1 p2) 2 5) "112.94477"
You can see that the distance function returned a value to the screen to only 3 places. That's sort of an AutoCAD habit. But if you use the function to store the distance in a symbol, then it's probably good to 16 places, which is a lot more than you need to build just about anything.
John F. Uhden
@Anonymous wrote:
....
Can i store the distance with the DIST command in a variable then put the variable in the alert code?
YES. The distance result of the latest DIST command goes into a System Variable called [wait for it....] DISTANCE. You don't need to store it in a variable of your own [though you can if you want to do other things with it], but can just use it right from the System Variable:
; CALCULATE DISTANCE FROM ORIGINAL POINT TO THE IMPRINTED POINT
(command "dist" p c) ;THIS SHOWS THE RIGHT DISTANCE
(alert (strcat "Max heigth is : " (rtos (getvar 'distance) 2 3)))
One thing that occurs to me that might explain differing results [without digging too deeply into your code] is that the (distance) AutoLisp function returns a 3D distance only if both points given to it are 3D [that is, have X, Y and Z coordinates]. If any points you're getting from other operations [this is where I didn't dig] are returned as XY-only 2D points, then (distance) will return the projected-flat distance as if both are in the same XY plane, not the actual 3D distance.
I just checked (in 2002 of course) and the DIST command returned a 3D distance between 2 points with differing Zs. (getvar "distance") returned the same 3D value.
John F. Uhden
@john.uhden wrote:
I just checked (in 2002 of course) and the DIST command returned a 3D distance between 2 points with differing Zs. (getvar "distance") returned the same 3D value.
Yes, but I was talking about the AutoLisp (distance) function. If, for example you extract a vertex point from the entity data list of a LWPolyline, that will only supply X and Y coordinates, and the result of a (distance) function using one of those, even if the other point is a full XYZ 3D point, will not reflect any Z-coordinate difference there may be between them.
In contrast, the DIST command, and therefore the value put into the DISTANCE System Variable, will assume a Z coordinate of the current ELEVATION setting to "flesh out" any supplied XY-only 2D point, and return a real 3D distance.
In 2002, I have not experienced what you are describing. The distance from a 2D point to a 3D point was the same 3D distance for both the DIST command and the distance function. The DIST command points were supplied by typing them in. The distance function was supplied with point lists, the first being 2D and the second being 3D. Yes, the 3D point was at a unique elevation /= 0. No, the current elevation was not equal to the 3D point elevation.
John F. Uhden
John F. Uhden
Hi, maybe this as inspiration.
i use a customized distance routine in 2d with grtext (lee mac, black background) and work with a message box in 3d because i prefer to work 3d in white.
A link to the code i will put beneith it.
Right now the only thing I am inspired to do is finish my project of rebuilding a shed door frame and door and siding and trim.
PL Premium Construction Adhesive is extremely inspiring. I figured out how to get most everything out of a caulk tube without it hardening up on me.
John F. Uhden
I think the difference is how lastpoint and osnap work together.
Let me try to explain better:
I have a solid with different heights (the max height of the solid is 152 units) and i need to find out his height in a specific point given by the user on the XY with GEOMARKLATLONG command.
So i draw a vertical line long 200 units from this point and imprint it with the solid then select the imprint point with LASTPOINT and measure the distance.
I believe with osnap, DIST command measure the distance from the point on XY to the point on the solid while DISTANCE measure from the point on XY to the end of the line. that is why with DISTANCE i get 200 no matter where the point on XY is.
If you have suggestions on how to resolve this it would be greatly appreciated.
Too make sure that (command "DIST" .....) isn't affected by OSNAP whatsoever, try setting the variable OSNAPCOORD to 1 (or change in your Options).
The points provided in your command statement are treated as keyboard input while the arguments in (distance .....) are not.
So (distance pt1 pt2) might show the actual real distance between the two supplied points, while (command "DIST" pt1 pt2) is affected by running object snaps.
it worked, it worked, it worked!!!
Here is the code:
; CALCULATE DISTANCE FROM ORIGINAL POINT TO THE IMPRINTED POINT and SHOW DISTANCE IN MESSAGE BOX
(command "dist" p c)
(alert (strcat "Max heigth is : " (rtos (getvar 'distance) 2 3) " mt or " (rtos (* 3.2808399 (getvar 'distance)) 2 3) " ft"))
Thank you all for the suggestions!