Jump to content

Layer Translation Mappings


Nenad Mutavdzic

Recommended Posts

I'm working on the translation of a large number of Layers, from existing to new ones, according to exactly defined pattern. And all this for 1,000 drawings.

 

Using command Layer Translator (LAYTRANS), is it possible to export Layer Translation Mappings as xls or txt file? XLS or TXT files are more editable and easier for work.

Also, is it possible to import a Layer Translation Mappings into Auto CAD as xls or txt file?

 

Is there a batch file which can convert layers in large number of drawings at the same time?

 

Thanks

Link to comment
Share on other sites

Yes Yes and YES others will comment re "Laytrans"

 

Yes1

Via lisp you can redefine all layers reading a text file that has all the preset names in it.

old new col LT
AB ABUTMENT              1   Continuous 
ALPL ALUMINIUM PLUG        1   Continuous 
ARR ARROW                 1   Continuous 
BOK BACK OF KERB          252 DASHED  

 

Yes2 1000 files a little bit of work but using a script very doable and you will be surprised how fast.

 

open dwg1 (load "convertlayers") close Y
open dwg2 (load "convertlayers") close Y
open dwg3 (load "convertlayers") close Y
open dwg41 (load "convertlayers") close Y
open dwg51 (load "convertlayers") close Y

 

Yes3 some sample code

(setq xxt 1)
(setq fname (open "P:\\Autodesk\\lisp\\layercodes.txt" "r"))
(while (setq layercode (read-line fname))

(setq  J  22)
(setq ans " ")
(While (= ans " ") 
(setq ans (substr layercode J 1))
(setq j (- j 1))
) ;end while
 
(setq Lname (substr layercode 1 (+ 1 J)))
 
(setq Laycol (atoi (substr layercode 23 3))) ; color is only 1 character

(setq  J  37)
(setq ans " ")
(While (= ans " ") 
(setq ans (substr layercode J 1))
(setq j (- j 1))
) ;end while
(setq j (- (+ j 2) 27))
(setq Laylt (substr layercode 27 J))

(princ xxt)

(vlax-for each layer  
(if (= lname  (vla-get-name each))
   (progn
   (vla-put-linetype each laylt)
   (vla-put-color each laycol)
   (vla-put-name each (strcat "EX_" lname))
   ) ;progn
) ; if

); for

(setq xxt (+ xxt 1))
) ;end file while
(close fname)


(alert "EX added to Layers ")

Link to comment
Share on other sites

Thank you very much for your reply and advice.

Unfortunately, I have not worked lisp programming until now.

I'll have to first learn how to work with them...

Link to comment
Share on other sites

My intention is to to write table Translation Layer Mapping in NotePad, such as:

Old Layer Name New Layer Name Color Linetype Lineweight

H---AP-S H_Geraete 7 Continuous 0,25

H---HK-Z H_Heizkoerper 10 Continuous 0,35

H---VL-Z H_Vorlauf 10 Continuous 0,35

H---RL-Z H_Ruecklauf 160 Continuous 0,35

H---AP-T H_Text-Allgemein 7 Continuous 0,25

In this way I can easily add the new conversions and edit existing ones.

The final table in NotePad I would import somehow in the dwg-file, in other to get layer conversion, from old to new ones ...

Is it possible?

Link to comment
Share on other sites

The code above uses fixed spacing, but you could use a csv file also there is lots of read csv and split into variables such as ReadCSV-V1-3.lsp by Lee-mac

 

H---AP-S H_Geraete 7 Continuous 0.25

H---HK-Z H_Heizkoerper 10 Continuous 0.35

H---VL-Z H_Vorlauf 10 Continuous 0.35

H---RL-Z H_Ruecklauf 160 Continuous 0.35

H---AP-T H_Text-Allgemein 7 Continuous 0.25

Edited by BIGAL
Link to comment
Share on other sites

Try this it seemed to work for me can use excel for layer list easier to make into a csv.

test data

