Jump to content

Need a TXT File Based Layer Translator


wojocad

Recommended Posts

Prior to Acad2002 (I think), LAYTRANS.ARX used simple TXT files to record sets of layer translations done within the routine. This allowed you to manually add or revise standard layer names / colors etc… in various “Rosetta Stone” TXT files using Notepad. You could then translate any of the old layer names in a drawing that appeared in the list of translations in the TXT you selected to the whatever standard you bothered to set up… REAL HANDY! I used to have a UPDATE LAYERNAMES button in my Customization that launched the routine and called up the office standard.

 

After 2004, AutoDesk complicated the whole scenario by tying their revised version of LAYTRANS.ARX to their new-fangled DWS format (pretty useless in my opinion). In Acad2002, I was able to rename my old version of LAYTRANS.ARX to TRANSLAY.ARX and appload it manually. It would boot out the newer version and function the same way as the old. In Acad2004, I think they changed ARX formatting somehow and one of my favorite tools went by the wayside (typical AutoDesk progress). I’ve tried asking (in lots of Cad Forums) who wrote the original LAYTRANS code to see if I could get AutoDesk to supply me with a newly recompiled version that works the old way… No luck.

 

Does anyone have or know of a Layer Translator routine that works something like the old LAYTRANS? It seems like a fairly simple thing to accomplish, but I don’t know how to write such a routine. I do consulting work for a lot of different firms and they all have their own methods and layer standards. I need my old LAYTRANS. Any help?

Link to comment
Share on other sites

  • Replies 23
  • Created
  • Last Reply

Top Posters In This Topic

  • irneb

    6

  • yui009

    5

  • wojocad

    4

  • ReMark

    3

Top Posters In This Topic

So you are saying that when one uses the LAYTRANS command in AutoCAD 2004 on up to and including 2011 it is not the same command it was prior to 2002?

 

For you who are unfamiliar with Layer Translator here is a good explanation of it's use from none other than the author of Michael's Corner here at CADTutor than Michael Beall himself.

 

http://autodesk.blogs.com/between_the_lines/2009/01/autocad-layer-translator.html

Link to comment
Share on other sites

Correct... They didn't have LAYTRANS connected to the DWS Drawing Standards thingy before 2002. The old dialog box had the option to write the translations to a text file that you could name anything you wanted and then call up again to run it again later. You didn't need to load a drawing to the second window. The current routine has the option to write new translations you create to a log file, but there's no place in the current Laytrans Dialog Box to recall a log file and reuse it... which begs the question... What the hell good is the Log file?

 

In Acad2002, ARX formating was still the same as when that Express Tool was originally written and compiled, so I was able to rename the ARX file to something new and then appload it over the newer version that was already loaded by the 2002 version of the Express Tools. When I went up to the Express Tools pulldown, it called up the old routine and dialog box which still worked. When I tried doing the same thing in Acad2004 and beyond, it wouldn't load, which tells me they changed something in the ARX code format... Just a guess.

Edited by wojocad
typo
Link to comment
Share on other sites

... When I tried doing the same thing in Acad2004 and beyond, it wouldn't load, which tells me they changed something in the ARX code format... Just a guess.
Good guess. Usually an ARX file is compiled using a set of libraries. Parts of these libraries (called a SDK, System Development Kit) then get included inside the ARX file. The thing is about each 2nd / 3rd version of ACad the SDK is overhauled - thus an ARX compiled with 2008's SDK may still work on 2009, but you can be 99.99999...% sure it's not going to run on 2011.

 

Re-doing the Layer Translator may be a bit of a long process. If you can find the source code, it would be possible to compile it using the newer ACad's SDK - thus enabling it to work on the new AC. But I don't think ADesk is going to give anyone the source for free ... or even a "modest" amount. It would be nice if they would open-source the Express Tools ARX's as "obsolete" source, but I wouldn't hold my breath.

Link to comment
Share on other sites

Why not just write a script

 

rename L oldlay1 newlay1 layer C 4 L dashed

rename L oldlay2 newlay2 layer C 5 L dashed

 

