lgrammel Posted August 5, 2019 Share Posted August 5, 2019 Hello, I have a highly repetitive task that I am trying to automate and looking for a way to do this... Copy files from Mechanical Directory "Model" (eg filename "Drawing1.dwg") paste in new directory "ELEC" and rename/ saveAs with -ELEC at end (eg filename "Drawing1-ELEC.dwg) Delete the contents Overlay mechanical DWG from the "Model" directory (XREF @ 0,0,0) (there can be 50+ mechanical drawings) Save Move on to next drawing in the "Model Directory (eg. "Drawing2.dwg") Repeat for next Mechanical DWG… Example: Project A has sub folders "Model" So I need to create subfolder "ELEC". The file "Mechanical1.dwg" in the "Mech" folder means that I need to have a "Mechanical1-ELEC.dwg" in the "ELEC" folder such that the drawing has the XREF to the "Mechanical1.dwg" file. Then I need to repeat for all .dwg files in the Mech folder. Quote Link to comment Share on other sites More sharing options...
Emmanuel Delay Posted August 7, 2019 Share Posted August 7, 2019 I can help you with 1 to 5. Then you still have to perform the routine multiple times, but it should still help. A few questions: - First, what do you mean with 3? Delete contents of what? - Can you repeat a bit more clearly which files are where? Which must be attached (overlayed) to which? Maybe you can give an example with absolute locations (example main file: "c:\usertemp\project1\drawing1.dwg" ...) Here's what I did: - main file: "C:\UserTemp\xref_copy\Mechanical.dwg" - folder to read files from: "C:\UserTemp\xref_copy\Model" (files "Elec1.dwg" "Elec2.dwg") - folder to write new files to: "C:\UserTemp\xref_copy\ELEC" - Then "Mechanical.dwg" gets xrefs: "C:\UserTemp\xref_copy\ELEC\Elec1-ELEC.dwg", "C:\UserTemp\xref_copy\ELEC\Elec2-ELEC.dwg" Quote Link to comment Share on other sites More sharing options...
rlx Posted August 7, 2019 Share Posted August 7, 2019 To get you started (site is called cadtutor for a reason) Begin with an empty drawing ;;; https://www.cadtutor.net/forum/topic/68409-automate-drawing-creation-overlay-xrefs/ ;;; Example: Project A has sub folders "Model" So I need to create subfolder "ELEC". ;;; The file "Mechanical1.dwg" in the "Mech" folder means that I need to have a "Mechanical1-ELEC.dwg" ;;; in the "ELEC" folder such that the drawing has the XREF to the "Mechanical1.dwg" file. ;;; Then I need to repeat for all .dwg files in the Mech folder. (defun c:t1 ( / doc sourceFolder targetFolder dwg-list dwg-name) (if (and (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))) (setq sourceFolder (getfolder "Select folder with source drawings" "" nil)) ;;; replace sourcefolder with "" if targetfolder is not a subfolder in sourcefolder (setq targetFolder (getfolder "Select folder to create new drawings" sourceFolder T)) (vl-consp (setq dwg-list (mapcar '(lambda (x)(strcat sourceFolder "\\" x)) (vl-directory-files sourceFolder "*.dwg" 1))))) (foreach dwg dwg-list ;;; create name to save drawing (setq dwg-name (strcat targetfolder "\\" (vl-filename-base dwg) "-ELEC.dwg")) ;;; remove all xrefs if any (vl-catch-all-apply 'vl-cmdf (list "-xref" "detach" "*")) ;;; attach dwg as xref (vl-catch-all-apply 'vl-cmdf (list "-xref" "overlay" dwg '(0 0) 1 1 0)) ;;; save the drawings (vla-saveas doc dwg-name) ) (prompt "\nFunction cancelled") ) (princ) ) ;;; $msg = message, $def = default path , %new = display create new folder option (t or nil) (defun GetFolder ($m $def %new / sh fol pFol path) (vl-catch-all-apply (function (lambda nil (setq sh (vlax-get-or-create-object "Shell.Application")) (setq fol (vlax-invoke-method sh 'BrowseForFolder 0 (cond ($m)(""))(if %new 0 512) (cond ($def)((strcat (getenv "userprofile") "\\Desktop\\"))))) (setq pFol (vlax-get-property fol 'ParentFolder)) (setq path (vlax-get-property (vlax-invoke-method pFol 'Parsename (vlax-get-property fol 'Title)) 'Path))))) (foreach x (reverse (list sh fol pFol path))(vl-catch-all-apply 'vlax-release-object (list x))) path ) Quote Link to comment Share on other sites More sharing options...
BIGAL Posted August 9, 2019 Share Posted August 9, 2019 Would using the vl file functions be easier than using shell ? Quote Link to comment Share on other sites More sharing options...
rlx Posted August 9, 2019 Share Posted August 9, 2019 3 hours ago, BIGAL said: Would using the vl file functions be easier than using shell ? if you're taking the copy & erase road ....maybe , something like (command "sh" "copy c:\projectA\model\*.dwg c:\projectA\elec\*-elec.dwg") or whatever. Starting with empty dwg and using xref & saveas no need for copy , erase & purge etc. But I'll leave that choice to OP , his (or her) party... 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.