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

Paste Xref into new dwg and maintain layer status possible?

14 REPLIES 14
SOLVED
Reply
Message 1 of 15
econnerly
10213 Views, 14 Replies

Paste Xref into new dwg and maintain layer status possible?

Looking some something that will allow me to copy an xref from one drawing and paste it into another drawing while keeping the layer status from the drawing that it was copied from. When I copy and paste the an Xref into a new drawing; it converts back to the layer state that exist in the actual xref drawing itself. It would be nice if we could copy select layers from the layer dialog box and paste them back into another drawing and have them overwrite if the layer already exist. I have used layer states but it gets a little time consuming when working with drawings with over 400 layers.

I have used layer states but they are a little time consuming for me. Maybe someone knows a trick to accomplish what I am looking for.
14 REPLIES 14
Message 2 of 15
hencoop
in reply to: econnerly

I have a lisp routine that I use for the purpose.  It will record all of the layer settings to include color, linetype, off, frozen, and vplayer frozen status, in a folder named "Layer Saves" and a text file with the name of the drawing+layout+viewport number and extension .xrl (it is still just a text file).  It does not record whether the layer is a non-plot-layer or not because I don't use that feature.  I suppose it could be made to w/o much trouble.

 

Since AutoCAD's viewport numbering is not constant from session to session the viewport numbering is accomplished using a layer naming scheme for viewports.  The routine offers to change the viewport to the layer number you specify if it doesn't already match the layer scheme but it is not required.  It will still use the number you specify in the name of the text file.

 

The command XRLAYERS saves the data and the command RXRLAY restores the current viewport layer settings to those in the file you select (or you may use the last XRLAYERS data which is in memory - this requires SDI=1 between drawings for the data in memory to be preserved).

 

The primary lisp file is XRLAYERS.LSP

It has some required subroutines which will automatically be loaded if they are found in your "AutoCAD Support File Search Path".

They are:

gvpno.lsp, uint.lsp, chkkwds.lsp, ukword.lsp, ustr.lsp, check_for_doslib.lsp, set_mjrg.lsp

I've put these in a single file (attached) because of the attachment limit.  It can either be loaded manually in AutoCAD or if the functions are separated into files of the same names (function name = filename.lsp), they will be autoloaded by XRLAYERS if they are found in your "AutoCAD Support File Search Path".

 

This application also requires DOSLIB by Robert McNeel & Associates.  Free to download here:
              "http://www.mcneel.com/"

 

DOSLib, is a library of AutoLISP-callable functions that provides a variety of Windows operating system capabilities to AutoCAD. It is written as an AutoCAD ObjectARX application.  My function "check_for_doslib" will autoload it if it is found in your "AutoCAD Support File Search Path".

I wrote the first version of this in 1999.  I last edited it in 2008 (as best I remember).  It was necessary to avoid the time consuming messes made by some entry level CAD technicians (and less frequently, by more experienced ones, including myself).  It eliminated any problem posed by changing layer settings in a sheet as they could be instantly restored even if the drawing layer state information had been damaged.

 

P.S. I had to rename the attachments giving them a .txt extension as this forum said: Error! the contents of the attachments do not match their file type.  You will need to rename them with .lsp extensions

AutoCAD User since 1989. Civil Engineering Professional since 1983
Product Ver.: 13.6.1781.0 Civil 3D 2024.3 Update
Built On:        U.152.0.0 AutoCAD 2024.1.2
                        27.0.37.14 Autodesk AutoCAD Map 3D 2024.0.1
                        8.6.52.0 AutoCAD Architecture 2024
Message 3 of 15
econnerly
in reply to: hencoop

All I can say is wow. This looks amazing. Im going to see how it goes when I get back to the office.

Message 4 of 15
econnerly
in reply to: hencoop

Hencoop,

This routine is amazing and will be used everyday! Thanks a million. Just a few questions on it if you dont mind?

Enter layer name prefix to filter for How is this to be used? Does this option filter OUT layers that you dont want to be updated?

I see that Enter layer name to isolate operation to  will allow me to filter just layers that I would like to use.

 

Also how am I to use IMPORTXRL to be used?

Tags (1)
Message 5 of 15
hencoop
in reply to: econnerly

The query "Enter layer name prefix to filter" should be "Enter layer xref name prefix to filter" (do not include the vertical bar "|")  I've made this change in the attached file.  It is used in conjunction with the input to "Enter layer name prefix to substitute for <layer xref name prefix>" and allows the restoration of layer settings from any drawing to any xref attached to it. It converts xref layer names to non-xref layer names and vice versa.  They can be made to have the same layer settings in spite of the xref prefix differences between their layer tables.

 

