Change line colour with simple script
Change line colour with simple script
(OP)
I'm new to script programming in AutoCAD, the application I'm trying to write is to use EXCEL to automatically change the colour of lines in an existing AutoCAD drawings. I can write the Excel VB code fine, I just need to know if there is a simple way to change the colour of a line if you know it's AutoCAD handle. i.e. all I really need is can this be done with a simple text script file (like that usually used for slideshows) or will I have to resort to VB?





RE: Change line colour with simple script
change
(handent "4c")
p
c
red
.....etc....
Hope this helps,
Carl
RE: Change line colour with simple script
Paste this code in a plain text file called CHCOL.LSP
;;; begin cut here
(defun C:CHCOL ( / hand newcolor thisobj )
(setq hand (getstring "\nEntity handle: "))
(setq newcolor (getstring "\New entity color: "))
(setq thisobj (entget (handent hand)))
(if (not (assoc 62 thisobj))
(entmod (append thisobj (list (cons 62 (cstoci newcolor)))))
(entmod (subst (cons 62 (cstoci newcolor))(assoc 62 thisobj) thisobj))
)
(entupd (handent hand))
)
(defun cstoci (str)
(setq str (strcase str))
(cond
((= str "RED") 1)
((= str "YELLOW") 2)
((= str "GREEN") 3)
((= str "CYAN") 4)
((= str "BLUE") 5)
((= str "MAGENTA") 6)
((= str "WHITE") 7)
((= str "BYLAYER") 256)
((= str "BYBLOCK") 0)
((= str "BY LAYER") 256)
((= str "BY BLOCK") 0)
((and (< 0 (atoi str)) (> 256 (atoi str))) (atoi str))
(nil))
)
;;; end cut here
Then
In a script file add this line....
replacing the handle and color with those you need....
(load "chcol") chcol handle_here color_here
The handle and color must not be a variable in the script.
Cheers......