Modifying dotted pair

Discussion in 'AutoCAD' started by Ryan Kiss, Jan 19, 2005.

  1. Ryan Kiss

    Ryan Kiss Guest

    I am new to lisp and trying to learn so please forgive what is probably a very simple question.
    I am trying to write a routine to search the drawing for any circles that are color 21 and change them to color 51. If there are no circles color 21 I'd like the routine to end.
    I've figured out how to create a selection set:
    (setq ss (ssget "x" '((0 . "circle")(62 . 21))))
    How do I go about changing these circles to color 51?
    Any help would be greatly appreciated. Thanks.
     
    Ryan Kiss, Jan 19, 2005
    #1
  2. Ryan Kiss

    T.Willey Guest

    (if (setq ss "x" '((0 . "CIRCLE")(62 . 21)))
    (while (setq tmpEnt (ssname ss 0))
    (setq EntData (entget tmpEnt))
    (entmod (subst (cons 62 51) (assoc 62 EntData) EntData))
    (ssdel tmpEnt ss)
    )
    )

    The while is saying while there is objects in the selection set do what is in the loop.
    What is in the loop is, getting the entity data from the object, the changeing it to the new data you want.

    Hope it helps. Written on the fly, but should work.
    Tim
     
    T.Willey, Jan 19, 2005
    #2
  3. The simplest way is to record the exact keystrokes you use in AutoCAD (after
    you have selected the items), then issue the following line -
    (command "_chprop" SS "" "C" "51" "")
    The "" after SS is a return character required to stop the selection
    process.
    The "" at the end is to finish the CHPROP command.
    There are many other ways to accomplish this, but this is the easiest to
    learn.

    are color 21 and change them to color 51. If there are no circles color 21
    I'd like the routine to end.
     
    Alan Henderson @ A'cad Solutions, Jan 19, 2005
    #3
  4. Ryan Kiss

    Ryan Kiss Guest

    Thanks Alan. That's exactly how I started and it worked great as long as those color 21circles existed. I got into problems with what to do with it if the selection set returned nil.
     
    Ryan Kiss, Jan 19, 2005
    #4
  5. (setq SS (ssget "X" (list (cons 0 "CIRCLE") (cons 62 "21"))))
    (if SS
    (command "_CHPROP" SS "" "C" "51" "")
    (princ "\nNo Color 21 Circles in Drawing.")
    )

    those color 21circles existed. I got into problems with what to do with it
    if the selection set returned nil.
     
    Alan Henderson @ A'cad Solutions, Jan 19, 2005
    #5
  6. Ryan Kiss

    Adesu Guest

    Hi Ryan Kiss,try my script

    ; ecc is stand for edit color circle
    ; Design by Ade Suharna <>
    ; 20 January 2005
    ; program no. 168/01/2005
    ; edit by
    (defun c:ecc (/ css ss idx cnt opt e en ed)
    (while
    (setq css (fix (getreal "\nENTER COLOR CHOOSE: ")))
    (setq ss (ssget "X" (list '(0 . "CIRCLE")(cons 62 css))))
    (setq idx 0)
    (setq cnt 0)
    (setq n (sslength ss))
    (setq opt (fix (getreal "\nENTER NEW COLOR: ")))
    (repeat n
    (setq e (ssname ss cnt))
    (setq en (entget e))
    (setq ed (subst (cons 62 opt)(assoc 62 en) en))
    (entmod ed)
    (setq cnt (1+ cnt )))
    )
    (princ)
    )


    are color 21 and change them to color 51. If there are no circles color 21
    I'd like the routine to end.
     
    Adesu, Jan 20, 2005
    #6
  7. Ryan Kiss

    Jürg Menzi Guest

    Hi Adesu

    To avoid user errors use:
    Code:
    ; ecc is stand for edit color circle
    ;       Design by Ade Suharna <>
    ;       20 January 2005
    ;       program no. 168/01/2005
    ;       edit by
    (defun c:ecc ( / css ss ExLoop GoLoop cnt opt e en ed)
    (while (not ExLoop)
    (initget 4)
    (cond
    ((not (setq css (getint "\nENTER COLOR CHOOSE: ")))
    (setq ExLoop T)
    )
    ((not (and (> css 0) (< css 256)))
    (princ "Invalid color number - requires a value between 1 and 255.")
    )
    ((not (setq ss (ssget "X" (list '(0 . "CIRCLE") (cons 62 css)))))
    (princ "\nNo matching objects found.")
    (setq ExLoop T)
    )
    (T
    (setq GoLoop T)
    (while GoLoop
    (initget 4)
    (cond
    ((not (setq opt (getint "\nENTER NEW COLOR: ")))
    (setq GoLoop nil)
    )
    ((not (and (> opt 0) (< opt 256)))
    (princ "Invalid color number - requires a value between 1 and 255.")
    )
    (T
    (setq cnt 0)
    (repeat (sslength ss)
    (setq e   (ssname ss cnt)
    en  (entget e)
    ed  (subst (cons 62 opt) (assoc 62 en) en)
    cnt (1+ cnt)
    )
    (entmod ed)
    )
    (setq GoLoop nil)
    )
    )
    )
    )
    )
    )
    (princ)
    )
    [code]
    
    Cheers
     
    Jürg Menzi, Jan 20, 2005
    #7
  8. Yet another approach:

    ;; loops through a selection set and applies fun to each VLA-Object
    (defun ssObjApply (fun ss / i e)
    (setq i -1)
    (if (= 'PICKSET (type ss))
    (while (setq e (ssname ss (setq i (1+ i))))
    (apply fun (list (vlax-ename->vla-object e)))
    )
    )
    )

    (defun c:Fixem ()
    (ssObjApply
    '(lambda (CircleObj)
    (vla-put-color CircleObj 51)
    )
    (ssget "x" '((0 . "circle")(62 . 21)))
    )
    (princ)
    )

    Matt

     
    Matt Stachoni, Jan 20, 2005
    #8
  9. Ryan Kiss

    Adesu Guest

    Hi Jürg,thanks a lot for your correction,this's good input for me.
     
    Adesu, Jan 24, 2005
    #9
  10. Ryan Kiss

    Jürg Menzi Guest

    Hi Adesu

    Glad to help you...¦-)

    Cheers
     
    Jürg Menzi, Jan 24, 2005
    #10
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.