You could save it as a txt file or as an excel file ? It seems to me to write a program would take a lot longer than a scr file cut and paste

 

Rereading your post if you have the txt file already your 1/2 way there. bring it into excel add the correct columns required and then just save as a scr

Link to comment
Share on other sites

Why not just write a script

 

rename L oldlay1 newlay1 layer C 4 L dashed

rename L oldlay2 newlay2 layer C 5 L dashed

 

You could save it as a txt file or as an excel file ? It seems to me to write a program would take a lot longer than a scr file cut and paste

 

Rereading your post if you have the txt file already your 1/2 way there. bring it into excel add the correct columns required and then just save as a scr

What would happen in the "oldlayer" doesn't exist in the drawing? The rename would fail, as would the layer colour & linetype setting. Would the rest of the SCR continue?

 

With the program it should check if the oldlayer exists, and only if so perform the change. Also if there are 2 (or more) oldlayer names which should be translated into one new layer - you would need to use the LayMrg command on the 2nd and following layers found in the DWG. That is the main working portion of the layer translator, but most of its coding is actually the displaying of information in those dialog boxes.

Link to comment
Share on other sites

I think Irneb is right... Scripts stall when they can't find something... which is why the old routine worked so well. It would somehow check a drawings existing layer set against the lines of translations listed in the Rosetta Stone text. It would then make the translations found and finish with only the oddball layer names in the left window for you to deal with manually.

 

There was also a routine called SCRIPTPRO which you could use to apply scripts to lists of drawings. They may still have that one around. Haven't used it in years. I had a script that would open a drawing... launch the old command line version of -LAYTRANS... tell it to use the office Rosetta Stone TXT... save and close the drawing and then ScriptPro would move on to the next drawing. I remember converting the layer sets on 1,500 drawings in a standard detail library while I did my laundry one day.

 

If you use the current LAYTRANS, there is an option to have it make a log file... which looks similar to what the old TXT file looked like. Too bad it's useless!

Link to comment
Share on other sites

What your trying to do is not very hard and theres lots of examples here about reading layer tables, checking for existing layers and read a text file, if exists then rename.

 

A script would open multiple dwgs and run the lisp

 

open dwg1 (load "mytrans") save Y close

open dwg2 (load "mytrans") save Y close

 

I have written something similar so post your txt file so people here may be able to put something together for you.

Link to comment
Share on other sites

It's been about eight years since they changed Laytrans... so I'll need to dig around to see if I can find one of my old Rosetta Stone files on a CD somewhere. I appreciate it, and will get back to you soon.

Link to comment
Share on other sites

  • 1 month later...

hi, it's first time to post i hope it is right place.

 

i need to do (may be 'laytrans') for 200-300 construction documents made by more than 10 different architects. files need to be converted into one layer system for collective plan in order to let 'study office' handle information efficiently.

 

only way i could imagine doing it are:

1. make main file insert all xrefs and bring all layer setting in laytrans

2. create dws file conversion table out of 'all' vs 'new'

3. find batch processing method to run 'laytrans' with .dws file created by step 2.

as number of layers are over 1000-1500, i wonder if this works. any advices will be great.

Link to comment
Share on other sites

Once you make your new dws your half way there, I could not get the laytrans to run without popping the dialouge box tried - _ . etc File dia 0 some commands are like this. Maybe some one can help need to enter alt+L (keycode) which is "load" then filename and other required keycodes to continue ?

 

Doing a script is the easy part to open all the drawings etc.

Link to comment
Share on other sites

thank you BIGAL and irneb.

 

it sounds there are no way to simply batch process by selecting folder contains all dwg files with one laytrans setting?

is there anyone who did similar thing before?

Link to comment
Share on other sites

What about something like this? Untested:

