Glynn_Seal Posted February 9, 2016 Share Posted February 9, 2016 Hi all, I need a little help. I have a number of drawings that contain various layers named in an old way. I need to merge these old layers into new layers. All to do with old layer names needing to comply with BS1192 layer naming conventions. Here are some examples, in the same file that I would need to merge: Old Layer 1 > New Layer 1 Old Layer 2 > New Layer 2 Old Layer 3 and 4 > New Layer 3 Old Layer 5 (remains as is, no merging required). I can do this (rather tediously) using the LAYMRG command, but I have about 30+ instances in a drawing to do, and I have about 100 drawings to do it in. Ideally, I would like to create a reference table (which I have currently in Excel) that contains what old layer(s) merge with what new layers, and then call this (with a script) inside the drawing file using the SCRIPT command, then select the file. I'm happy to open each drawing and run the script each time rather than batch run the script on multiple files (seems riskier). Can anyone help me work out a script to do this, as I am unfamilar with the scipt syntax (I will need to learn). I did find an old script (possibly 2008, but it won't run because I think the old MergeLayers command is defunct in 2015LT. I tried to substitiute for the LAYMRG command, but with no luck. Any help would be very greatly appreciated, as I'm a script noob Cheers, Glynn Quote Link to comment Share on other sites More sharing options...
RobDraw Posted February 9, 2016 Share Posted February 9, 2016 If LT has it, it can be done with the layer translator. Once you get it set-up, you can then save the translation file and apply it to other drawings. Quote Link to comment Share on other sites More sharing options...
Glynn_Seal Posted February 10, 2016 Author Share Posted February 10, 2016 Thanks RobDraw. LT doesn't have Layer Translator by the looks of it - only applies to AutoCad 2015, not the LT version. https://knowledge.autodesk.com/support/autocad/learn-explore/caas/CloudHelp/cloudhelp/2016/ENU/AutoCAD-Core/files/GUID-597F7140-6BB9-444C-8F14-5E5655556B69-htm.html As a check, I tried it and the LAYTRANS command didn't work :/ Cheers sir, Glynn Quote Link to comment Share on other sites More sharing options...
RobDraw Posted February 10, 2016 Share Posted February 10, 2016 No translator, that sucks. Scripting LAYMRG should be fairly easy. I've never written script but it is based on the command line, so if you walk through the process using the command line version, you should be able figure it out. Use the "name" option and enter the layer names manually. That would be the basis of the script. Copy and paste, do a little formatting, and you should be good to go. Quote Link to comment Share on other sites More sharing options...
Glynn_Seal Posted February 10, 2016 Author Share Posted February 10, 2016 Indeed, I can use the Command Line to copy/paste in the stuff I need. For example: kind of like this... LAYMRG N OLDLayer1 OLDLayer2 OLDLayer3 N NEWLayer1 The probelm I have, is that as soon as the first layer name needs to be selected, a dialog box pops up, and I am unsure of how use keystrokes in the command line to cancel the box, as it does paste it into the command line already. If I could use the SCRIPT command to basically run the same thing, where I can use keystrokes that would be perfect... but I just don't know the scripting syntax well enough. Quote Link to comment Share on other sites More sharing options...
RobDraw Posted February 10, 2016 Share Posted February 10, 2016 Like I said, a little formatting is necessary. I'd have to look up how to do it. You could probably figure it out on your own before I get a chance to look into it. Quote Link to comment Share on other sites More sharing options...
ReMark Posted February 10, 2016 Share Posted February 10, 2016 If you are writing a script wouldn't you have to use the command line version of Layer Merge which would be -LAYMRG thus avoiding the dialog box. Quote Link to comment Share on other sites More sharing options...
RobDraw Posted February 10, 2016 Share Posted February 10, 2016 That would be correct. I didn't realize that mistake because on MEP there isn't a dialog box when using the command without the dash. Can you post a screen shot of the dialog box? Not that it makes any difference for the script, I'm just curious. Quote Link to comment Share on other sites More sharing options...
Glynn_Seal Posted February 10, 2016 Author Share Posted February 10, 2016 Thanks RobDraw and ReMark, response greatly appreciated. Progress is that I can actually use either LAYMRG or -LAYMRG provided the syntax is correct. Doing this (the carriage returns/empty lines are very important) in a script file (.scr), and calling it from SCRIPT in the command line works: -LAYMRG n OLDLayer1 n NEWLayer y -LAYMRG n OLDLayer2 n NEWLayer y -LAYMRG n OLDLayer3 n NEWLayer y -LAYMRG n OLDLayer4 n NEWLayer y The only thing that stuffs it up, is that if any of the OLDLayers don't exist, it breaks the script sequence at that point :/ Quote Link to comment Share on other sites More sharing options...
RobDraw Posted February 10, 2016 Share Posted February 10, 2016 You can create the layers at the beginning of the script. Quote Link to comment Share on other sites More sharing options...
Glynn_Seal Posted February 10, 2016 Author Share Posted February 10, 2016 Ooo, I'll try that... great idea. I was thinking I could just drag all the layers I need in from DesignCenter to the drawing first, but I like this idea better to script it :0) Some layers exist in some files and some dont. I need to ensure that I create all possible layers in the file, but not overwrite any that exist before, and ensure that nothing breaks the script sequence if a layer being created already exists. I'll play, cheers man, Glynn Quote Link to comment Share on other sites More sharing options...
RobDraw Posted February 10, 2016 Share Posted February 10, 2016 The properties of the old layers doesn't matter. They are getting merged to the new layer and taking on the properties of that one. I wonder if you will get an error if you try to create a layer that already exists. Quote Link to comment Share on other sites More sharing options...
Glynn_Seal Posted February 10, 2016 Author Share Posted February 10, 2016 (edited) Okay, gents... this works perfect! Thanks so much for your assistance with this. I have objects on OLDLayer 1, 2 and 3. When I run the script, all the objects are on the NEWLayer. As noted, the blank lines are really important. I have indicated empty carriage return lines (no spaces) with . -LAYER M OLDLayer4 -LAYER M OLDLayer3 -LAYER S 0 -LAYMRG n OLDLayer1 n NEWLayer y -LAYMRG n OLDLayer2 n NEWLayer y -LAYMRG n OLDLayer3 n NEWLayer y -LAYMRG n OLDLayer4 n NEWLayer y All of that is in a Notepad file with a .scr suffix rather than a .txt suffix. I type SCRIPT at the command line, select the .scr file and bingo. Now I just need to correctly populate my .scr file with the actual layer names. AWESOME! Cheers, Glynn Edited February 10, 2016 by Glynn_Seal dyslexia Quote Link to comment Share on other sites More sharing options...
Glynn_Seal Posted February 10, 2016 Author Share Posted February 10, 2016 Just to add, this bit... -LAYER S 0 was added because when a new layer is created, it defaults to current, and you cannot merge a current layer, so I make it 0, as 0 exists in all files Quote Link to comment Share on other sites More sharing options...
RobDraw Posted February 10, 2016 Share Posted February 10, 2016 I knew you could do it. Quote Link to comment Share on other sites More sharing options...
Glynn_Seal Posted February 10, 2016 Author Share Posted February 10, 2016 I knew you could do it. Cheers sir! Quote Link to comment Share on other sites More sharing options...
Glynn_Seal Posted February 10, 2016 Author Share Posted February 10, 2016 One last parting shot for anyone finding this thread later and having the same trouble. I've just created my actual script on a current drawing and it worked flawlessly after the following caveat: Any layers that have spaces in the layer names should be formatted as follows in the script When using -LAYER, layers containing spaces should be enclosed in quotation marks: -LAYER M "OLD Layer 4" When using -LAYMRG, you DO NOT need the quotation marks. -LAYMRG n OLD Layer 1 n NEWLayer Thanks, Glynn Quote Link to comment Share on other sites More sharing options...
YZ Posted February 11, 2016 Share Posted February 11, 2016 The properties of the old layers doesn't matter. They are getting merged to the new layer and taking on the properties of that one. I wonder if you will get an error if you try to create a layer that already exists. To confirm, no, there is no error if an layer already exists that a script is trying to create. Creating them all at the start is the perfect fail safe. Great work Glynn, that is a robust solution. Quote Link to comment Share on other sites More sharing options...
YZ Posted February 11, 2016 Share Posted February 11, 2016 Just to add, this bit... -LAYER S 0 was added because when a new layer is created, it defaults to current, and you cannot merge a current layer, so I make it 0, as 0 exists in all files Also, if you use -LAYER New instead of -LAYER Make The new layer does not default to current. Quote Link to comment Share on other sites More sharing options...
Glynn_Seal Posted February 11, 2016 Author Share Posted February 11, 2016 To confirm, no, there is no error if an layer already exists that a script is trying to create. Creating them all at the start is the perfect fail safe. Great work Glynn, that is a robust solution. Cheers YZ Good advice on the -LAYER New instead of Make. It still needs the "set current to layer 0" line though, just in case the currently selected layer in the file (when you run the script) just happens to be one that needs merging Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.