Author Topic: Convert a circle to pline  (Read 6711 times)

0 Members and 1 Guest are viewing this topic.

Adesu

  • Guest
Convert a circle to pline
« on: December 20, 2006, 04:14:29 AM »
Hi Alls,
I'm planning to convert a circle to become pline,I got trouble at syntax for command .
Does anyone know syntax command for pline in mapcar.
here that code
Code: [Select]
; cctpl is stand for Convert Circle To PLine
(defun c:cctpl (/ cmt cnt len lst opt spt ss sse ssl ssn ssp)
  (setq ss (car (entsel "\nSelect a circle")))
  (setq opt (getreal "\nEnter number of segment <12>: "))
  (if
    (= opt nil)
    (setq opt 12)
    (setq opt (fix opt))                                    ; 1).
    )                                     ; repeat
  (command "_divide" ss opt "")
  (setq ssp (ssget "x" '((0 . "point"))))
  (setq ssl (sslength ssp))
  (setq cnt 0)
  (repeat
    ssl
    (setq ssn (ssname ssp cnt))
    (setq sse (entget ssn))
    (setq spt (cdr (assoc 10 sse)))
    (setq lst (append lst (list spt)))
    (command "_erase" ssn "")
    (setq cnt (1+ cnt))
    )                                     ; repeat
  (command "_erase" ss "")
  (mapcar '(lambda (x)
     (command "_pline")
     (command x)
     (command "")) lst)
  (princ)
  )                                       ; defun 

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Convert a circle to pline
« Reply #1 on: December 20, 2006, 06:03:16 AM »
As an example
Code: [Select]
(defun c:test (/ A E I L P R)
  ;; Return new entity name
  (if (setq e (car (entsel "\nSelect a circle")))
    (progn
      (setq
        i (/ pi
             ((lambda (i)
                (if i
                  i
                  12
                ) ;_ if
              ) ;_ lambda
               (getint "\nEnter number of segment <12>: ")
             )
             0.5
          ) ;_ /
        a (+ pi pi)
        r (cdr (assoc 40 (entget e)))
        p (cdr (assoc 10 (entget e)))
        l nil
      ) ;_ setq
      (while (> a 0)
        (setq l (cons (cons 10 (polar p a r)) l)
              a (- a i)
        ) ;_ setq
      ) ;_ while
      (entdel e)
      (entmakex
        (append
          (list
            '(0 . "LWPOLYLINE")
            '(100 . "AcDbEntity")
            '(100 . "AcDbPolyline")
            (cons 90 (length l))
            '(70 . 1)
          ) ;_ list
          l
        ) ;_ append
      ) ;_ entmakex
    ) ;_ progn
  ) ;_ if
) ;_ defun

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Convert a circle to pline
« Reply #2 on: December 20, 2006, 08:26:50 AM »
Hi,

Here's a code I had. The pline have only two segments (arcs).

