Jump to content

Automate drawing creation/ overlay XREFs?!


lgrammel

Recommended Posts

Hello,

I have a highly repetitive task that I am trying to automate and looking for a way to do this...

 

  1. Copy files from Mechanical Directory "Model" (eg filename "Drawing1.dwg")
  2. paste in new directory "ELEC" and rename/ saveAs with -ELEC at end (eg filename "Drawing1-ELEC.dwg)
  3. Delete the contents
  4. Overlay mechanical DWG from the "Model" directory (XREF @ 0,0,0) (there can be 50+ mechanical drawings)
  5. Save
  6. Move on to next drawing in the "Model Directory (eg. "Drawing2.dwg")
  7. 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.

Link to comment
Share on other sites

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"

 

 

Link to comment
Share on other sites

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
)

Link to comment
Share on other sites

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

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