The query "Enter layer name to isolate operation to" accepts wildcard strings and limits the layer changes to only those layers that match the string, wildcard or not, that you provide.

 

IMPORTXRL asks you to select a saved layer settings file and then provide the name of the source Xref.  The input for "source Xref" is the same as "layer xref name prefix".  This input for IMPORTXRL limits the operation to only those layers that match the layer xref name prefix.  The purpose is to allow setting xref layer settings to match any other drawing's saved layer settings for that same xref.

 

Once again, .lsp "content... doesn't match... type" so rename the attachment to have a .lsp extension.

AutoCAD User since 1989. Civil Engineering Professional since 1983
Product Ver.: 13.6.1781.0 Civil 3D 2024.3 Update
Built On:        U.152.0.0 AutoCAD 2024.1.2
                        27.0.37.14 Autodesk AutoCAD Map 3D 2024.0.1
                        8.6.52.0 AutoCAD Architecture 2024
Message 6 of 15
econnerly
in reply to: hencoop

Aww... Im getting it now. Thats for clarifying this for me. One last thing.... where in the lisp can I change where it writes the file to? Its really not that big of a deal but its writing the folder to our server.

Message 7 of 15
hencoop
in reply to: econnerly

I intended to make the layer saves available in the same location as the drawing they were taken from.  If this is a problem for any reason you can easily change the code to write them to a folder of your own choosing on any drive that you have write privileges to.  The program will create your folder if it doesn't exist at the time you run XRLAYERS.

 

Type VLIDE at the command prompt and open the file XRLAYERS.LSP (just in case this is new to you).

