Jump to content

Copying layouts with vla-CopyObjects breaks drawing


Recommended Posts

Posted

I am currently writing a program that will take layouts defined in a template file and copy them over to the current drawing. But running this program will cause the the file to break. The new layouts will not show up and if you attempt to switch to a different layout AutoCad will crash. If you try to open the file up again AutoCad will say its corrupted and will repair the file which seems to fix the problem. 

(defun c:copyLayouts ()
	(vl-load-com)
	(setq acadObj (vlax-get-acad-object))
	(setq doc (vla-get-ActiveDocument acadObj))

  	(setq impdwg (getfiled "Select Master Template" "" "dwt" 16))
  	(setq impdoc
	        (vla-getinterfaceobject
		(vlax-get-acad-object)
		(strcat "ObjectDBX.AxDbDocument." (itoa (atoi (getvar 'acadver))))
		);vla-getinterfaceobject
	);setq
  
  	(vl-catch-all-apply 'vla-open (list impdoc impdwg))
  
  	(setq layoat (vlax-get-property impdoc 'layouts))

	(setq safeLayout (vlax-make-safearray vlax-vbObject (cons 0 (- (vla-get-count layoat) 1))))
  
  	(setq i 0)
	(repeat (vla-get-count layoat)
		(vlax-safearray-put-element safeLayout i (vla-item layoat i))
		(setq i (1+ i))
	);repeat

  	(vla-CopyObjects impdoc safeLayout (vlax-get-property doc 'layouts))

  	(princ "\n\ncopy done\n\n")
  	(princ)
);defun

 

This only seems to be a problem with layouts. Using the same code for say a UCS works just fine. This is probably just some stupid mistake but I have been stuck on this for a while now so any help would be appreciated. 

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