Jump to content

Recommended Posts

Posted

Hi Guys

 

I've searched for this assuming someone would hav already, and it seems like theres many similar but not the same.
Between 20 and 100 times per day I need to draw a line, this line is always horizontal so no angle required.

I would know its length (this is the 1st variable) and I have an endpoint to click on, which would be the midpoint of the line (2nd variable)
Currently i'm drawing a line at its length and moving it from Midpoint to endpoint
 

So i'm looking for a routine that asks for Pt1 (i can choose an endpoint of a line)
Then asks for the line length (I input its total length)
and it draws a horizontal line of that length, and the centre of this line is the endpoint i chose.

 

Any and all help is appreciated, questions also welcome

Posted (edited)

@Sharper Here is a fairly simple one that gives you the option to enter a length, or select an endpoint of the line to make the distance.

(defun c:MIDLINE (/ an ln mp p2)
   (if
      (and
         (setq mp (getpoint "\nSelect a point for the Middle of the Line: "))
         (or (setq ln (getdist "\nEnter the length of the line or <Enter to select Endpoint>: "))
             (setq p2 (getpoint mp "\nSelect an Endpoint for the line: ")
                   ln (if p2 (* (distance mp p2) 2))
             )
         )
      )
      (progn
         (setq an (if p2 (angle p2 mp) 0.0))
         (command "._Line" "_non" (polar mp an (/ ln 2)) "_non" (polar mp (+ an pi) (/ ln 2)) "")
      )
   )
   (princ)
)

 

NOTE: if you use the "Select Endpoint" option. this will draw the midline at any angle created with the midpoint and endpoint.

Edited by pkenewell
Added note for use.
  • Thanks 1
Posted

Here is a quick and dirty example, using a data entry helper function.  Some other ways to do the same thing also shown (remmed out) in code.

(defun C:LineMPL (/ MP P1 P2 OldOsnap)
; Draw line based on centre point and length
; KJM - Jan 2025
; Uses custom functions:
;	getdata

; Get inputs
; Midpoint
(setq MP (getpoint "\nSelect line midpoint..."))

; Length with pre-set default
(if (and (not MyLength) (not (type MyLength) 'REAL)) (setq MyLength 10.0))	; hard coded starting default
(setq MyLength (getdata "R" "Enter length " MyLength))

; Angle (even though you do not need, someone else might.  Rem it out if not needed)
(if (and (not MyAngle) (not (type MyAngle) 'REAL)) (setq MyAngle 0.0))	; hard coded starting default
(setq MyAngle (getdata "R" "Enter angle (degrees) " MyAngle))

; Better method that allows pick, but no default
;(setq MyAngle (getangle MP "\nSelect or enter angle..."))

; Make line endpoints
(setq P1 (polar MP (+ MyAngle pi) (* 0.5 MyLength)))
(setq P2 (polar P1 MyAngle MyLength))

; Draw line (or could entmake the line - see example below)
; Cancel any current object snaps
(setq OldOsnap (getvar "OSMODE"))
(setvar "OSMODE" 0)

(command ".LINE" P1 P2 "")

; Reset object snap setting
(setvar "OSMODE" OldOsnap)

; Draw line using entmake (do not need to worry about object snaps)
;(entmake (list '(0 . "LINE") (cons 10 P1) (cons 11 P2)))

(princ)
)


; ========================================================= Helper functions


(defun GetData (DataType DataPrompt Default / Data)
; Get Integer, Real, String or Point, returns Data
; KJM 1990?
; Input:
;	DataType - (string, typ 1 char) desired type of value
;		where	"I" = integer
;			"R" = Real
;			"S" = String
;			"P" = Point (or vector)
;	DataPrompt - (string) text prompt 
;	Default - (integer or real) default value 
; Returns
;	value of type specified by 'DataType'
; Uses custom functions:
;	none!

(setq DataType (strcase (substr DataType 1 1)))
(prompt (strcat "\n" DataPrompt " <"))
(princ Default)(princ)
(cond
	((= DataType "I")	; Integer
	  (progn
		(setq Data (getint ">: "))
		(if (= Data nil) (setq Data Default))
	  )
	)
	((= DataType "R")	; Real
	  (progn
		(setq Data (getreal ">: "))
		(if (= Data nil) (setq Data Default))
	  )
	)
	((= DataType "S")	; String (with spaces)
	  (progn
		(setq Data (getstring 1 ">: "))
		(if (= Data "") (setq Data Default))
	  )
	)
	((= DataType "P")	; Point
	  (progn
		(setq Data (getpoint ">: "))
		(if (= Data nil) (setq Data Default))
	  )
	)
)
Data	; return data
)

 

  • Thanks 1
Posted

Ahh this is perfect, and most perfectly

 

You sir are a Legend

 

  • Like 1
Posted

Thanks Kirby

 

Another great one, i'll keep this in case they change what they need in future.

Posted

Just noticed a typo in my solution, had asked for the angle in degrees but didn't convert to radians to use in polar function.  (Not sure how to edit previous posts)

Posted
1 minute ago, kirby2 said:

Just noticed a typo in my solution, had asked for the angle in degrees but didn't convert to radians to use in polar function.  (Not sure how to edit previous posts)

@kirby2 Select the 3 vertical dots on the upper right corner of your post, then select "Edit". To edit code afterward just double click on the code pane.

image.png.b3a99ea81ba4cbed90d00a4e1619a701.png

Posted

@Pkenewell

Thanks, mine only shows 'Report and Share' (maybe because my new user profile only has 7 messages - lost access to my original 'kirby' profile a year ago).

Posted (edited)

I am on holidays but I have a catch error reactor so you would type m123 on command line and it would ask for a pt and draw line 123 long or any mxxx distance  hopefully this is correct example of circle and offset you can add the mxxx option. On iPad at moment. fillet reactor.lsp

Edited by BIGAL

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