(vl-load-com)
;; Function to read target layers from a DWG/DWT/DWS file
(defun ReadLayerFile (filename / *error* lst odbx acVer lay)
 (defun *error* (msg)
   (if odbx
     (vl-catch-all-apply 'vlax-release-object '(odbx))
   )
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (and msg (princ (strcat "\n** Error: " msg " **")))
       (princ)
   )
 )
 (if (and (setq odbx (vla-GetInterfaceObject
                       (vlax-get-acad-object)
                       (if (< (setq acVer (atoi (getvar "ACADVER"))) 16)
                         "ObjectDBX.AxDbDocument"
                         (strcat "ObjectDBX.AxDbDocument." (itoa acVer))
                       )
                     )
          )
          (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-open (list odbx filename))))
     )
   (progn
     (vlax-for lay (vla-get-Layers odbx)
       (setq lst (cons (list (strcase (vla-get-Name lay))
                             (vla-get-Color lay)
                             (vla-get-LineType lay)
                             (vla-get-LineWeight lay)
                             (vla-get-Description lay)
                       )
                       lst
                 )
       )
     )
     (vla-Close odbx)
   )
 )
 (*error* nil)
 lst
)

;; Function to read layer translation file
;; The file's structure should be:
;; OldLayerName<TAB>NewLayerName<NewLine>
(defun ReadLayerTrans (filename / f str split lst)
 (if (setq f (open filename "r"))
   (progn
     (while (setq str (read-line f))
       (if (setq split (vl-string-search "\t" str))
         (setq lst (cons (cons (strcase (substr str 1 split)) (substr str (1+ split))) lst))
       )
     )
     (close f)
   )
 )
 lst
)

