Line from circumference of a circle

Line from circumference of a circle

Anonymous
Not applicable
3,384 Views
14 Replies
Message 1 of 15

Line from circumference of a circle

Anonymous
Not applicable

Hi, 
I need help with something. I want my lisp to be able to draw a circle of an already specified radius and automatically draw line from the middle of the circumference of the circle. I managed to do the circle and radius part. Here's what I have so far:
(defun c:lolp (/ center value-of-radius)
(terpri)
(setq center (getpoint "Specify center of circle:"))
(terpri)
(setq value-of-radius 1124.998)
(command "_circle" center value-of-radius)
(command "_chprop" "_last" "" "_color" "green" "")
)
I don't know how to add the line part. I know I can use the line command by doing something like : (command "_line") but idk how to write in my program that the line should start from the middle point of the circumference of the circle, either vertical or horizontal line. The length of line will also be specific in the program so at the end I should get a circle and line drawn together with predefined values. Could someone help me with line part or suggest something? 
Any help will be appreciated 🙂

 

0 Likes
Accepted solutions (2)
3,385 Views
14 Replies
Replies (14)
Message 2 of 15

DannyNL
Advisor
Advisor

What do you mean with 'middle of the circumference'?

I don't know exactly what you mean and you must probably mean something else since you already have the center of the circle.

0 Likes
Message 3 of 15

Anonymous
Not applicable

sorry if I wasn't clear 🙂 I mean I want the line to be drawn from the boundary/edge of the circle. I don't want to draw the line from the middle of the circle because then I'll have to trim it. I want the starting point of the line to be on the edge of the circle, more specifically the mid point on the edge of the circle. 

0 Likes
Message 4 of 15

roland.r71
Collaborator
Collaborator

So you need to retrieve the use the selected circles centerpoint, add or substract the (known) radius from the x or y value (depending on which direction you wish to go) and start drawing your line from there.

0 Likes
Message 5 of 15

Anonymous
Not applicable

Yes! but the problem is the x and y value will change depending on what the user will select as the center point of the circle so I don't know how to calculate that.

0 Likes
Message 6 of 15

Anonymous
Not applicable

Also, the length of line will be a fixed value so I only need the start point no end point. The end point will be determined by the predefined length of the line which can be set inside the code.

0 Likes
Message 7 of 15

DannyNL
Advisor
Advisor
Accepted solution

Ok, try this.

Just used your own code and added some stuff, so no pretty code or error checking etc.

 

(defun c:lolp (/ varlist oldvars center value-of-radius line-length direction)
   (setq varlist '("CMDECHO" "OSMODE"))
   (setq oldvars (mapcar 'getvar varlist))
   (setvar "OSMODE" 4)
   (setq center (getpoint "Specify center of circle:"))
   (setq value-of-radius 1124.998)
   (setq line-length 2500.0)
   (command "_circle" center value-of-radius)
   (command "_chprop" "_last" "" "_color" "green" "")
   (setvar "OSMODE" 0)
   (setq direction (getangle center "\nDirection of line: "))
   (command "_.LINE" (polar center direction value-of-radius) (polar center direction (+ value-of-radius line-length)) "")
   (mapcar 'setvar varlist oldvars)
   (princ)
)

 Any direction of the line will work, but use with ORTHO if you only want to use horizontal/vertical direction (can also be hardcoded if necessary).

0 Likes
Message 8 of 15

roland.r71
Collaborator
Collaborator
Accepted solution

try this:

(setq center (getpoint "Specify center of circle:"))
(setq value-of-radius 1124.998)
(command "_.circle" center value-of-radius)
(command "_.chprop" "_last" "" "_color" "green" "")
(setq circ_x (+ (nth 0 center) value-of-radius))
(setq circ_y (nth 1 center))
(setq circ_z (nth 2 center))
(setq start_line (list circ_x circ_y circ_z))
(command "_.line" start_line "@ 1000,0" "")

What you have for the var center is a list: (x y z)

 

You can retrieve each value as i did above and add or substract the radius from that.

Then create a list with the new values and use that as startingpoint for the line.

 

Here it will draw a line to the right (X + radius), 1000 points long.

0 Likes
Message 9 of 15

Anonymous
Not applicable

Thats excatly what I wanted. Thanks a lot! 🙂

0 Likes
Message 10 of 15

Anonymous
Not applicable

Thank you so much 🙂

0 Likes
Message 11 of 15

DannyNL
Advisor
Advisor

You're welcome and glad we could help Smiley Happy

 

Just for fun as I had some time to spare, see new code below.

This code will let you select multiple circles, ask for the needed values and create the circles and lines for all selected circles.

 

(defun C:LOLP (/ LOLP_Selection LOLP_DefaultLength LOLP_DefaultAngle LOLP_DefaultRadius LOLP_LineLength LOLP_LineAngle LOLP_CircleRadius LOLP_CircleList)
   (if
      (setq LOLP_Selection (ssget '((0 . "CIRCLE"))))
      (progn
         (setq LOLP_DefaultLength 2500.0)
         (setq LOLP_DefaultAngle  0.0)
         (setq LOLP_DefaultRadius 1124.998)
         (initget 6)         
         (if
            (not (setq LOLP_LineLength (getreal (strcat "\nLine length <" (rtos LOLP_DefaultLength) ">: "))))
            (setq LOLP_LineLength LOLP_DefaultLength)
         )
         (initget 6)         
         (if
            (not (setq LOLP_LineAngle (getangle (cdr (assoc 10 (entget (ssname LOLP_Selection 0)))) (strcat "\nDirection of line <" (rtos LOLP_DefaultAngle) ">: "))))
            (setq LOLP_LineAngle LOLP_DefaultAngle)
         )
         (initget 6)         
         (if
            (not (setq LOLP_CircleRadius (getreal (strcat "\nCircle radius <" (rtos LOLP_DefaultRadius) ">: "))))
            (setq LOLP_CircleRadius LOLP_DefaultRadius)
         )        
         (foreach LOLP_Circle (vl-remove-if '(lambda (LOLP_Item) (listp (cadr LOLP_Item))) (ssnamex LOLP_Selection))
            (entmake               
               (list
                  '(0 . "CIRCLE")
                  '(100 . "AcDbEntity")
                  '(100 . "AcDbCircle")
                  (assoc 10 (setq LOLP_CircleList (entget (cadr LOLP_Circle))))
                  (cons 40 LOLP_CircleRadius)
                  '(62 . 3)
               )               
            )
            (entmake               
               (list
                  '(0 . "LINE")
                  '(100 . "AcDbEntity")
                  '(100 . "AcDbLine")
                  (cons 10 (polar (cdr (assoc 10 LOLP_CircleList)) LOLP_LineAngle LOLP_CircleRadius))
                  (cons 11 (polar (cdr (assoc 10 LOLP_CircleList)) LOLP_LineAngle (+ LOLP_CircleRadius LOLP_LineLength)))
                  '(62 . 3)
               )               
            )            
         )
      )
   )
   (princ)
)
0 Likes
Message 12 of 15

Kent1Cooper
Consultant
Consultant

It seems to me this could be done a lot more simply.  If you have a fixed value, there's no point in setting it into a variable [especially when you use a variable name considerably longer than entering the value directly].  And the Circle command will supply its own prompt for the center.  And multiple commands can be combined into one (command) function.  Try something like this:

(defun C:LOLP (/ ctr)
  (command
    "_circle" pause 1124.998
    "_chprop" "_last" "" "_color" "green" ""
    "_.line" (polar (setq ctr (getvar 'lastpoint)) 0 1124.998) "@2000,0" "" ; EDIT length
    "_.rotate" "_last" "" ctr pause
  )
  (princ)
)

It draws the Line before  asking you which direction you want it to go, and you Rotate it to that direction, seeing it at its actual length in the process.

 

Kent Cooper, AIA
Message 13 of 15

roland.r71
Collaborator
Collaborator

@Kent1Cooper wrote:

It seems to me this could be done a lot more simply.  If you have a fixed value, there's no point in setting it into a variable [especially when you use a variable name considerably longer than entering the value directly].  And the Circle command will supply its own prompt for the center.  And multiple commands can be combined into one (command) function.  Try something like this:

(defun C:LOLP (/ ctr)
  (command
    "_circle" pause 1124.998
    "_chprop" "_last" "" "_color" "green" ""
    "_.line" (polar (setq ctr (getvar 'lastpoint)) 0 1124.998) "@2000,0" "" ; EDIT length
    "_.rotate" "_last" "" ctr pause
  )
  (princ)
)

It draws the Line before  asking you which direction you want it to go, and you Rotate it to that direction, seeing it at its actual length in the process.

 


@Anonymous't forget to add a space between the @ and the coords. to make a relative coordinate work from lisp.

"@2000,0" doesn't work

"@ 2000,0" does

0 Likes
Message 14 of 15

Kent1Cooper
Consultant
Consultant

@roland.r71 wrote:
@Anonymous't forget to add a space between the @ and the coords. to make a relative coordinate work from lisp.

"@2000,0" doesn't work

"@ 2000,0" does


Not true  for me [Acad2016 where I am at the moment] -- it works fine as written.

Kent Cooper, AIA
0 Likes
Message 15 of 15

roland.r71
Collaborator
Collaborator

Hmm... they both work fine (AutoCAD 2015). at least with _.line

Wierd, as not too long ago there was a topic about it and it did indeed not work... there and then.

Adding the space solved the issue.

 

edit:

Nah, i give up. Tried various ways to get the coords. (lists, integers, strings) and tried various commands, but ...

I can't get it to NOT work anymore Smiley Frustrated (oh well, if it works, it works)

0 Likes