H---AP-S,H_Geraete,7,Continuous,0.25
H---HK-Z,H_Heizkoerper,10,Continuous,0.35
H---VL-Z,H_Vorlauf,10,Continuous,0.35
H---RL-Z,H_Ruecklauf,160,Continuous,0.35	
H---AP-T,H_Text-Allgemein,7,Continuous,0.25

; LAYERS RENAME LT COLOR FROM A CSV FILE
; BY ALAN H
(DEFUN ah:RELAYS ( / layer fname newname laycol lname laylt layltwt Lst str)
(setq layer (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))) ; open database get layers
(setq fname (open "C:\\temp\\test.csv" "r"))
(while (setq str (read-line fname))
(setq lst (cons (LM:csv->lst str "," 0) lst))
(reverse lst)
(setq lst (nth 0 lst))
 
(setq lname (nth 0 lst))
(setq newname (nth 1 lst))
(setq laycol (nth 2 lst))
(setq laylt (nth 3 lst))
(setq layltwt (nth 4 lst))

(vlax-for each layer  
(if (= lname  (vla-get-name each))
   (progn
   (vla-put-linetype each laylt)
   (vla-put-color each laycol)
   (vla-put-name each newname)
   ; (vla-put-lineweight each layltwt); check variable name
   ) ;progn
) ; if
); for
(setq lst nil)
) ;end file while
(close fname)
) ; defun

;; Read CSV  -  Lee Mac
;; Parses a CSV file into a matrix list of cell values.
; Alan H removed open file in this defun and do all in preference to line by line in other defun

;; CSV -> List  -  Lee Mac
;; Parses a line from a CSV file into a list of cell values.
;; str - [str] string read from CSV file
;; sep - [str] CSV separator token
;; pos - [int] initial position index (always zero)

(defun LM:csv->lst ( str sep pos / s )
   (cond
       (   (not (setq pos (vl-string-search sep str pos)))
           (if (wcmatch str "\"*\"")
               (list (LM:csv-replacequotes (substr str 2 (- (strlen str) 2))))
               (list str)
           )
       )
       (   (or (wcmatch (setq s (substr str 1 pos)) "\"*[~\"]")
               (and (wcmatch s "~*[~\"]*") (= 1 (logand 1 pos)))
           )
           (LM:csv->lst str sep (+ pos 2))
       )
       (   (wcmatch s "\"*\"")
           (cons
               (LM:csv-replacequotes (substr str 2 (- pos 2)))
               (LM:csv->lst (substr str (+ pos 2)) sep 0)
           )
       )
       (   (cons s (LM:csv->lst (substr str (+ pos 2)) sep 0)))
   )
)

(defun LM:csv-replacequotes ( str / pos )
   (setq pos 0)
   (while (setq pos (vl-string-search  "\"\"" str pos))
       (setq str (vl-string-subst "\"" "\"\"" str pos)
             pos (1+ pos)
       )
   )
   str
)



(PRINC)

(VL-LOAD-COM)
(AH:RELAYS)

Edited by BIGAL
Link to comment
Share on other sites

Excellent, It works, thank you.

How to multiply it to 1000 files with similar but not the same layers?

 

And a aditional question: What does "r" mean, in the line: (setq fname (open "C:\\temp\\test.csv" "r"))?

Link to comment
Share on other sites

Easy one first "R" is read "w" is write "A" append to file

 

1000 files two parts

If you make a data file with all layer combos possible it will work our data files has around 200+ but a typical dwg is about 100. When I find something that has not worked I add it to the list and run again

Use a script file there are various ways to make a script this depends on how complex your directories are. 1000 maybe do overnight, I would do in batches.

open dwg1 (load "Layers rename") close Y
open dwg2 (load "Layers rename") close Y
open dwg3 (load "Layers rename") close Y
open dwg4 (load "Layers rename") close Y

 

3rd part different csv's modify code to include correct data file

open dwg4 (load "Layers rename")(AH:relays "list1") close Y

Link to comment
Share on other sites

I've already made a CSV file with all possible layer name conversions. There are over 500 conversions.

Lisp RELAYS, you sent me, works when I load it in each of the drawings individually, but it performs the conversion for only the first 4 layers. Other layers remain unchanged.

Regarding the multiplication to 1000 files, one more question:

