Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Automated Color Changes?

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
johnfischerLSI
599 Views, 7 Replies

Automated Color Changes?

Hoping to get some ideas here! My company just switched sheet lasers, and the new machine doesn't read DWG color data (for determining laser power) the same as the old one. What I'm hoping to do is create a batch process to modify all the old files into compatible ones. Essentially, here are the steps I'm hoping to automate:

 

- Open DWG

- Explode block (there's just one in each drawing)

- QSELECT all RED lines

- Change property to WHITE

- QSELECT all GREEN lines

- Change property to YELLOW

- SAVE

 

So far I've looked at BatchInEditor, but that doesn't quite seem to have the correct commands. I'm guessing this is a good situation for a custom LISP, but I don't have any experience writing those. I greatly appreciate any insights. Thanks!

 

(Attached sample files for reference)

7 REPLIES 7
Message 2 of 8

(defun C:RWGY () ; = Red to White, Green to Yellow

  (command

    "_.explode" (entlast)

    "_.chprop" (ssget "_X" '((62 . 1))) "" "_color" 7 ""

    "_.chprop" (ssget "_X" '((62 . 3))) "" "_color" 2 ""

  )

  (prin1)

)

Kent Cooper, AIA
Message 3 of 8

Wow, that was quick! I'm pretty new to using these sorts of commands, how do I enter this in, exactly? Do I need to add this to the body of a new LISP command?

Message 4 of 8

Save it from a plain-text editor such as Notepad to a file with a .lsp filetype ending [call it whatever you want as a file name otherwise].  In AutoCAD, use APPLOAD to load it, and type the command name RWGY [always the part immediately following the C:, and you can change that to anything you prefer] to use it.  If you want to try it first, you can just paste the code into AutoCAD at the command line, hit Enter if it ends at a ), and then type the command name.

 

There's a way to have it loaded automatically into every drawing you create or open, if it's something you would use often enough to want that.  If you have other things defined into a file of such things that you load, it can be added into that instead of having its own separate file.

Kent Cooper, AIA
Message 5 of 8

Going back to @Kent1Cooper 's proposal and you want to do a batch process on a folder, try this

For security purposes:
You open a single Autocad session (a new drawing, no other drawings open)
You copy-paste the given code directly into the command line.
You choose the folder where all the drawings to be processed are contained.
And there you should have a command window which will run AcCoreConsole on each of your files.

 

((lambda ( / f_exe ShlObj Folder FldObj Out_Fld file_scr file_bat)
  (vl-load-com)
  (setq f_exe (findfile "accoreconsole.exe"))
  (setq
    ShlObj (vla-getinterfaceobject (vlax-get-acad-object) "Shell.Application")
    Folder (vlax-invoke-method ShlObj 'BrowseForFolder 0 "" 0)
  )
  (vlax-release-object ShlObj)
  (if Folder
    (progn
      (setq
        FldObj (vlax-get-property Folder 'Self)
        Out_Fld (vlax-get-property FldObj 'Path)
      )
      (vlax-release-object Folder)
      (vlax-release-object FldObj)
    )
  )
  (setq file_scr (open (strcat (getvar "ROAMABLEROOTPREFIX") "support\\update.scr") "w"))
  (write-line "((lambda ( / ss n)" file_scr)
  (write-line " (setq ss (ssget \"_X\" '((0 . \"INSERT\") (2 . \"`*U*\"))))" file_scr)
  (write-line " (if ss" file_scr)
  (write-line "   (repeat (setq n (sslength ss))" file_scr)
  (write-line "     (command \"_.explode\" (ssname ss (setq n (1- n))))" file_scr)
  (write-line "   )" file_scr)
  (write-line " )" file_scr)
  (write-line " (setq ss (ssget \"_X\" '((62 . 1))))" file_scr)
  (write-line " (if ss (command \"_.chprop\" ss \"\" \"_color\" 7 \"\"))" file_scr)
  (write-line " (setq ss (ssget \"_X\" '((62 . 3))))" file_scr)
  (write-line " (if ss (command \"_.chprop\" ss \"\" \"_color\" 2 \"\"))" file_scr)
  (write-line "))" file_scr)
  (write-line "(command \"_.audit\" \"_Yes\")" file_scr)
  (write-line "(command \"_.-purge\" \"_Regapps\" \"*\" \"_No\")" file_scr)
  (write-line "(command \"_.-purge\" \"_All\" \"*\" \"_No\")" file_scr)
  (write-line "(command \"_.saveas\" \"_LT2013\" \"\" \"_Yes\")" file_scr)
  (close file_scr)
  (setq file_bat (open (strcat (getvar "ROAMABLEROOTPREFIX") "support\\update.bat") "w"))
  (write-line (eval (read "(strcat \"set accoreexe=\" \"\\\"\" f_exe \"\\\"\")")) file_bat)
  (write-line (eval (read "(strcat \"set source=\" \"\\\"\" Out_Fld \"\\\"\")")) file_bat)
  (write-line (eval (read "(strcat \"set script=\" \"\\\"\" (getvar \"ROAMABLEROOTPREFIX\") \"support\\\\update.scr\" \"\\\"\")")) file_bat)
  (write-line "FOR /f \"delims=\" %%f IN ('dir /b \"%source%\\\*.dwg\"') DO %accoreexe% /i \"%source%\\%%f\" /s %script%" file_bat)
  (close file_bat)
  (startapp (strcat (getvar "ROAMABLEROOTPREFIX") "support\\update.bat"))
  (princ"\Job finished")
  (prin1)
))
Message 6 of 8

hey,

is there a necessity to explode a block?

Message 7 of 8
Kent1Cooper
in reply to: komondormrex


@komondormrex wrote:

.... is there a necessity to explode a block?


They would need to answer that, but some thoughts:

 

It's certainly a lot easier to change the colors working with top-level objects rather than nested ones, so Exploding simplifies things considerably.  But with more complex code it could be done inside the Block definition.

 

Since in their case, as described, there's only the one Block in a drawing, it reduces the file size to Explode it, if it is also then Purged from the drawing.  It takes less memory to store the information about the pieces on their own than to store all of that and the definition of it all into a Block and the information about the Insertion of that Block.

Kent Cooper, AIA
Message 8 of 8

This worked like a charm! Thank you so much for your help!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Autodesk Design & Make Report