Author Topic: Continuous Polar Line with lisp  (Read 1251 times)

0 Members and 1 Guest are viewing this topic.

siddik

  • Mosquito
  • Posts: 6
Continuous Polar Line with lisp
« on: June 14, 2021, 07:59:35 AM »
hi

i was digging the internet from couple of days to find our a lisp to draw an object with a continuous line, since my drawings are always symmetrical Circular Parts with n number of steps in Outer Diameter & inner Diameter, to draw a length is easy just line command & enter length, but to make steps diametrically i have to switch on transparent cal command & type (d1 - d2)/2 for each of the steps which is quite time consuming, & new users who are not use to cal command they use physical calculator for this process

can anybody help me with lisp code so that i just enter the length & next diameter until the last point, also need to generate a center line & mirror the object at the end & connect all the lines of inner diameter

hope my explanation is clear, even though i am attaching an example drawing for a clear picture.

d2010

  • Bull Frog
  • Posts: 326
Re: Continuous Polar Line with lisp
« Reply #1 on: June 14, 2021, 08:44:49 AM »
Code: [Select]
TEXTSCR
REGEN
(COMMAND "UNITS" "2" "3" "3" "5" "300" "y")
(SETVAR "TEXTSIZE" 0.5)
(SETQ C1ECOLOR (GETVAR "CECOLOR"))
(SETQ C1LAYER (GETVAR "CLAYER"))
(IF (/= C1ECOLOR "1") (SETVAR "CECOLOR" "1"))
(IF (/= C1LAYER "0") (SETVAR "CLAYER" "0"))
(COMMAND "OSNAP" "OFF")
(COMMAND "_.UNDO" "_BEGIN")
TEXT 3509.642,836.389   "s500"
LINE 3509.642,836.389 @115.705<352.5315g
TEXT 3431.143,921.392   "pP1" TEXT 3509.642,836.389   "s500"
LINE 3509.642,836.389 @86.318<388.878g
TEXT 3494.638,921.392   "pP2" TEXT 3509.642,836.389   "s500"
LINE 3509.642,836.389 @71.591<386.5586g
TEXT 3494.638,906.390   "pP3" TEXT 3509.642,836.389   "s500"
LINE 3509.642,836.389 @70.003<399.547g
TEXT 3509.144,906.390   "pP3" TEXT 3509.642,836.389   "s500"
LINE 3509.642,836.389 @50.002<399.3657g
TEXT 3509.144,886.389   "pP5" TEXT 3509.642,836.389   "s500"
LINE 3509.642,836.389 @70.003<399.547g
TEXT 3509.144,906.390   "pP4" TEXT 3509.642,836.389   "s500"
LINE 3509.642,836.389 @50.002<399.3657g
TEXT 3509.144,886.389   "pP5" TEXT 3509.642,836.389   "s500"
LINE 3509.642,836.389 @51.306<14.3931g
TEXT 3521.143,886.389   "pP6" TEXT 3509.642,836.389   "s500"
LINE 3509.642,836.389 @44.255<35.6378g
TEXT 3533.142,873.889   "pP6" TEXT 3509.642,836.389   "s500"
LINE 3509.642,836.389 @34.311<48.0318g
TEXT 3533.142,861.389   "pP6" TEXT 3509.642,836.389   "s500"
LINE 3509.642,836.389 @34.311<351.9682g
TEXT 3486.142,861.389   "pP6" TEXT 3509.642,836.389   "s500"
LINE 3509.642,836.389 @46.391<366.183g
TEXT 3486.142,876.387   "pP6" TEXT 3509.642,836.389   "s500"
LINE 3509.642,836.389 @60.58<345.9105g
TEXT 3464.144,876.387   "pP6" TEXT 3509.642,836.389   "s500"
LINE 3509.642,836.389 @71.38<356.0016g
TEXT 3464.144,891.389   "pP6" TEXT 3509.642,836.389   "s500"
LINE 3509.642,836.389 @60.58<345.9105g
TEXT 3464.144,876.387   "pP6" TEXT 3509.642,836.389   "s500"
LINE 3509.642,836.389 @71.38<356.0016g
TEXT 3464.144,891.389   "pP6" TEXT 3509.642,836.389   "s500"
LINE 3509.642,836.389 @86.295<343.9942g
TEXT 3443.146,891.389   "pP6" TEXT 3509.642,836.389   "s500"
LINE 3509.642,836.389 @100.235<353.8219g
TEXT 3443.146,911.390   "pP6"
(COMMAND "_.UNDO" "_END")
(COMMAND "OSNAP" "CEN")
(SETQ C1ECOLOR NIL)
(SETQ C1LAYER NIL)
GRAPHSCR

