Go Back   Cadalyst Discussion Forums > Forums > Hot Tip Harry: AutoCAD Customization
FAQ Members List Social Groups Calendar Search Today's Posts Mark Forums Read

Notices

Hot Tip Harry: AutoCAD Customization Cadalyst's popular Hot Tip Harry and his entourage are here to assist you with AutoCAD customization. Request help with a programming problem, locate a needed routine, or just keep up with Harry's latest activities. You'll find Harry's archive of AutoLISP and VBA code and hatch patterns at www.cadalyst.com/cadtips. Moderated by R.K. McSwain.

 
 
Thread Tools Display Modes
  #1  
Old 03-06-2008, 07:32 PM
Jordan Wies Jordan Wies is offline
Senior Member
 
Join Date: May 2007
Posts: 359
Default Massive layer re-naming program

Ok, not that massive, we have about 12,000 drawings and 98 layer names. I'm working on a new layer name standard that will carry us away from the old, less descriptive names. With a batch file and lisp routine I am planning on updating and swapping all layer names in the 12,000 drawings to the new names I create. (whoo hoo).

So, I know I can do this with TBLSEARCH, a couple hundred variables, and alot of typing.. but I would like to think there is an easier way without getting TOO involved. Ideally it would be a list of the current names and the names to change them to. I couldn't find anything online that fit my needs, surprisingly, since it would seem this type of tool would be widespread... maybe it's not that easy?

In laymans terms it would go something like: Open drawing, gather all layer names, change them to the new standard names, purge all, maybe set a couple warnings for certain old things that need to be discarded, and exit.


Anyways, any help is appreciated, as usual.

-J
  #2  
Old 03-06-2008, 09:15 PM
wizman's Avatar
wizman wizman is offline
Senior Member
 
Join Date: Sep 2004
Location: Abu Dhabi / Philippines
Posts: 276
Default

i suggest using the built-in cad standards checker(see tools>cad standards)
  #3  
Old 03-11-2008, 02:41 PM
Harry_Is_Alive's Avatar
Harry_Is_Alive Harry_Is_Alive is offline
Guest
 
Join Date: Jan 2006
Location: Silicon Cornfields, OH
Posts: 277
Default

Quote:
Originally Posted by Jordan Wies
Ok, not that massive, we have about 12,000 drawings and 98 layer names. I'm working on a new layer name standard that will carry us away from the old, less descriptive names. With a batch file and lisp routine I am planning on updating and swapping all layer names in the 12,000 drawings to the new names I create. (whoo hoo).

So, I know I can do this with TBLSEARCH, a couple hundred variables, and alot of typing.. but I would like to think there is an easier way without getting TOO involved. Ideally it would be a list of the current names and the names to change them to. I couldn't find anything online that fit my needs, surprisingly, since it would seem this type of tool would be widespread... maybe it's not that easy?

In laymans terms it would go something like: Open drawing, gather all layer names, change them to the new standard names, purge all, maybe set a couple warnings for certain old things that need to be discarded, and exit.


Anyways, any help is appreciated, as usual.

-J
Actually, it is not as difficult as you might think. The only real hang up is that LISP does not do well going from drawing to drawing unless you script it.

The heart of the code you need is LayerSwap in my examples found at http://www.autocode.com/lisp/autolisp.html

keep on programmin'
Bill Kramer
  #4  
Old 03-11-2008, 09:38 PM
cadmoogle's Avatar
cadmoogle cadmoogle is offline
Senior Member
 
Join Date: Oct 2007
Posts: 456
Default

First here is some reading material...
http://forums.cadalyst.com/showthread.php?t=5792

We already have our standards, but we had a time when we didn't so I had to constantly go back and change layers. So with the help of Carl,CAB,wiz, etc I merged some codes to create the layers I want, then filter and move certain layers with wildcard strings. I do not know how it would work on a batch process but I will be glad to post my final working code so you can see how I have it setup.

