- 积分
- 15341
- 明经币
- 个
- 注册时间
- 2002-2-4
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2003-10-14 12:36:00
|
显示全部楼层
保留失去PreviewThumbnail的辦法(FOR R2000~R2002 ONLY)
;;配合ACADX.ARX
This document describes a method in AcadX which provides
a workaround to a problem that affects VBA and ActiveX
clients which save documents to pre-AutoCAD 2000 .DWG
file formats.
When the Save or SaveAs methods of the Document object
are used to save a document to an earlier DWG release
format (e.g., R14 or earlier), AutoCAD does not generate
a thumbnail preview image for the file.
The AcadXApplication class provides a method that serves
to work around this problem:
MakePreviewImage(Document as Object,[UseCurrentView as Variant])
This method causes AutoCAD to generate a preview
thumbnail for the specified document, which will
be retained when a VBA or ActiveX client uses the
Save or SaveAs methods to save the document to an
earlier release format.
The optional UseCurrentView argument specifies if
the current viewport of the active document is to
be used as the basis for the preview image. If this
value is supplied and is True, the preview image
will have the same view parameters as the current
modelspace viewport. If this value is not supplied,
or is supplied and False, the preview image is a
plan view of the document's model space.
Note: This method is limited in that it will only
create previews of model space views. It will
not create a preview of a layout view as AutoCAD
does when saving a file currently in layout view.
You should first activate the document you are
going to save, then call MakePreviewImage
and pass the Document as the first parameter.
You should call MakePreviewImage just before
calling the Save or SaveAs methods, to ensure the
preview thumbnail is current.
Example:
' Note: You must reference the AcadX type library
' in the VBA project that uses this.
Public Sub TestMakePreviewImage()
Dim AcadX As AcadXApplication
Set AcadX = GetInterfaceObject("AcadX.Application")
ThisDrawing.Activate
AcadX.MakePreviewImage ThisDrawing
ThisDrawing.SaveAs "AcadR14.dwg", acR14_dwg
End Sub
In addition to creating model space previews for
documents saved to earlier release formats, this
method is also useful for generating previews in
documents that are accessed via ObjectDBX ActiveX
services (the AxDbDocument class).
For example, when you use the AcadDocument.WBlock
method to write a block or selected objects to a
new DWG file, the file will not have a preview
image. You can subsequently load this file into
an AxDbDocument object, and call MakePreviewImage()
to generate a preview of the DWG file produced by
the WBlock method.
When you call this method to create a preview of
a file opened in an AxDbDocument, you should pass
False as the value of the optional UseCurrentView
parameter, to force the preview to include the
entire extents of the document's model space.
In addition, when passing an AxDbDocument object
to any AcadX method as a parameter from Visual
LISP, you should then call the FreeObject method
of the AcadXApplication class, to ensure that
the object is properly released. This is required
due to a bug in Visual LISP, which erroneously
increments the reference count of vla-objects
that are passed as parameters to ActiveX methods.
The following example demonstrates how to open
a drawing using ObjectDBX from Visual LISP, and
generate a preview of the drawing, save it, and
finally releases it using FreeObject:
(vl-load-com)
(defun C:MAKEDWGPREVIEW ( / file dbxdoc acad acadx rslt)
(if (setq file
(getfiled "Select Drawing File" "" "dwg" 0)
)
(progn
(setq rslt
(vl-catch-all-apply
'(lambda ()
(setq acad (vlax-get-acad-object))
(setq dbxdoc
(vla-getInterfaceObject acad
"ObjectDBX.AxDbDocument"
)
)
(setq acadx
(vla-getInterfaceObject acad
"AcadX.Application"
)
)
(vla-open dbxdoc file)
(vlax-invoke-method acadx
'MakePreviewImage
dbxdoc
:vlax-false
)
(vlax-invoke-method AcadX 'SaveAs dbxdoc file)
)
)
)
(if (vl-catch-all-error-p rslt)
(princ (strcat (vl-catch-all-error-message rslt)))
)
(if dbxdoc
(progn
(vlax-invoke-method acadx 'FreeObject dbxdoc)
(vlax-release-object dbxdoc)
)
)
(vlax-release-object acadx)
)
)
(princ)
) |
|