To keep from changing the location of the content identified by these line numbers (and making it more difficult to find the correct line to edit) do not add or remove any lines while editing the old content.

 

  1. Go to line #44 (ditto line #946):
      (VL-MKDIR (STRCAT (GETVAR "dwgprefix") "Layer Saves\\"))

     Line #44 creates a new folder named "Layer Saves" under the current drawing folder (if it doesn't exist).  If you want a specific new folder create it by providing the full path as a string in place of (STRCAT... ) or use (STRCAT... ) to concatenate the parts of your full path into one path string from multiple individual strings.

  2. Go to line #46 & #47 (ditto line #951 & #952):
             (STRCAT (GETVAR "dwgprefix")
                     "Layer Saves\\"
    Modify lines #46 and #47 (ditto line #951 & #952) with the same string or (STRCAT... ) concatenation elements that you put in line #44 (ditto line #946).  Note that this (STRCAT... ) includes the filename parts as well so you don't need to enclose the new path parts in their own (STRCAT...) again here (although it would still work if you did).  (The filename parts start on line #48 (ditto #953) and continue through line #69 (ditto #975)).

The 900's code lines mentioned tel DOS_GETFILENAV the default path to open for selecting the saved layer file to restore so it should be the same as the one you saved them to.  (There may be a slicker more economical way to code this but cut & paste worked well for me when I wrote it).

 

AutoCAD User since 1989. Civil Engineering Professional since 1983
Product Ver.: 13.6.1781.0 Civil 3D 2024.3 Update
Built On:        U.152.0.0 AutoCAD 2024.1.2
                        27.0.37.14 Autodesk AutoCAD Map 3D 2024.0.1
                        8.6.52.0 AutoCAD Architecture 2024
Message 8 of 15
hencoop
in reply to: econnerly

P.S.  If you specify one common folder to collect all of your layer saves in without regard to the individual drawing paths you will rapidly collect a very large number of files to browse through.  This will likely exponentially increase the time it takes to find and restore the one you want.  Also, if some drawings from different projects happen to have the same filename you will not be able to determine which drawing was the source of your saved layer settings.  Having a folder structure for your layer saves that matches your project folder structure will eliminate or greatly reduce the chances of encountering these problems.

If you must not put them on your server, I suggest that you only change the drive letter to a local one and keep the rest of your drawing path as your save/restore path.  This can be accomplished by (STRCAT "C" (SUBSTR (GETVAR "DWGPREFIX") 2)) in place of (GETVAR "DWGPREFIX") to change the drive letter to "C" and similarly for any other drive letter.

AutoCAD User since 1989. Civil Engineering Professional since 1983
Product Ver.: 13.6.1781.0 Civil 3D 2024.3 Update
Built On:        U.152.0.0 AutoCAD 2024.1.2
                        27.0.37.14 Autodesk AutoCAD Map 3D 2024.0.1
                        8.6.52.0 AutoCAD Architecture 2024
Message 9 of 15
hencoop
in reply to: hencoop

P.S.S.   If your typical drawing path doesn't already do so it would be a good idea to include a single folder at the root of the drive letter in which you will collect all of your various project drawing paths for cataloging and storing the layer saves.

e.g. Instead of using my suggestion to use

(STRCAT "C" (SUBSTR (GETVAR "DWGPREFIX") 2))

 in place of

(GETVAR "DWGPREFIX")

 to change the drive letter to "C", use

 

(STRCAT "C:\\NEW FOLDER" (SUBSTR (GETVAR "DWGPREFIX") 3))

in order to create the folder you need something like this

(PROGN
       (SETQ newfolder-path nil
             tokens-lst nil
       )
       (SETQ newfolder-path "C:" ;or whatever drive letter you need
             tokens-lst (CDR
(DOS_STRTOKENS ;requires DOSLIB
(STRCAT newfolder-path
"\\NEW FOLDER" ;replace with yours
(SUBSTR (GETVAR "DWGPREFIX") 3)
)
"\\"
)
) ) (DOS_DRIVE (CAR tokens-lst)) (FOREACH n tokens-lst (SETQ newfolder-path (STRCAT newfolder-path "\\" n)) (VL-MKDIR newfolder-path) (DOS_CHDIR newfolder-path) ) ;_ end of foreach )

 

AutoCAD User since 1989. Civil Engineering Professional since 1983
Product Ver.: 13.6.1781.0 Civil 3D 2024.3 Update
Built On:        U.152.0.0 AutoCAD 2024.1.2
                        27.0.37.14 Autodesk AutoCAD Map 3D 2024.0.1
                        8.6.52.0 AutoCAD Architecture 2024
Message 10 of 15
raghib.boctor
in reply to: hencoop

@hencoop  

 

Thank's for the lisp, just wondering if you have another way to do this as my the office IT department isn't allowing me to install "Doslib". 

i am wanting to just copy an existing Xref from one file and paste it in a different file while maintaining all layer changes i have made  ie " colour, line type, transparency" 

 

 

Thank you so much 

Ray

Message 11 of 15
hencoop
in reply to: raghib.boctor

I have modified the routine partially.

I checked for DOSLIB functions in the RXRLAY function and changed the code so that if they are not defined there is alternative code that works; however, you should use the "None" option for each prompt as I have not fixed the code in the subroutines for those.  I tested it by substituting DDOS_*** for the DOSLIB functions so that they would be undefined on my system and it ran okay for me.  (I changed them all back to DOS_*** which should be undefined for you and perform the same).

 

Again, be sure to rename the extension of the attached file to .lsp from .txt

 

P.S. You can try the Layer States Manager but I've found that it could have some trouble restoring linetypes (and it is not even kind enough to tell you which ones it had a problem with).

AutoCAD User since 1989. Civil Engineering Professional since 1983
Product Ver.: 13.6.1781.0 Civil 3D 2024.3 Update
Built On:        U.152.0.0 AutoCAD 2024.1.2
                        27.0.37.14 Autodesk AutoCAD Map 3D 2024.0.1
                        8.6.52.0 AutoCAD Architecture 2024
Message 12 of 15
MKKL
in reply to: hencoop

Message 11 is shown as a reply to message 10. Message 10's author, raqhib.boctor

 

 

 

 

Message 13 of 15
matthias.keusch
in reply to: MKKL

Hey MKKL if you did not found a solution yet, this would probably help you:

Link to the solution is blocked sorry.. but I got a screenshot atteched for you.

 

greets

Message 14 of 15

When I use RXRLAY it gives me the following error message:

; error: no function definition: DOS_GETFILENAV

Message 15 of 15

That function is defined within Robert McNeel & Associates' DOSLIB which is a free download, free to use.

you can get it here: https://wiki.mcneel.com/doslib/home  

Download it, install it (put it in s folder on your support file search path) and load its version for your version of AutoCAD.  If you have my "check_for_doslib.lsp" file, RXRLAY should load the correct version of DOSLIB for you once it is available on your support file search path.

AutoCAD User since 1989. Civil Engineering Professional since 1983
Product Ver.: 13.6.1781.0 Civil 3D 2024.3 Update
Built On:        U.152.0.0 AutoCAD 2024.1.2
                        27.0.37.14 Autodesk AutoCAD Map 3D 2024.0.1
                        8.6.52.0 AutoCAD Architecture 2024

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

Post to forums  

Autodesk Design & Make Report

”Boost