Author Topic: create many circle on circumference of a circle - Help please  (Read 2145 times)

0 Members and 1 Guest are viewing this topic.

Adesu

  • Guest
create many circle on circumference of a circle - Help please
« on: November 04, 2007, 09:58:23 PM »
Hi Alls.
Here my code, this code to create many circle on circumference of a circle, but that result not as I want.
look at attach file
Code: [Select]
(defun c:test (/ bp cir cnt ctr dia div ent obj
                ss sse ssl ssn vevo)
   (vl-load-com)
   (if
      (setq ent (car (entsel "\nSelect an object circle")))
      (progn
         (setq vevo (vlax-ename->vla-object ent))
         (setq obj (vlax-get vevo 'objectname))
         (if
            (= obj "AcDbCircle")
            (progn
               (setq ctr (vlax-get vevo 'center))
               (setq cir (vlax-get vevo 'circumference))
               (setq dia (getreal "\nEnter diameter circle<1>: "))
               (if (= dia nil)(setq dia 1))
               (setq div (getint "\nEnter total circle<12>: "))
               (if (= div nil)(setq div 12))
               (command "_divide" ent div "")
               (setq ss (ssget "x" '((0 . "POINT"))))
               (setq ssl (sslength ss))
               (setq cnt 0)
               (repeat
                  ssl
                  (setq ssn (ssname ss cnt))
                  (setq sse (entget ssn))
                  (setq bp (cdr (assoc 10 sse)))
                  (command "_circle" bp dia "")
                  (setq cnt (1+ cnt))
                  ) ; repeat
               )    ; progn
            (alert "\nThat object is not circle")
            )       ; if
         )          ; progn
      (alert "\nInvalid selected object,try again")
      )             ; if
   (princ)
   ) ; defun


jonesy edit - changed thread title
« Last Edit: November 05, 2007, 11:24:01 AM by jonesy »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: What wrong my code
« Reply #1 on: November 04, 2007, 10:48:53 PM »
What happens when you use this:
Code: [Select]
(command "_circle" "_non" bp dia "")
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Adesu

  • Guest
Re: What wrong my code
« Reply #2 on: November 04, 2007, 11:06:50 PM »
Hi CAB,
it's great solution and good trick.
thanks,..thanks,....thanks.


What happens when you use this:
Code: [Select]
(command "_circle" "_non" bp dia "")

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: What wrong my code
« Reply #3 on: November 04, 2007, 11:14:12 PM »
What do you think about this code?
I'll see your reply in the morning as it's 11:15 pm here. Off to bed.

Code: [Select]
(defun c:test (/ pt cir dia div ent dis step)
  (vl-load-com)
  (if
    (setq ent (car (entsel "\nSelect an object circle")))
     (progn
       (if (= (cdr(assoc 0 (entget ent))) "CIRCLE")
          (progn
            (setq cir (vlax-curve-getDistAtParam ent (vlax-curve-getEndParam ent)))
            (setq dia (getreal "\nEnter diameter circle<1>: "))
            (or dia (setq dia 1))
            (setq div (getint "\nEnter total circle<12>: "))
            (or div (setq div 12))

            (setq step (/ cir div)
                  dis  step
            )
            (repeat div
              (setq pt  (vlax-curve-getpointatdist ent dis)
                    dis (+ step dis)
              )
              (entmake (list (cons 0 "CIRCLE")
                             (cons 10 pt)
                             (cons 40 dia)
                       )
              )
            )
          )
          (alert "\nThat object is not circle")
       )
     )
     (alert "\nInvalid selected object,try again")
  )
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Adesu

  • Guest
Re: What wrong my code
« Reply #4 on: November 05, 2007, 01:52:26 AM »
Hi CAB ,
This code good too, I like that..thanks.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: create many circle on circumference of a circle - Help please
« Reply #5 on: November 05, 2007, 09:42:19 AM »
How about another version?
Code: [Select]
(defun c:test (/ pt cir dia div ent dis step)
  (vl-load-com)
  (if
    (setq ent (car (entsel "\nSelect an object circle")))
     (progn
       (if
         (and (= (cdr (assoc 0 (setq elst (entget ent)))) "CIRCLE")
              (not (initget 6))
              (or (setq dia (getdist "\nEnter diameter of circle to add <1>: "))
                  (setq dia 1)
              )
              (not (initget 6))
              (or (setq div (getint "\nEnter number of circles to add <12>: "))
                  (setq div 12)
              )
              (not
                (while
                  (progn
                    (setq ang (getint "\nEnter angle for first circle <0>: "))
                    (cond
                      ((null ang) (setq ang 0.) nil) ; exit loop
                      ((< ang -360)
                       (print "Angle must be greater than -360.")
                      )
                      ((> ang 360)
                       (print "Angle must be less than 360.")
                      )
                      (t nil) ; exit loop
                    )
                  )
                )
              )
         )
          (progn
            (command "_undo" "_begin")
            (setq ang (/ (* ang pi) 180.0)) ; deg to radians
            (setq cen (cdr (assoc 10 elst)) ; center point
                  rad (cdr (assoc 40 elst)) ; radius
                  cir (* pi (* rad 2)) ; circumference
            )

            (setq deltaAng (/ (* pi 2) div))
            (repeat div
              (setq pt  (polar cen ang rad)
                    ang (+ ang deltaAng)
              )
              (entmake (list (cons 0 "CIRCLE")
                             (cons 10 pt)
                             (cons 40 dia)
                       )
              )
            )
            (command "_undo" "_end")
          )
          (alert "\nThat object is not circle")
       )
     )
     (alert "\nInvalid selected object,try again")
  )
  (princ)
)
« Last Edit: November 05, 2007, 01:09:11 PM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.