×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Change line colour with simple script

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

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

RE: Change line colour with simple script

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 "chcol") chcol handle_here color_here

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

Cheers......

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources