Hippe013 Posted May 23, 2013 Posted May 23, 2013 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. Quote
Lee Mac Posted May 24, 2013 Posted May 24, 2013 (edited) 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 August 30, 2022 by Lee Mac 1 Quote
Hippe013 Posted May 24, 2013 Author Posted May 24, 2013 (edited) 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 May 24, 2013 by Hippe013 Quote
Lee Mac Posted May 24, 2013 Posted May 24, 2013 (edited) 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 August 30, 2022 by Lee Mac Quote
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.