Lisp to insert Xrefs from different folders

Lisp to insert Xrefs from different folders

sambaldan
Contributor Contributor
2,809 Views
9 Replies
Message 1 of 10

Lisp to insert Xrefs from different folders

sambaldan
Contributor
Contributor

Hi,

 

I've been working on a lisp to help us set up new drawings. It works in the way that as a company we use the same DWG names for all of the same xrefs even between different projects. i.e. 2D First Floor General Arrangement  =  2D-XA-01.dwg / 2D Second Floor RCP = 2D-XA-02-RCP.dwg etc etc

 

See my attempt below which may make things a little clearer:

 

 

(defun c:01ABC ( / )
(command "_-xref" "overlay" "C:\\Users\\home\\Desktop\\LISP TEST\\0341 - ABC\\123\\XREF\\2D XREFS\\2D-XA-01.dwg" "0,0,0" "" "" "") (princ)
(command "_-xref" "overlay" "C:\\Users\\home\\Desktop\\LISP TEST\\0341 - ABC\\123\\XREF\\2D XREFS\\2D-XA-01-RCP.dwg" "0,0,0" "" "" "") (princ)
(command "_-xref" "overlay" "C:\\Users\\home\\Desktop\\LISP TEST\\0341 - ABC\\123\\XREF\\2D XREFS\\2D-XA-01-FURNITURE.dwg" "0,0,0" "" "" "") (princ)
(command "_-xref" "overlay" "C:\\Users\\home\\Desktop\\LISP TEST\\0341 - ABC\\123\\XREF\\3D XREFS\\3D-XA-01.dwg" "0,0,0" "" "" "") (princ)
(command "_-xref" "overlay" "C:\\Users\\home\\Desktop\\LISP TEST\\0341 - ABC\\123\\XREF\\2D XREFS\\2D-XS-02.dwg" "0,0,0" "" "" "") (princ)
(command "_-xref" "overlay" "C:\\Users\\home\\Desktop\\LISP TEST\\0341 - ABC\\123\\XREF\\3D XREFS\\3D-XS-02.dwg" "0,0,0" "" "" "") (princ)
(command "zoom" "e")
(princ))

(defun c:01XYZ ( / )
(command "_-xref" "overlay" "C:\\Users\\home\\Desktop\\LISP TEST\\0342 - XYZ\\123\\XREF\\2D XREFS\\2D-XA-01.dwg" "0,0,0" "" "" "") (princ)
(command "_-xref" "overlay" "C:\\Users\\home\\Desktop\\LISP TEST\\0342 - XYZ\\123\\XREF\\2D XREFS\\2D-XA-01-RCP.dwg" "0,0,0" "" "" "") (princ)
(command "_-xref" "overlay" "C:\\Users\\home\\Desktop\\LISP TEST\\0342 - XYZ\\123\\XREF\\2D XREFS\\2D-XA-01-FURNITURE.dwg" "0,0,0" "" "" "") (princ)
(command "_-xref" "overlay" "C:\\Users\\home\\Desktop\\LISP TEST\\0342 - XYZ\\123\\XREF\\3D XREFS\\3D-XA-01.dwg" "0,0,0" "" "" "") (princ)
(command "_-xref" "overlay" "C:\\Users\\home\\Desktop\\LISP TEST\\0342 - XYZ\\123\\XREF\\2D XREFS\\2D-XS-02.dwg" "0,0,0" "" "" "") (princ)
(command "_-xref" "overlay" "C:\\Users\\home\\Desktop\\LISP TEST\\0342 - XYZ\\123\\XREF\\3D XREFS\\3D-XS-02.dwg" "0,0,0" "" "" "") (princ)
(command "zoom" "e")
(princ))