Code: [Select]
(defun c:circle2pline (/ ent cen rad)
  (if (setq ent (ssget "_:S:E" '((0 . "CIRCLE"))))
    (progn
      (setq ent (ssname ent 0)
    cen (cdr (assoc 10 (entget ent)))
    rad (cdr (assoc 40 (entget ent))))
      (entmake
(list '(0 . "LWPOLYLINE")
'(100 . "AcDbEntity")
(assoc 8 (entget ent))
'(100 . "AcDbPolyline")
'(90 . 2)
'(70 . 1)
(cons 38 (cadddr (assoc 10 (entget ent))))
(cons 10 (list (+ (car cen) rad) (cadr cen)))
'(42 . 1.0)
(cons 10 (list (- (car cen) rad) (cadr cen)))
'(42 . 1.0)
(assoc 210 (entget ent))
)

  )
      (entdel ent)
      )
    )
  )

Quote
Does anyone know syntax command for pline in mapcar.

Do you mean that ?

Code: [Select]
(command "_.pline")
(mapcar 'command pts_lst)
(command)
« Last Edit: December 20, 2006, 09:49:14 AM by gile »
Speaking English as a French Frog

Joe Burke

  • Guest
Re: Convert a circle to pline
« Reply #3 on: December 20, 2006, 09:37:03 AM »
Hi Ade,

In addition to what Evgeniy and Gile posted, you might take a look at the code I posted with the "Add wipeouts to existing blocks" topic. There's a function in there called TraceObject. It returns a "traced" point list from any type of pline, or an arc, circle, ellipse or spline.

Given a complex curve like an ellipse or spline, it "traces" the object with some intelligence. Meaning it does not simply divide the curve like the divide command would. Instead the distance between points is based on the delta angle along the curve.

<link added by CAB>
http://www.theswamp.org/index.php?topic=13842.msg166907#msg166907
« Last Edit: December 24, 2006, 03:18:48 PM by CAB »

LE

  • Guest
Re: Convert a circle to pline
« Reply #4 on: December 20, 2006, 07:17:54 PM »
And here you my found a routine to that too... HTH

http://www.theswamp.org/index.php?topic=9441.msg169883#msg169883


Have fun.

Adesu

  • Guest
Re: Convert a circle to pline
« Reply #5 on: December 20, 2006, 07:56:10 PM »
Hi gile,
it's great,thanks for your help,and especially for your code in mapcar.

Hi,

Here's a code I had. The pline have only two segments (arcs).

Code: [Select]
(defun c:circle2pline (/ ent cen rad)
  (if (setq ent (ssget "_:S:E" '((0 . "CIRCLE"))))
    (progn
      (setq ent (ssname ent 0)
    cen (cdr (assoc 10 (entget ent)))
    rad (cdr (assoc 40 (entget ent))))
      (entmake
(list '(0 . "LWPOLYLINE")
'(100 . "AcDbEntity")
(assoc 8 (entget ent))
'(100 . "AcDbPolyline")
'(90 . 2)
'(70 . 1)
(cons 38 (cadddr (assoc 10 (entget ent))))
(cons 10 (list (+ (car cen) rad) (cadr cen)))
'(42 . 1.0)
(cons 10 (list (- (car cen) rad) (cadr cen)))
'(42 . 1.0)
(assoc 210 (entget ent))
)

  )
      (entdel ent)
      )
    )
  )

Quote
Does anyone know syntax command for pline in mapcar.

Do you mean that ?

Code: [Select]
(command "_.pline")
(mapcar 'command pts_lst)
(command)

Adesu

  • Guest
Re: Convert a circle to pline
« Reply #6 on: December 20, 2006, 08:01:24 PM »
Hi Elpanov,
Your code it's great too,I like that and many thanks for your help.

As an example
Code: [Select]
(defun c:test (/ A E I L P R)
  ;; Return new entity name
  (if (setq e (car (entsel "\nSelect a circle")))
    (progn
      (setq
        i (/ pi
             ((lambda (i)
                (if i
                  i
                  12
                ) ;_ if
              ) ;_ lambda
               (getint "\nEnter number of segment <12>: ")
             )
             0.5
          ) ;_ /
        a (+ pi pi)
        r (cdr (assoc 40 (entget e)))
        p (cdr (assoc 10 (entget e)))
        l nil
      ) ;_ setq
      (while (> a 0)
        (setq l (cons (cons 10 (polar p a r)) l)
              a (- a i)
        ) ;_ setq
      ) ;_ while
      (entdel e)
      (entmakex
        (append
          (list
            '(0 . "LWPOLYLINE")
            '(100 . "AcDbEntity")
            '(100 . "AcDbPolyline")
            (cons 90 (length l))
            '(70 . 1)
          ) ;_ list
          l
        ) ;_ append
      ) ;_ entmakex
    ) ;_ progn
  ) ;_ if
) ;_ defun

Adesu

  • Guest
Re: Convert a circle to pline
« Reply #7 on: December 20, 2006, 08:17:00 PM »
Thanks Luis for your share and info too.

And here you my found a routine to that too... HTH

http://www.theswamp.org/index.php?topic=9441.msg169883#msg169883


Have fun.

sinc

  • Guest
Re: Convert a circle to pline
« Reply #8 on: December 21, 2006, 08:25:33 AM »
Given a complex curve like an ellipse or spline, it "traces" the object with some intelligence. Meaning it does not simply divide the curve like the divide command would. Instead the distance between points is based on the delta angle along the curve.

I haven't looked at your code, and don't know how you came up with the Deltas, but do you basically just use the same Delta value for each sample?

If so, you might want to try using the midordinate distance instead.  If you look at an arc segment and its subtended chord, the midordinate distance is the distance between the midpoint of the arc and the midpoint of the chord.  If you select your sample points so that the midordinate distance is always smaller than a certain value, then you know your "approximation" will always follow the curve within a specific amount of error, regardless of how big or small the radius of the curve is.

sinc

  • Guest
Re: Convert a circle to pline
« Reply #9 on: December 21, 2006, 08:36:03 AM »
Hi Alls,
I'm planning to convert a circle to become pline,I got trouble at syntax for command .

Do you happen to have Map?  If so, you can use Drawing Cleanup to turn lines, arcs, circles, and 3D-Polylines into normal polylines.  A circle gets turned into a polyline with a single arc segment, though.  I don't think it will turn a circle into an approximation using line-segments.

But there's also the POLYGON command...  Another version of your Lisp routine could be written that simply erases the circle, and then creates a POLYGON using the same basic parameters.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Convert a circle to pline
« Reply #10 on: December 21, 2006, 08:48:07 AM »
 :-)

Only in Russian
http://dwg.ru/dnl/load.php?id=607&z=.rar

Quote
========== The certain commands(teams) ============

PL-JOIN        Association of polylines
PL-A2L         Replacement of a linear segment in a polyline an arc segment.
PL-L2A         Replacement of an arc segment in a polyline a linear segment.
PL-DIV          Break the chosen segment of a polyline into the specified quantity(amount) of segments or through the specified distance
PL-DIVALL    Break segments of the chosen polyline into the specified quantity(amount) of segments or through the specified distance
PL-VxAdd     Add new top to a polyline
ENTREVS     a reverser of object. A piece choice with the instruction(indication) of a direction
ENTREV       a reverser of objects (a plural choice)
PL-VxRdc     Removal(Distance) of tops of polylines which lay on one straight line (weeding)
PL-VxDel      Removal(Distance) of the chosen top
PL-VxOpt     Removal(Distance) of conterminous tops from a polyline
PL-NoArc     Approximation of arc segments of a polyline
CVPOLY       transformation 3D polylines in 2D polylines from Tony Tanzillo

Adesu

  • Guest
Re: Convert a circle to pline
« Reply #11 on: December 21, 2006, 06:44:29 PM »
Hi sinc,
thanks for your give alternative choose,last time I  created code in order to a circle can be erase a part of whole that circle,look like this code.
Code: [Select]
; cctpl is stand for Convert Circle To PLine
;        Design by  : Adesu <Ade Suharna>
;        Email      : mteybid@yuasabattery.co.id
;        Homepage   : http://www.yuasa-battery.co.id
;        Create     : 20 December 2006
;        Program no.: 0501/12/2006
;        Edit by    : Adesu         21/12/2006      1).
;                     Jeff Mishler  21/12/2006      2).

(defun c:cctpl (/ clt cmt cnt len lst opt spt ss sse ssl ssn ssp)
  (setq ss (car (entsel "\nSelect a circle"))) 
  (or last_num
      (setq last_num 36)
      )                                                    ; if 2).
  (setq opt
(getint
   (strcat "\nEnter number of segment < "
   (itoa last_num)
   " >: ")))
  (if
    (not opt)
    last_num
    (setq last_num opt)
    )                                                      ; if 2).
  (print last_num) 
  (command "_divide" ss opt "")
  (setq ssp (ssget "x" '((0 . "point"))))
  (setq ssl (sslength ssp))
  (setq cnt 0)
  (repeat
    ssl
    (setq ssn (ssname ssp cnt))
    (setq sse (entget ssn))
    (setq spt (cdr (assoc 10 sse)))
    (setq lst (append lst (list spt)))
    (command "_erase" ssn "")
    (setq cnt (1+ cnt))
    )                                                      ; repeat
  (command "_erase" ss "")
  (setq len (length lst))
  (setq cmt 0)
  (setq clt 1)
  (repeat                                                  ; 1).
    len
    (command "pline" (nth cmt lst)(nth clt lst) "")
    (setq cmt (1+ cmt))
    (setq clt (1+ clt))
    )                                                      ; repeat
  (command "_pline" (car lst)(last lst) "")                ; 1).
  (princ)
  )                                                        ; defun


Hi Alls,
I'm planning to convert a circle to become pline,I got trouble at syntax for command .

Do you happen to have Map?  If so, you can use Drawing Cleanup to turn lines, arcs, circles, and 3D-Polylines into normal polylines.  A circle gets turned into a polyline with a single arc segment, though.  I don't think it will turn a circle into an approximation using line-segments.

But there's also the POLYGON command...  Another version of your Lisp routine could be written that simply erases the circle, and then creates a POLYGON using the same basic parameters.

Joe Burke

  • Guest
Re: Convert a circle to pline
« Reply #12 on: December 24, 2006, 09:52:33 AM »
Given a complex curve like an ellipse or spline, it "traces" the object with some intelligence. Meaning it does not simply divide the curve like the divide command would. Instead the distance between points is based on the delta angle along the curve.

I haven't looked at your code, and don't know how you came up with the Deltas, but do you basically just use the same Delta value for each sample?

If so, you might want to try using the midordinate distance instead.  If you look at an arc segment and its subtended chord, the midordinate distance is the distance between the midpoint of the arc and the midpoint of the chord.  If you select your sample points so that the midordinate distance is always smaller than a certain value, then you know your "approximation" will always follow the curve within a specific amount of error, regardless of how big or small the radius of the curve is.

Well, look at what I posted. Why question how I did it, without looking first?

sinc

  • Guest
Re: Convert a circle to pline
« Reply #13 on: December 25, 2006, 02:57:46 AM »
Well, look at what I posted. Why question how I did it, without looking first?

Because you made it hunt-n-seek game - you said it was in the code you posted in some other topic, and left it up to the user to find the other topic, and the post in the other topic, and the code, and then look at the code...  I didn't feel like taking the time to hunt down the code, when you didn't take the time to provide a link.

But you're right - I had no right to comment on your code without looking at it.  Take my post then as just a generic bit-o-info for other possibly-interested parties, and ignore it.

Joe Burke

  • Guest
Re: Convert a circle to pline
« Reply #14 on: December 25, 2006, 09:48:22 AM »
Thanks to CAB for adding a link to my first post here, to the code I refered to in my topic about wipeouts in blocks.