Help to correction my code

Discussion in 'AutoCAD' started by Adesu, Feb 1, 2005.

  1. Adesu

    Adesu Guest

    I just create a script ,this program is to create a spline and every point
    make a circle,my code got problem,and I don't know why this code not yet
    completed.
    Would you help me to correct it,thanks.

    (defun c:ccs (/ cir pt npt n idx cnt e)
    (setq cir (getreal "\nENTER NEW RADIUS: "))
    (while
    (setq pt (getpoint "\nEnter Point: "))
    (setq npt (append npt (list pt))))
    (setq n (length npt))
    (setq idx 0)
    (setq cnt 0)
    (repeat n
    (setq e (nth cnt npt))
    (princ "\n")(princ e)
    (command "_spline" pt e "" "" "")
    (command "_circle" pt cir ""
    "_circle" e cir "")
    (setq cnt (1+ cnt)))
    (princ)
    )
     
    Adesu, Feb 1, 2005
    #1
  2. Adesu

    Joe Burke Guest

    Hi Ade,

    The main problem with your code is you cannot start the spline command and then call
    the circle command within a (repeat) loop. IOW, draw the spline, then add the circles
    at each fit point, assuming that's what you want.

    Something like this.

    Code:
    (defun c:ccs (/ osm radius p1 pt ptlst)
    (setq osm (getvar "osmode"))
    ;use getdist rather than getreal?
    (setq radius (getdist "\nENTER NEW RADIUS: "))
    ;p1 for rubberband between points
    (setq p1 (getpoint "\nEnter Point: "))
    (setq ptlst (list p1))
    (while (setq pt (getpoint p1 "\nEnter Point: "))
    (setq ptlst (append ptlst (list pt)))
    (setq p1 pt)
    )
    (setvar "osmode" 0)
    (command "_spline") ;start spline command
    (foreach x ptlst
    (command x)
    )
    (command "" "" "") ;end spline command
    (foreach x ptlst
    (command "_circle" x radius)
    )
    (setvar "osmode" osm)
    (princ)
    ) ;end
    
    HTH
    Joe Burke
     
    Joe Burke, Feb 1, 2005
    #2
  3. Adesu

    Adesu Guest

    Yes , like that,thanks a lot Joe

     
    Adesu, Feb 2, 2005
    #3
  4. Adesu

    Joe Burke Guest

    Ade,

    You're welcome. Glad to hear I understood your intent.

    Joe Burke
     
    Joe Burke, Feb 2, 2005
    #4
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.