(defun c:02ABC ( / )
(command "_-xref" "overlay" "C:\\Users\\home\\Desktop\\LISP TEST\\0341 - ABC\\123\\XREF\\2D XREFS\\2D-XA-02.dwg" "0,0,0" "" "" "") (princ)
(command "_-xref" "overlay" "C:\\Users\\home\\Desktop\\LISP TEST\\0341 - ABC\\123\\XREF\\2D XREFS\\2D-XA-02-RCP.dwg" "0,0,0" "" "" "") (princ)
(command "_-xref" "overlay" "C:\\Users\\home\\Desktop\\LISP TEST\\0341 - ABC\\123\\XREF\\2D XREFS\\2D-XA-02-FURNITURE.dwg" "0,0,0" "" "" "") (princ)
(command "_-xref" "overlay" "C:\\Users\\home\\Desktop\\LISP TEST\\0341 - ABC\\123\\XREF\\3D XREFS\\3D-XA-02.dwg" "0,0,0" "" "" "") (princ)
(command "_-xref" "overlay" "C:\\Users\\home\\Desktop\\LISP TEST\\0341 - ABC\\123\\XREF\\2D XREFS\\2D-XS-03.dwg" "0,0,0" "" "" "") (princ)
(command "_-xref" "overlay" "C:\\Users\\home\\Desktop\\LISP TEST\\0341 - ABC\\123\\XREF\\3D XREFS\\3D-XS-03.dwg" "0,0,0" "" "" "") (princ)
(command "zoom" "e")
(princ))

(defun c:02XYZ ( / )
(command "_-xref" "overlay" "C:\\Users\\home\\Desktop\\LISP TEST\\0342 - XYZ\\123\\XREF\\2D XREFS\\2D-XA-02.dwg" "0,0,0" "" "" "") (princ)
(command "_-xref" "overlay" "C:\\Users\\home\\Desktop\\LISP TEST\\0342 - XYZ\\123\\XREF\\2D XREFS\\2D-XA-02-RCP.dwg" "0,0,0" "" "" "") (princ)
(command "_-xref" "overlay" "C:\\Users\\home\\Desktop\\LISP TEST\\0342 - XYZ\\123\\XREF\\2D XREFS\\2D-XA-02-FURNITURE.dwg" "0,0,0" "" "" "") (princ)
(command "_-xref" "overlay" "C:\\Users\\home\\Desktop\\LISP TEST\\0342 - XYZ\\123\\XREF\\3D XREFS\\3D-XA-02.dwg" "0,0,0" "" "" "") (princ)
(command "_-xref" "overlay" "C:\\Users\\home\\Desktop\\LISP TEST\\0342 - XYZ\\123\\XREF\\2D XREFS\\2D-XS-03.dwg" "0,0,0" "" "" "") (princ)
(command "_-xref" "overlay" "C:\\Users\\home\\Desktop\\LISP TEST\\0342 - XYZ\\123\\XREF\\3D XREFS\\3D-XS-03.dwg" "0,0,0" "" "" "") (princ)
(command "zoom" "e")
(princ))

 I understand i'm far from spectacular at writing these but at the moment it works great. For example, if i want to insert level 2 XREFS for project XYZ i simply type 02XYZ

 

 

The project numbers i.e. 0341/0342 is always changing as new jobs come in and their ABC/XYZ values change also so my lisp would require me to adapt/update it every time a new project is started.

 

My question is whether there is a way to load the XREFS from the folder after selecting what project i want or having some sort of wild card so when prompted for the job number it will automatically read for folders containing that job number and follow the path through there and load xrefs from 

\\123\\XREF\\3D XREFS\\etc.dwg 

onwards

 

I understand this probably isn't a 5 minute piece of assistance and your help is greatly appreciated.

 

Thank you in advance for any help

 

Sam

 

 

 

 

 

 

0 Likes
2,810 Views
9 Replies
Replies (9)
Message 2 of 10

pbejse
Mentor
Mentor

@sambaldan wrote:

Hi,

  

I understand this probably isn't a 5 minute piece of assistance and your help is greatly appreciated.

 

Thank you in advance for any help

 

Sam 


Use a template, better yet, look into sheets sets.

 

Or even this..

 

 

layout tab.png 

 

0 Likes
Message 3 of 10

pbejse
Mentor
Mentor

@sambaldan wrote:

 

My question is whether there is a way to load the XREFS from the folder after selecting what project i want or having some sort of wild card so when prompted for the job number it will automatically read for folders containing that job number and follow the path through there and load xrefs from 
\\123\\XREF\\3D XREFS\\etc.dwg

 

 

Sam 


 

I may have something similar to this in the past, and few ideas to streamline the process.  its way past my bed time. I'll check in tomorrow.

 

Cheers

0 Likes
Message 4 of 10

sambaldan
Contributor
Contributor

I appreciate you looking at this for me.

 