I started with this code below 'credited to wizman' and added some of my on desired goals to create the layers prior to running....


Code:
(defun c:test (/    ss        layData    ObjLst
        a_block    a_cntr      cnt_blks    ent_block
        ent_layer   laycolor    layfrom    layfrom2
        layname    layname2    matchlist   myblocks
        vla_a_block
       )
  (vl-load-com)
  (setq matchList '(   ; From -------  To -----
     ; Color
      ("*lot*,*Prop*" "LL" "YELLOW")
      ("*Road*,*Pave*" "EOP" "MAGENTA")
     )
  )
  (command "undo" "begin")
  (foreach layData matchList
    (setq LayFrom  (car LayData)
   LayName  (cadr layData)
   LayColor (last LayData)
    )
    (if (tblsearch "Layer" layName)
      (command "._layer"  "_thaw"    layName "_on"    layName
        "_unlock"  layName    "_set" layName    ""
       )
      (command "._layer" "_make" layName "_color" LayColor layName "")
    )
    (if (setq ss (ssget "_all" (List (cons 8 LayFrom))))
      (progn
 ;;  SS  To list of objects
 (setq objLst (mapcar 'vlax-ename->vla-object
        (mapcar 'cadr (ssnamex ss))
       )
 )
 (foreach Obj objLst
   (vla-put-layer Obj LayName)
 )
      )
    )
  )
  (setq cnt_blks 0)
  (if (setq myblocks (ssget "_all" '((0 . "INSERT"))))
    (progn
      (while (< cnt_blks (sslength myblocks))
 (setq a_block (ssname myblocks cnt_blks))
 (setq
   ent_block (tblobjname
        "BLOCK"
        (cdr (assoc 2 (entget a_block)))
      )
 )
 (setq a_block (entnext ent_block))
 (setq a_cntr 0)
 (while a_block
   (setq ent_layer (cdr (assoc 8 (entget a_block))))
   (foreach x matchlist
     (progn
       (setq LayFrom2 (strcase (car x)))
       (setq LayName2 (strcase (cadr x)))
       (if (wcmatch (strcase ent_layer) Layfrom2)
  (progn
    (setq vla_a_block (vlax-ename->vla-object a_block))
    (vla-put-layer vla_a_block layname2)
  )
       )
     )
   )
   (setq a_block (entnext a_block))
   (setq a_cntr (1+ a_cntr))
 )
     ;(entupd a_block)
 (setq cnt_blks (1+ cnt_blks))
      )
    )
  )
  (command "undo" "end")
  (command "_regenall" )
  (princ)
)
(princ)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
And I added this to the front of the code (I'm not at work right not so the final code is not with me right now...

Code:
(command "._layer"
      "_make"
      "EOP"
      "_color"
      "MAGENTA"
      "EOP"
      "_ltype"
      "CONTINUOUS"
      ""
    )
  )
Anyway's I'll provide the rest if it interest you, or just follow the link I provided to see what was going on.

-Daniel
  #5  
Old 03-17-2008, 06:55 PM
Jordan Wies Jordan Wies is offline
Senior Member
 
Join Date: May 2007
Posts: 359
Default Layer Changing For Standards

Quote:
Originally Posted by cadmoogle
First here is some reading material...
http://forums.cadalyst.com/showthread.php?t=5792

We already have our standards, but we had a time when we didn't so I had to constantly go back and change layers. So with the help of Carl,CAB,wiz, etc I merged some codes to create the layers I want, then filter and move certain layers with wildcard strings. I do not know how it would work on a batch process but I will be glad to post my final working code so you can see how I have it setup.

I started with this code below 'credited to wizman' and added some of my on desired goals to create the layers prior to running....



-Daniel
Right on, thank you, I can start with that. Not sure which is more effective/faster, a script or code, so I'm going to test both.

Thanks again,

-J
  #6  
Old 03-17-2008, 07:00 PM
Jordan Wies Jordan Wies is offline
Senior Member
 
Join Date: May 2007
Posts: 359
Default I figured

Quote:
Originally Posted by Harry_Is_Alive
Actually, it is not as difficult as you might think. The only real hang up is that LISP does not do well going from drawing to drawing unless you script it.

The heart of the code you need is LayerSwap in my examples found at http://www.autocode.com/lisp/autolisp.html

keep on programmin'
Bill Kramer
I somehow knew I wasn't the only one who wanted one of these. Darn, I've been busy trying to perfect 3D modeling in Autocad, and it's amazing how much programming knowledge you can lose after a short time! I'm going to have to go back and re-read books again. ;>

thank you!

-J
  #7  
Old 03-25-2008, 01:03 PM
Nancy_Johnson Nancy_Johnson is offline
Nancy Johnson, Cadalyst
 
Join Date: Feb 2005
Posts: 50
Thumbs up Latest Harry's Code Class Newsletter: Messing with Layer Names

Hi All --

Just want to bring to your attention that the latest edition of Harry's Code Class, a free e-newsletter from Cadalyst, addresses this topic in detail.

Check out "Messing with Layer Names" at http://management.cadalyst.com/cadma...tegoryId=39808.

Subscribe to Cadalyst e-newsletters at http://management.cadalyst.com/cadma...Newsletter.jsp.

Thanks!

Nancy
__________________
Nancy Johnson
Editor-in-Chief
Cadalyst
editors@cadalyst.com
  #8  
Old 03-28-2008, 02:27 AM
Jordan Wies Jordan Wies is offline
Senior Member
 
Join Date: May 2007
Posts: 359
Default I saw that! Awesome!

Quote:
Originally Posted by Nancy_Johnson
Hi All --

Just want to bring to your attention that the latest edition of Harry's Code Class, a free e-newsletter from Cadalyst, addresses this topic in detail.

Check out "Messing with Layer Names" at http://management.cadalyst.com/cadma...tegoryId=39808.

Subscribe to Cadalyst e-newsletters at http://management.cadalyst.com/cadma...Newsletter.jsp.

Thanks!

Nancy
Yes I got that in my Email. Awesome. I used it and it works great (fast too!),


Thanks,

-J
  #9  
Old 03-28-2008, 02:35 AM
Jordan Wies Jordan Wies is offline
Senior Member
 
Join Date: May 2007
Posts: 359
Default adding scripting to open files..

Quote:
Originally Posted by Harry_Is_Alive
Actually, it is not as difficult as you might think. The only real hang up is that LISP does not do well going from drawing to drawing unless you script it.

The heart of the code you need is LayerSwap in my examples found at http://www.autocode.com/lisp/autolisp.html

keep on programmin'
Bill Kramer
Ok, I am going to use the code that you sent out in the newsletter. That one is perfect, now I just wonder how to automatically open all those drawings, or open them one at a time, run the lisp, close them, and if necessary, move them to a different directory?

If only there were a "Drawingnext" command.. haha (or is there??....)

thanks,

-J
  #10  
Old 04-04-2008, 02:02 PM
evjens evjens is offline
Junior Member
 
Join Date: Apr 2008
Posts: 6
Default The article was great...

I read the article and it gave me an idea on how to improve a routine I've been building. What I need however is access to the block table from each of my open drawings.

I tried (vla-get-blocks DWG) but was coming up with errors. The documentation in help is a little light on what the available methods are.

Currently I'm scanning a drawing, grabbing a list of specific blocks, and spitting out a count to an excel document, along with calculations, to come up with a building summary. I have to do this for 4-5 floors, then manually merge the files into one. This has already taken a 4-6 hour task and made it take about 15 minutes. This one little tidbit could make it a 30 second task.

Any help available on what vla-get method I need?

Thanks, Shawn

Last edited by evjens; 04-04-2008 at 02:05 PM.
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 12:03 PM.





Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.