In the line open dwg1 (load "Layers rename") close Y

dwg1 - should I write the complete path and name of the file?

Once again a big thank you for the effort and good will to give me help.

I have to learn the basics of writing Lisp.

Can you give me a recommendation for some tutortial

Link to comment
Share on other sites

Not sure why it stops after 4 post say 10 lines of csv, can test then

 

Yes dwg1 would be "F:\projects\freds bigshed\dwg1234ba" you may need double backslashes the space in directory names can cause problems.

 

How spread out are the dwg files directory wise if only a few do this.

 

Bottom left windows START cmd this takes you to the windows command prompt say

F:

CD \projects\freds bigshed\

dir *.dwg >dwglst /b

Exit

 

You can open dwglst which is a list of your dwgs use this as a start to make a script. I use Word to edit use search/replace and the ^p is end of line, so ^p replace with ^p open. Try it

Link to comment
Share on other sites

A new problem in Command Prompt:

>C:\TEMP\DWG\dir *.dwg >dwglst /b

' C:\TEMP\DWG\dir' is not recognized as an internal or external command,

operable program or batch file.

 

Long time ago, I learnt DOS, but I forgot everything.

Thanks anyway.

Link to comment
Share on other sites

Lisp RELAYS steel works only for the first 4 layers. Other layers remain unchanged.

Here are the list of 10 layers:

lname newname laycol laylt layltwt

H---AP-T H_Text-Allgemein 1 Continuous 0.25

H---AP-Z H_Geraete 2 Continuous 0.35

H---FBV-Z H_FB-Vorlauf 3 Continuous 0.35

H---HK-Z H_Heizkoerper 4 Continuous 0.35

H---KR-Z K_Kaltwasser Ruecklauf 5 Continuous 0.25

H---KV-Z K_Kaltwasser Vorlauf 6 Continuous 0.25

H---LT-T H_L-T-V 7 Continuous 0.35

H---LT-V H_L-T-V 8 Continuous 0.35

H---RL-Z H_Ruecklauf 9 Continuous 0.35

H---VL-Z H_Vorlauf 10 Continuous 0.25

Link to comment
Share on other sites

DOS go to START then CMD

 

The data has Tabs the program looks for a comma two ways can change lee-mac section to look for a tab or

bring into Word search/replace look for ^t replace with ,

 

H---AP-T,H_Text-Allgemein,1,Continuous,0.25

H---AP-Z,H_Geraete,2,Continuous,0.35

H---FBV-Z,H_FB-Vorlauf,3,Continuous,0.35

H---HK-Z,H_Heizkoerper,4,Continuous,0.35

H---KR-Z,K_Kaltwasser Ruecklauf,5,Continuous,0.25

H---KV-Z,K_Kaltwasser Vorlauf,6,Continuous,0.25

H---LT-T,H_L-T-V,7,Continuous,0.35

H---LT-V,H_L-T-V,8,Continuous,0.35

H---RL-Z,H_Ruecklauf,9,Continuous,0.35

H---VL-Z,H_Vorlauf,10,Continuous,0.25

Link to comment
Share on other sites

I see...

It was part of XLS-file.

In lisp RELAYS I put CSV-file with commas...

 

lname,newname,laycol,laylt,layltwt

H---AP-T,H_Text-Allgemein,1,Continuous,0.25

H---AP-Z,H_Geraete,2,Continuous,0.35

H---FBV-Z,H_FB-Vorlauf,3,Continuous,0.35

H---HK-Z,H_Heizkoerper,4,Continuous,0.35

H---KR-Z,K_Kaltwasser Ruecklauf,5,Continuous,0.25

H---KV-Z,K_Kaltwasser Vorlauf,6,Continuous,0.25

H---LT-T,H_L-T-V,7,Continuous,0.35

H---LT-V,H_L-T-V,8,Continuous,0.35

H---RL-Z,H_Ruecklauf,9,Continuous,0.35

H---VL-Z,H_Vorlauf,10,Continuous,0.25

 

But, It still works only for the first 4 layers...

I am making mistake somewhere...but it doesn't matter.

 

Thank you very much

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...