Jump to content

Attach One XREF to all Layouts in the open drawing


Hippe013

Recommended Posts

Hello everyone!

 

Just as the title says I am looking to attach an xref to each layout in my open drawing. I am currently using Civil3D 2013.

 

My current code is as follows:

 

(defun c:XREF-LAYOUT (/ fp xrname PS LOs AD)
 (setq fp (getfiled "Select External Reference: " "" "dwg" 0))
 (if (/= nil fp)
   (progn
     (setq xrname (vl-filename-base fp))
     (setq PS (vla-get-paperspace (setq AD (vla-get-activedocument (vlax-get-acad-object)))))
     (setq LOs (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object))))
     (vlax-for lo LOs
(if (/= "Model" (vla-get-name lo))
  (progn
    (vlax-put-property AD 'ActiveLayout lo)
    (setq xr (vla-AttachExternalReference PS fp xrname (vlax-3d-point (list 0 0 0)) 1. 1. 1. 0. :vlax-false))
  )
)
     )
   )
 )
 )

 

I keep getting this error:

 

; error: Exception occurred: 0xC0000005 (Access Violation)

; warning: unwind skipped on unknown exception

 

Any help would be appreciated.

Link to comment
Share on other sites

Try this:

(defun c:xrl ( / acd acl dwg ins xrn )
   (if (setq dwg (getfiled "Select XRef" "" "dwg" 16))
       (progn
           (setq acd (vla-get-activedocument (vlax-get-acad-object))
                 acl (vla-get-activelayout acd)
                 xrn (vl-filename-base dwg)
                 ins (vlax-3D-point 0 0)
           )
           (vlax-for lay (vla-get-layouts acd)
               (if (/= "MODEL" (strcase (vla-get-name lay)))
                   (progn
                       (vla-put-activelayout acd lay)
                       (vla-attachexternalreference (vla-get-paperspace acd) dwg xrn ins 1.0 1.0 1.0 0.0 :vlax-false)
                   )
               )
           )
           (vla-put-activelayout acd acl)
       )
   )
   (princ)
)
(vl-load-com) (princ)
 
Edited by Lee Mac
  • Like 1
Link to comment
Share on other sites

Hey Lee,

 

Thanks for the reply. Though in the mean time I ended up getting it to work. My revised code is as follows:

 


(defun c:xrl (/ fp xrname AD PS LO l PS)
 (setq fp (getfiled "Get 
Xref" "" "dwg" )
 (setq xrname (vl-filename-base fp))
 (setq 
AD (vla-get-ActiveDocument (Vlax-get-acad-object)))
 (setq LO 
(vla-get-layouts AD))
 (vlax-for l LO
   (if (/= 
"Model" (vla-get-name l))
     
(progn
(vla-put-ActiveLayout AD l)
(princ (strcat "\n***" 
(vla-get-name l) "***\n"))
(setq PS (vla-get-block l))
(setq 
xr (vla-AttachExternalReference PS fp xrname (vlax-3d-point '(0 0 0)) 1. 1. 1. 
0. :vlax-false))
)
     
)
   )
 (princ)
 )

Edited by Hippe013
Link to comment
Share on other sites

Here is another method to avoid the need to switch layouts:

(defun c:xrl ( / acd dwg ins obj xrn )
   (if (setq dwg (getfiled "Select XRef" "" "dwg" 16))
       (progn
           (setq acd (vla-get-activedocument (vlax-get-acad-object))
                 xrn (vl-filename-base dwg)
                 ins (vlax-3D-point 0 0)
                 obj (list (vla-attachexternalreference (vla-get-modelspace acd) dwg xrn ins 1.0 1.0 1.0 0.0 :vlax-false))
           )
           (vlax-for lay (vla-get-layouts acd)
               (if (/= "MODEL" (strcase (vla-get-name lay)))
                   (vlax-invoke acd 'copyobjects obj (vla-get-block lay))
               )
           )
           (vla-delete (car obj))
       )
   )
   (princ)
)
(vl-load-com) (princ)
 
Edited by Lee Mac
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...