Moving or copying half distance of your pick points
Hello all,
Getting tired of using distance command or drawing reference lines to get half distances I wrote the following lisp. This copies something 1/2 the distance you select and uses the same angle (so if your 2nd point was 6" to the right of your 1st point, the object will get copied 3" to the right)
Also included is the move half distance, it works the same way.
Code:
(defun c:movehalfdist (/ pt1 pt2 myselset halvedtext disttobehalved halfdist angledeg)
(setq myselset (ssget))
(setq pt1 (getpoint "Pick start point: "))
(command "line" pt1 pause "")
(setq pt2 (getvar "lastpoint"))
(setq disttobehalved (distance pt1 pt2))
(command "erase" (entlast) "")
(setq halfdist (/ disttobehalved 2))
;(alert (strcat (rtos halfdist 2 2) " is half of " (rtos disttobehalved 2 2)))
(setq angledeg (* (angle pt1 pt2) (/ 180 3.14159265)))
;(alert (strcat (rtos angledeg 2 0)))
(setq halvedtext (strcat "@" (rtos halfdist 2 6) "<" (rtos angledeg 2 2)))
(command "move" myselset "" pt1 halvedtext)
(princ))
(defun c:copyhalfdist (/ pt1 pt2 myselset halvedtext disttobehalved halfdist angledeg)
(setq myselset (ssget))
(setq pt1 (getpoint "Pick start point: "))
(command "line" pt1 pause "")
(setq pt2 (getvar "lastpoint"))
(setq disttobehalved (distance pt1 pt2))
(command "erase" (entlast) "")
(setq halfdist (/ disttobehalved 2))
;(alert (strcat (rtos halfdist 2 2) " is half of " (rtos disttobehalved 2 2)))
(setq angledeg (* (angle pt1 pt2) (/ 180 3.14159265)))
;(alert (strcat (rtos angledeg 2 0)))
(setq halvedtext (strcat "@" (rtos halfdist 2 6) "<" (rtos angledeg 2 2)))
(command "copy" myselset "" pt1 halvedtext)
(princ))
(defun c:offsethalfdist (/ pt1 pt2 disttobehalved halfdist)
(setq pt1 (getpoint "Pick start point: "))
(command "line" pt1 pause "")
(setq pt2 (getvar "lastpoint"))
(setq disttobehalved (distance pt1 pt2))
(command "erase" (entlast) "")
(setq halfdist (/ disttobehalved 2))
(command ".offset" halfdist)
(princ))
Always up for learning, if I did somehing ineffeciently or just wrong, let me know.
Thansk all
RE: Moving or copying half distance of your pick points
Why not just use the "Midpoint Between 2 points" osnap?
Or... If you are on a previous version that doesn't have that built-in then you can also use an older user version like:
Code:
;;; Mid point of two points
;;;
(DEFUN c:midpt (/ |lunits| |pt1| |pt2| |ptm|)
(SETQ |pt1| (GETPOINT "\nMIDPT: Specify first point: "))
(SETQ |pt2| (GETPOINT |pt1| "\nMIDPT: Specify second point: "))
(SETQ |ptm| (POLAR |pt1|
(ANGLE |pt1| |pt2|)
(/ (DISTANCE |pt1| |pt2|) 2.0)
)
)
(SETQ |lunits| (GETVAR "lunits"))
(IF (MEMBER (GETVAR "cmdnames") (LIST "MIRROR"))
(STRCAT (RTOS (CAR |ptm|) |lunits| 15)
","
(RTOS (CADR |ptm|) |lunits| 15)
)
(STRCAT (RTOS (CAR |ptm|) |lunits| 15)
","
(RTOS (CADR |ptm|) |lunits| 15)
","
(RTOS (CADDR |ptm|) |lunits| 15)
)
)
)
The advantage that using a midpt routine is that you can use it on any command, not just MOVE, COPY, OFFSET.
Start a line, type in " 'midpt ", click first point, second point, and you are now starting a line mid point between the two selected points.
Also included is my OFFSET HALF version. Mine works a little different, but I'm including just for the FYI of it.
Code:
;;; FOR OFFSETTING 1/2 DISTANCE
(DEFUN c:o2 (/ |dist| |fracoff| |lunits| |luprec| |pt1| |pt2|)
(SETQ |lunits| (GETVAR "lunits"))
(SETQ |luprec| (GETVAR "luprec"))
(SETQ |dist|
(GETREAL
"\nEnter Distance To Divide In HALF <ENTER to select first point>: "
)
)
(IF (= |dist| nil)
(SETQ |pt1| (GETPOINT "\nSelect First Point: ")
|pt2| (GETPOINT |pt1| "\nSelect Second Point: ")
|dist| (DISTANCE |pt1| |pt2|)
)
)
(SETQ |halfoff| (/ |dist| 2.0))
(PRINC (STRCAT "\nOffset Distance Set To: "
(RTOS |fracoff| |lunits| |luprec|)
)
)
(COMMAND "offset" |halfoff|)
(PRINC)
)