i was digging the internet from couple of days to find our a lisp to draw an object with a continuous line, since my drawings are always symmetrical Circular Parts with n number of steps in Outer
« Last Edit: June 14, 2021, 08:56:12 AM by d2010 »

BIGAL

  • Swamp Rat
  • Posts: 1409
  • 40 + years of using Autocad
Re: Continuous Polar Line with lisp
« Reply #2 on: June 14, 2021, 09:04:32 PM »
A lisp pick end of c/l go left or right, then make a list of the dia and step length, do a check before pressing ok a custom dcl. Then draw and as suggested mirror. This is very much like a stair.lsp.

If I get time will do something.

d2010 stop posting Bull@#$% where is the Administrator.
A man who never made a mistake never made anything

BIGAL

  • Swamp Rat
  • Posts: 1409
  • 40 + years of using Autocad
Re: Continuous Polar Line with lisp
« Reply #3 on: June 16, 2021, 12:59:08 AM »
I forgot about this may be a starting point. Could add maybe C for chamfer.

Code: [Select]
; draw a pline by direction Up Down left or Right use upper or lowercase
; by Alan H dec 2015
; this version is a metric/decimal version
; version 2 depending on request will be a imperial version
; 1'8 1/4" input d1.8.25 start with 1.8 = 1'8" then add second fraction ver 3

; how to use u123.45 D34.57 R102.6

(defun ah:left ( / pt2)
(setq pt2 (polar pt pi (atof (substr ans 2 (- (strlen ans) 1)))))
(setq pt pt2)
(command pt2)
)

(defun ah:up ( / pt2)
(setq pt2 (polar pt (/ pi 2.0) (atof (substr ans 2 (- (strlen ans) 1)))))
(setq pt pt2)
(command pt2)
)

(defun ah:right ( / pt2)
(setq pt2 (polar pt 0.0 (atof (substr ans 2 (- (strlen ans) 1)))))
(setq pt pt2)
(command pt2)
)

(defun ah:down ( / pt2)
(setq pt2 (polar pt (* 1.5 pi) (atof (substr ans 2 (- (strlen ans) 1)))))
(setq pt pt2)
(command pt2)
)

(defun C:ahpliner ( / pt ans)

(command "_pline")
(command (setq pt (getpoint "Pick start point - Enter or C to finish")))
(while (= (getvar "cmdactive") 1 )
(setq ans (getstring "Enter L123 U456 R67 D78"))
(cond ((= ans "")(command ""))
      ((= "L"(strcase (substr ans 1 1)))(ah:left))
      ((= "U"(strcase (substr ans 1 1)))(ah:up))
      ((= "D"(strcase (substr ans 1 1)))(ah:down))
      ((= "R"(strcase (substr ans 1 1)))(ah:right))
      ((= "C"(strcase (substr ans 1 1)))(command "close"))
) ;cond
) ; while
)
A man who never made a mistake never made anything

siddik

  • Mosquito
  • Posts: 6
Re: Continuous Polar Line with lisp
« Reply #4 on: June 17, 2021, 02:07:09 AM »
thanks Bigal, we are almost there but need a little change in the code since this is only drawing Left, Right, Up & down, my requirement for down is to divide (d1-d2)/2, so if d1 is initially added with getreal and D should prompt for next Diameter(d2) and make the calculation as required will make the thing happen

BIGAL

  • Swamp Rat
  • Posts: 1409
  • 40 + years of using Autocad
Re: Continuous Polar Line with lisp
« Reply #5 on: June 17, 2021, 08:17:30 PM »
I understand your request and calculating simple formulas has been asked before its very complicated to do in a programming sense.

Enter d1 d2 etc d3= (d1-d2)/2 and so on.

It is possible to do a auto make variable names so making d1 d2 d3 etc is not a problem.

Using cal a function inside Autocad very few know about it. In your case would need to look at string does it have any of the following ( + - / * note -ve may need a double check or always enter as d4=(d1-d2) not d4=d1-d2

Code: [Select]
(defun c:foo ()
(setq d1 100 d2 50)
;(setq str (getstring "string"))
(setq str "d3=(d1-d2)/2")
(setq ans (cal str))
(alert (rtos ans 2 3))
(princ)
)
(c:foo)

dynamic d's
Code: [Select]
(setq x 1)
(set (read (strcat "d" (rtos x 2 0))) ans)

I think a triple column dcl would be good so enter all formula values etc then view before pressing OK. The third column is updated based on the values. A complicated dcl.

If happy post what you have. Or PM me the code.

« Last Edit: June 17, 2021, 09:38:57 PM by BIGAL »
A man who never made a mistake never made anything