Author Topic: dxf code for changing color  (Read 5270 times)

0 Members and 1 Guest are viewing this topic.

andrew_nao

  • Guest
dxf code for changing color
« 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))

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: dxf code for changing color
« Reply #1 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)
)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

andrew_nao

  • Guest
Re: dxf code for changing color
« Reply #2 on: April 18, 2011, 04:13:34 PM »
it is 62?... hmmm

thank sir for your help

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: dxf code for changing color
« Reply #4 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))))
)

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: dxf code for changing color
« Reply #5 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).
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

andrew_nao

  • Guest
Re: dxf code for changing color
« Reply #6 on: April 19, 2011, 11:01:54 AM »
is it possible to set a dxf code as a variable?

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: dxf code for changing color
« Reply #7 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)
  )
)
« Last Edit: April 19, 2011, 11:15:16 AM by Lee Mac »

andrew_nao

  • Guest
Re: dxf code for changing color
« Reply #8 on: April 19, 2011, 11:51:03 AM »
never mind, im a dope

 :ugly:

thanks for youre help Lee.