;; Function to ensure a layer exists & optionally set its properties (if list)
(defun LayerEnsure (lay / name item)
 (or *layers* (setq *layers* (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object)))))
 (setq name (if (= (type lay) 'LIST) (car lay) lay))
 (if (not (setq item (vla-Item *layers* name)))
   (setq item (vla-Add *layers* name))
 )
 (if (= (type lay) 'LIST)
   (progn
     (vla-put-Color item (cadr lay))
     (vla-put-LineType item (caddr lay))
     (vla-put-LineWeight item (cadddr lay))
     (vla-get-Description item (last lay))
   )
 )
)

;; Function to rename / merge a layer into another
(defun LayerMerge (old new / lay name)
 (or *layers* (setq *layers* (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object)))))
 (if (tblsearch "LAYER" old)
   (progn
     (setq name (if (= (type new) 'LIST) (car new) new))
     (if (tblsearch "LAYER" name)
       (vl-cmdf "._LAYMRG" "_Name" old "" "_Name" "_Yes")
       (progn
         (setq lay (vla-Item *layers* old))
         (vla-put-Name lay name)
       )
     )
   )
 )
 (LayerEnsure new)
)

;; Command to translate layers
(defun c:LayTrans2 (/ fn tLst sLst lay props lst tran new notFound err)
 (if (and (setq fn (getstring "\nWhat standard's file do you want to use? "))
          (setq fn (findfile fn))
          (setq sLst (ReadLayerFile fn))
          (setq fn (getstring "\nWhat translation file do you want to use? "))
          (setq fn (findfile fn))
          (setq tLst (ReadLayerTrans fn))
          )
   (progn
     (initget "Yes No")
     (if (setq props (getkword "\nDo you want to set the properties as well? [Yes/No] <No>: "))
       (setq props (eq props "Yes"))
     )
     (setq lay (tblnext "LAYER" t))
     (while lay
       (setq lst (cons (strcase (cdr (assoc 2 lsy))) lst))
       (setq lay (tblnext "LAYER"))
     )
     (foreach lay lst
       (if (and (setq new (assoc lay sLst)) props) (LayerEnsure new)
         (if (setq tran (assoc lay tLst))
           (if (setq new (assoc (cdr tran) sLst))
             (LayerMerge lay (if props new (car new)))
           )
           (setq notFound (cons lay notFound))
           (setq err (cons tran err))
         )
       )
     )
     (if notFound
       (progn
         (setq new (open (strcat (getvar "DWGNAME") "-Unfound Layers.TXT") "w"))
         (foreach lay notFound
           (write-line lay new)
         )
         (close new)
       )
     )
     (if err
       (progn
         (setq new (open (strcat (getvar "DWGNAME") "-Error Translated Layers.TXT") "w"))
         (foreach lay err
           (write-line (strcat (car lay) "\t" (cdr lay)) new)
         )
         (close new)
       )
     )
   )
 )
 (princ)
)

The idea is to perform LayTrans from command-line switches - so you can run it from a script. It "should" read the standard layers from any DWT/DWG/DWS file. Then it uses a text file to store which layers should be renamed / merged into which standard layer. If a new layer is found it's saved to a text file named as the DWG you're editing + "-Unfound Layers.TXT". If there's an error in the translation file this is saved to another TXT file named as the current DWG + "-Error Translated Layers.TXT".

 

So from there you should be able to generate the translation file pretty easily through NotePad. It's simply a text file with the incorrect layer's name, a tab, then the correct layer's name, one line per translation. Note all the layer names in this file need to be upper case at present (I'm not sure how to handle it otherwise).

Link to comment
Share on other sites

hi, irneb

 

first i tried by saving your code in .vlx and load in autocad.

replaced 'filename' in code to saved .dws file. but did not work.

 

second saving your code in .scr and load in autoscript.

it started process but never ended. so i assume i did not do what you have intended.

could you let me know step by step?

Link to comment
Share on other sites

Sorry yes ... if you save it to VLX (I'm assuming you do so through compiling it in VLIDE), make sure you don't use any extra optimizations - the lisp isn't written for separate namespaces as FAS/VLX does when you set the optimizations too high. I tend to only compile to FAS/VLX once I know the LSP file is working - it's a lot simpler to modify and reload (once click) instead of modify, compile again (multiple clicks) and then reload (switch to ACad window and type (load ....)).

 

Second: It might not have ended if there was an error. Perhaps the VLX file could not be found in the support paths. Could you post the command log which AutoScript should be able to create for you? From there I might be able to tell where the hang happens.

 

Remember, the code as per my previous post includes comments: everything after a semi-colon ";" on each line, e.g.

;; Command to translate layers

These only work inside LSP files. The SCR is a literal key-press file ... as if that is what you yourself would type into the command-line. Thus if you want to simply place the code into the SCR remove any comments not inside a "(" .... ")" combination - otherwise you'll find some weird unknown command complaints happening.

 

My code should run without changing anything the 1st time ... unless you've created the translation already. After the 1st run you should have a file inside the same folder as the DWG with the same name as the DWG, but a suffix of -Unfound Layers.TXT. Open this file in Notepad, copy the layers you want translated to the Text file you're using to store all the translations. On each line at the end add a TAB and the name of the layer it should be translated to. Unfortunately I haven't made something as "user friendly" as the normal Standards Checker ... I was more interested in making something which could run for multiple files without any user intervention.

Link to comment
Share on other sites

replaced 'filename' in code to saved .dws file. but did not work.
No! You don't need to modify the code thus, the command asks you to input the filename - this so it can run in any instance. I'll try and make a video screen capture for you so you can see what I mean ... might take a while though, since I'm a bit busy at present :o.
Link to comment
Share on other sites

hi, irneb

 

thank you for response! are you friend of od1? he pointed out that you may be a person wih whom he worked. as i had communication with him by normal mail.

1.

i tried from scratch, i saved code from your post and created .lsp file. yet still not working,,, after i have noticed that after defun 'c:' were missing in few places. i don't know if it was intentional or not, but i have given 'c:' after each DEFUN line.

after giving 'c:' lisp was recognized in autocad, however, received message

'Command: readlayerfile
; error: too few arguments. 

2.

i tried to get log file you mentioned above, but as command goes on without end, it seems that log is repetition of one line.

Script file: C:\Users\User\Desktop\ReadLayerFile.scr
U:\xxx\07_DESSINS\DWG\Xref\Logement_DCE\xx\xx_xxx_R1_110202.dwg----------
Command "SCRIPT" done.

 

i found idea is great and it will definitely help what i need to do. so i am still willing to do all necessary process to make this happen.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...