CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ActiveX 开发指南

相关分类

关闭方法 (ActiveX)

2023-1-4 11:23| 发布者: admin| 查看: 583| 评论: 0|来自: AutoCAD

摘要: 关闭指定的图形或所有打开的图形。

关闭指定的图形或所有打开的图形。

支持的平台:仅窗口

签名

工 务 局:

object.Close [SaveChanges] [, FileName]
对象

类型:文档,文档

此方法适用的对象。

保存更改

访问:仅输入;自选

类型:变体

指定是否要保存图形。 (从集合调用时不适用。)Documents

  • True:保存绘图。
  • False:不保存绘图。
文件名

访问:仅输入;自选

类型:字符串

要指定给图形的名称。如果首次保存图形时未提供名称,则将使用 VBA 项目信息保存图形:(从集合调用时不适用。ThisDrawing.Path\ThisDrawing.NameDocuments

返回值(RetVal)

无返回值。

言论

如果图形没有更改,则忽略。如果对图形进行了更改,则指定是否应保存更改。参数的默认值为。SaveChangesFileNameSaveChangesSaveChangesTrue

  • Ifisand还没有与图形关联的文件名,则使用参数。省略了 ifis,或者如果从文档集合调用此方法,则会发出错误。SaveChangesTrueFileNameFileName
  • Ifis,则图形将关闭,并且不会保存更改。SaveChangesFalse

在 MDI 模式下从文档集合调用此方法将关闭所有打开的图形。若要关闭单个图形,请从要关闭的图形调用此方法。

不能从该图形的事件处理程序内部关闭图形。

注意:关闭图形会破坏对象。切勿在对象被销毁或在这种情况下关闭后尝试引用对象。进程内客户端(VBA 宏)可能会注意到,在退出子例程之前,不会销毁对象。但是,根本不建议引用已销毁的对象,即使在进程内代码中也是如此。Document

例子

工 务 局:

Sub Example_Close()
    ' This example cycles through the documents collection
    ' and closes all open drawings using the Close method.

    Dim DOC As AcadDocument
    
    ' If there are no open documents, then exit
    If Documents.count = 0 Then
        MsgBox "There are no open documents!"
        Exit Sub
    End If
    
    ' Close all open documents
    For Each DOC In Documents
        If MsgBox("Do you wish to close the document: " & DOC.WindowTitle, vbYesNo & vbQuestion) = vbYes Then
            If DOC.FullName <> "" Then
                DOC.Close
            Else
                MsgBox DOC.name & " has not been saved yet, so it will not be closed."
            End If
        End If
    Next
End Sub

Visual LISP:

(vl-load-com)
(defun c:Example_Close()
    ;; This example cycles through the documents collection
    ;; and closes all open drawings using the Close method
    ;; except the current drawing.
    (setq acadObj (vlax-get-acad-object))
    (setq curDoc (vla-get-ActiveDocument acadObj))
    (setq docs (vla-get-Documents acadObj))

    ;; Close all open documents and discard changes, except for the current drawing
    (vlax-for doc docs
        (if (/= (vla-get-Name doc) (vla-get-Name curDoc))
	    (progn
	        (alert (strcat "Closing " (vla-get-Name doc) " file."))
                (vla-Close doc :vlax-false)
	    )
        )
    )
)

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )

GMT+8, 2024-5-12 03:02

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部