(command "_-xref" "overlay" "C:\\Users\\home\\Desktop\\LISP TEST\\0342 - XYZ\\123\\XREF\\3D XREFS\\0342-3D-XS-03.dwg" "0,0,0" "" "" "") (princ)

Last night in the absence from my office i missed the job number (0342-) which i have indicated in bold above. I'm not sure if this will affect anything i previously mentioned.

 

Thanks

0 Likes
Message 5 of 10

pbejse
Mentor
Mentor

@sambaldan wrote:

I appreciate you looking at this for me.

 


Have you had time to explore Sheet Set Manager?

 

dst template.PNG

 

You can select a template that fits your project requirement

 

You can setup your title blocks and any other Xrefs that goes with the project, page setup, including blocks for annotations, publish and e-transmit. folder structures even.

 

I would gladly help you with your code, but at least have a look at what Sheet Set Manager can do for you, it has a lot to offer.

 

I will tinker with your code and post it later.

 

Cheers

 

 

 

 

0 Likes
Message 6 of 10

sambaldan
Contributor
Contributor

 

I'll have a look in to it - never used it before so ill see if i can figure it out.

 

Thanks

0 Likes
Message 7 of 10

pbejse
Mentor
Mentor

 

 

Quick, Is this the format for project number 0342 - XYZ numbers - letters? or sometimes its a mix?  number - numbers/letters

 

or

 

always numbers and dash? space between dash? or you can just type in the prefix?

 

 

0 Likes
Message 8 of 10

sambaldan
Contributor
Contributor

Folder is always Job Number + space + dash + space + job title (03xx - Job Title) however this may be in the format of (03xx - 100 Smith Street)

DWG Files are always Job Number+dash+XA/XS

 

 

0 Likes
Message 9 of 10

pbejse
Mentor
Mentor

@sambaldan wrote:

Folder is always Job Number + space + dash + space + job title (03xx - Job Title) however this may be in the format of (03xx - 100 Smith Street)

DWG Files are always Job Number+dash+XA/XS


To make it simple, just type in the prefix

 

(Defun c:PXREF ( / project prefix)
      (if (and
		(setq project (acet-ui-pickdir "Select Project Folder" "C:\\Users\\YourFoldername"))
        	(setq prefix  (lisped "PREFIX"))
                )
        (progn
                 (Foreach projectxref '("2D-XA-02.dwg"
                                            "2D-XA-02-RCP.dwg"
                                            "2D-XA-02-FURNITURE.dwg"
                                            "3D-XA-02.dwg"
                                            "2D-XS-03.dwg"
                                            "3D-XS-03.dwg")                      
                      (if (findfile (setq xref2attach (strcat project "\\" prefix "-" projectxref)))
                          (command "_-xref" "overlay" xref2attach "0,0,0" "" "" "")
                          )
                      )
            )
      )
)
0 Likes
Message 10 of 10

pbejse
Mentor
Mentor

And if the xref files do not exist on the selected folder

 

 

(Defun c:PXREF ( / sourceXREF project prefix)
(setq sourceXREF "C:\\Users\\YourFolder\\Blocks\\") (if (and (setq project (acet-ui-pickdir "Select Project Folder" "C:\\Users\\YourFolder")) (setq prefix (lisped "PREFIX"))) (progn (Foreach projectxref '("2D-XA-02.dwg" "2D-XA-02-RCP.dwg" "2D-XA-02-FURNITURE.dwg" "3D-XA-02.dwg" "2D-XS-03.dwg" "3D-XS-03.dwg") (if (or (findfile (setq xref2attach (strcat project "\\" prefix "-"projectxref))) (vl-file-copy (strcat sourceXREF prefix "-" projectxref) xref2attach) ) (command "_-xref" "overlay" xref2attach "0,0,0" "" "" "") ) ) ) ) )

The program will make a copy from your library to specified folder

 

or even

 

(Foreach projectxref (vl-directory-files project "*.dwg")                        	
    	 (command "_-xref" "overlay" (strcat project "\\" projectxref) "0,0,0" "" "" "")		
    )

EDIT: No need for Findfile function

 

HTH

 

MORE EDIT: HANG ON A MINUTE. THIS IS EXACTLY LIKE XREF MANAGER 'S FUNCTION Smiley Very Happy I OVER ANALYZE EVERYTHING THESE DAYS. need a break 🙂

0 Likes