ssget ? for circles

Discussion in 'AutoCAD' started by spencer1971, May 6, 2004.

  1. spencer1971

    spencer1971 Guest

    Is there a way to select all circles on a layer using ssget and draw a pline to join the centre points of them (from top down or left to right)

    I have managed to make the set but drawing the pline is proving very difficult. for my basic knowlage.

    Many thanks in advance
     
    spencer1971, May 6, 2004
    #1
  2. spencer1971

    BillZ Guest

    Could you post what you have so others can see where help is needed?


    Bill
     
    BillZ, May 6, 2004
    #2
  3. http://www.caddzone.com/ssindex.lsp

    The code shows how to sort objects in a selection set
    (the example is to sort text objects by their X and Y
    ordinates) but can be used to do what you need. The
    gathering of the circles would go something like this:

    (setq LayerPattern "Layer1")

    (setq ss (ssget "x" (list '(0 . "CIRCLE") (cons 8 LayerPattern))))

    Once you have the selection set, you can use the code
    from ssindex.lsp to index the elements in it using whatever
    sort criteria you want, and then process the selection set
    in the sorted order using the index list.

    Drawing the polyline through the center points is relatively
    easy, ask if you need help.
     
    Tony Tanzillo, May 6, 2004
    #3
  4. spencer1971

    spencer1971 Guest

    I have taken this code from a previous post

    (defun C:pl (/ ss)
    (setq ss (ssget '((0 . "CIRCLE"))))
    (if ss
    (progn
    (setq n (1- (sslength ss)))
    (while (>= n 0)
    (setq elist (entget (ssname ss n))
    r (cdr (assoc 40 elist))
    c (cdr (assoc 10 elist))
    n (1- n)
    )
    (xxxxxxxxxxxxxxx)
    )
    )
    )
    )


    This seems to take care of the selection of the circles but its what goes in xxxxx that is confusing.

    (prviously this was a lsp to draw a donut so the xxxx was replaced with donut..... etc..

    I may be completely wrong but can this not be used to insert a pline instead
     
    spencer1971, May 6, 2004
    #4
  5. Doing what you ask requires a modest amount of programming
    experience. The "xxxxx" part as you put it, is fairly involved because
    it requires you to sort the coordinates you get from the selection
    set. The example code I pointed you to will do that, but it is not
    an all-inclusive, read-to-use solution, you need to adapt it.
     
    Tony Tanzillo, May 6, 2004
    #5
  6. spencer1971

    BillZ Guest

    This is how I would do it.

    < not tested >

    (defun C:pl (/ ss)
    (setq ss (ssget '((0 . "CIRCLE"))))
    (if ss
    (progn
    (setq pt (cdr (assoc 10 (entget (ssname ss 0))))
    cnt 1
    )
    (command "pline" pt)
    (repeat (1- (sslength ss))
    (setq pt (cdr (assoc 10 (entget (ssname ss cnt))))
    cnt (1+ cnt)
    )
    (command pt)
    )
    (command "")
    )
    )

    HTH

    Bill
     
    BillZ, May 6, 2004
    #6
  7. spencer1971

    spencer1971 Guest

    Tony,

    help..

    That is a bit complicated.

    Do I just copy the entire script into my code or is there a section that I should extract...
     
    spencer1971, May 6, 2004
    #7
  8. spencer1971

    bob.at Guest

    Spencer

    i would replace (xxxxxx) by the following:

    (setq csor (vl-sort c (function (lambda (e1 e2) (< (car e1) (car e2))))))
    (command "._pline")
    (foreach n csor
    (command n)
    )
    (command "")

    this sorts by x coordinate. For y sorting change the first line to the following:

    (setq csor (vl-sort c (function (lambda (e1 e2) (< (cadr e1) (cadr e2))))))

    bob.at
     
    bob.at, May 6, 2004
    #8
  9. spencer1971

    spencer1971 Guest

    I have this code now but when I run it I get the message:

    Error: bad argument type: consp 0.0

    what does this mean??

    (defun C:pl (/ ss)
    (setq ss (ssget '((0 . "CIRCLE"))))
    (if ss
    (progn
    (setq n (1- (sslength ss)))
    (while (>= n 0)
    (setq elist (entget (ssname ss n))
    r (cdr (assoc 40 elist))
    c (cdr (assoc 10 elist))
    n (1- n)
    )
    (setq csor (vl-sort c (function (lambda (e1 e2) (< (car e1) (car e2))))))
    (command "._pline")
    (foreach n csor
    (command n)
    )
    (command "")
    )
    )
    )
    )
     
    spencer1971, May 7, 2004
    #9
  10. spencer1971

    bob.at Guest

    sorry i typed this without having the posibility to test it. You must build a list from the midpoints. (Now i've testet and it worked, but of course error handling etc. is missing):

    (defun C:pl (/ ss)
    (setq ss (ssget '((0 . "CIRCLE"))))
    (if ss
    (progn
    (setq n (1- (sslength ss)) r nil c nil)
    (while (>= n 0)
    (setq elist (entget (ssname ss n))
    r (cons (cdr (assoc 40 elist)) r)
    c (cons (cdr (assoc 10 elist)) c)
    n (1- n)
    )
    (setq csor (vl-sort c (function (lambda (e1 e2) (< (cadr e1) (cadr e2))))))
    (command "._pline")
    (foreach n csor
    (command n)
    )
    (command "")
    )
    )
    )
    )
     
    bob.at, May 7, 2004
    #10
  11. spencer1971

    spencer1971 Guest

    ONCE AGAIN BOB.AT COMES UP TRUMPS.

    Thank you very much for your help..

    Ill keep practicing,

    Spencer
     
    spencer1971, May 7, 2004
    #11
  12. spencer1971

    spencer1971 Guest

    BOB

    Sorry to keep on at you but I am trying to understand this.

    Why does the routine draw multiple plines with each one gettingh longer ? Is it not possible to draw one, I have tried repositioning the (command pline) line but to no avail.

    It seems to draw a new pline from each centrepoint as well as a continuous one.
     
    spencer1971, May 7, 2004
    #12
  13. spencer1971

    bob.at Guest

    Yes you're right. A closing bracket has moved downwards so the while loop repeats the pline command too. This is wrong becaus you must gather the points, than sort them and than draw the line:


    (defun C:pl (/ ss)
    (setq ss (ssget '((0 . "CIRCLE"))))
    (if ss
    (progn
    (setq n (1- (sslength ss)) r nil c nil)
    (while (>= n 0)
    (setq elist (entget (ssname ss n))
    r (cons (cdr (assoc 40 elist)) r)
    c (cons (cdr (assoc 10 elist)) c)
    n (1- n)
    )
    )
    (setq csor (vl-sort c (function (lambda (e1 e2) (< (cadr e1) (cadr e2))))))
    (command "._pline")
    (foreach n csor
    (command n)
    )
    (command "")
    )
    )
    )


    If you want you can omit the line beginnig with r (cons (cdr .... It builds a list of the circle radii but you dont use it

    bob.at
     
    bob.at, May 7, 2004
    #13
  14. spencer1971

    spencer1971 Guest

    Bob

    I can see it now,

    Thank you for your patients

    Spencer
     
    spencer1971, May 7, 2004
    #14
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.