Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change line colour with simple script

Status
Not open for further replies.

wowski

Electrical
Jan 22, 2001
27
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?
 
Replies continue below

Recommended for you

You should be able to use a script for this. Can use lisp commands within lisp. Within AutoCAD command you can supply entity name for "select objet", and can get entity name with HANDENT function. Example of script to change color, for entity with handle '4C':

change
(handent "4c")

p
c
red
.....etc....

Hope this helps,
Carl
 
First....
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 &quot;chcol&quot;) chcol handle_here color_here

The handle and color must not be a variable in the script.

Cheers......
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor