TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: andrew_nao on April 18, 2011, 03:42:02 PM

Title: dxf code for changing color
Post by: andrew_nao on April 18, 2011, 03:42:02 PM
something simple i can not for the life of me remember

i want to change the color not the layer
the acad help says 62 but that doesnt work

thanks

 :ugly:
Code: [Select]
 (setq ent (car (entsel "\nSelect a object to be color change")))
  (setq sse (entget ent))
  (entmod (subst (cons 8 "6") (assoc 8 sse) sse))
Title: Re: dxf code for changing color
Post by: alanjt on April 18, 2011, 03:48:53 PM
eg.
Code: [Select]
(defun c:test (/ ent data ass)
  (if (setq ent (car (entsel)))
    (entmod (if (setq ass (assoc 62 (setq data (entget ent))))
              (subst '(62 . 6) ass data)
              (append data '((62 . 6)))
            )
    )
  )
  (princ)
)
Title: Re: dxf code for changing color
Post by: andrew_nao on April 18, 2011, 04:13:34 PM
it is 62?... hmmm

thank sir for your help
Title: Re: dxf code for changing color
Post by: alanjt on April 18, 2011, 04:14:38 PM
it is 62?... hmmm

thank sir for your help
Yes and you're welcome.

see:
http://images.autodesk.com/adsk/files/acad_dxf2.pdf
http://docs.autodesk.com/ACD/2011/ENU/filesDXF/WSfacf1429558a55de185c428100849a0ab7-5f35.htm
Title: Re: dxf code for changing color
Post by: Lee Mac on April 18, 2011, 08:17:07 PM
Weirdly, this seems to work whether DXF 62 is present or not:

Code: [Select]
(if (setq e (car (entsel)))
  (entmod (append (entget e) '((62 . 6))))
)
Title: Re: dxf code for changing color
Post by: alanjt on April 19, 2011, 08:21:04 AM
Weirdly, this seems to work whether DXF 62 is present or not:

Code: [Select]
(if (setq e (car (entsel)))
  (entmod (append (entget e) '((62 . 6))))
)
I was under the impression that only worked on newer versions (can't test since I only have access to 2009 and 2011).
Title: Re: dxf code for changing color
Post by: andrew_nao on April 19, 2011, 11:01:54 AM
is it possible to set a dxf code as a variable?
Title: Re: dxf code for changing color
Post by: Lee Mac on April 19, 2011, 11:06:36 AM
is it possible to set a dxf code as a variable?

Yes, but we must construct the dotted pair using the list/cons functions, since when using the apostrophe expressions are not evaluated:

Code: [Select]
([color=blue]setq [/color]colour 30)
([color=blue]setq [/color]newpair ([color=blue]cons [/color]62 colour))

([color=blue]if [/color]([color=blue]setq [/color]entity ([color=blue]car [/color]([color=blue]entsel[/color])))
  ([color=blue]progn
[/color]    ([color=blue]setq [/color]elist ([color=blue]entget [/color]entity))

    ([color=blue]if [/color]([color=blue]setq [/color]oldpair ([color=blue]assoc [/color]62 elist))
      ([color=blue]setq [/color]elist ([color=blue]subst [/color]newpair oldpair elist))
      ([color=blue]setq [/color]elist ([color=blue]append [/color]elist ([color=blue]list [/color]newpair)))
    )
    ([color=blue]entmod [/color]elist)
  )
)
Title: Re: dxf code for changing color
Post by: andrew_nao on April 19, 2011, 11:51:03 AM
never mind, im a dope

 :ugly:

thanks for youre help Lee.