代码之家  ›  专栏  ›  技术社区  ›  libzz

如何运行具有不同commandFlags值的函数?

  •  0
  • libzz  · 技术社区  · 6 年前

    我有两个DLL文件。我们叫他们:

    1. 剂量01.dll
    2. 剂量测量02.dll

    下面的步骤描述了我正在处理这两个DLL的用例:

    1. 在AutoCAD中打开drawing01.dwg和drawing02.dwg。
    2. 通过命令行中的netload将dosomething01.dll加载到AutoCAD中。
    3. 通过命令行中的netload将dosomething02.dll加载到AutoCAD中。
    4. 我从drawing01.dwg的命令行运行dosomething01.dll中的函数。
    5. 我从drawing02.dwg的命令行运行dosomething02.dll中的函数。
    6. 单击绘图上的某个内容(作为dosomething02.dll上函数的输入)。

    我要做的是从一个操作中运行两个DLL的函数——基本上在一个新的DLL文件中的一个函数调用中执行步骤4到6。

    我的新dll文件中的代码如下:

    Dim acDocDwg01 As Document
    Dim acDocDwg02 As Document
    
    <CommandMethod("DOITALL", CommandFlags.Session)>
    Public Sub AllInOneFunction()
        Dim dosomething01 As New DoSomething01.clsMain
        Dim dosomething02 As New DoSomething02.clsMain
    
        Dim acDocMgr As DocumentCollection = Application.DocumentManager
    
        If isBothDrawingsOpened() Then
            ' Activate Drawing01 document
            acDocMgr.MdiActiveDocument = acDocDwg01
            dosomething01.createStuff()
    
            ' Activate Drawing02 document
            acDocMgr.MdiActiveDocument = acDocDwg02
            dosomething02.createMoreStuff()
        End If
    End Sub
    
    Private Function isBothDrawingsOpened() As Boolean
        Dim flag As Boolean
    
        'Collection of all opened documents
        Dim acadDocs As DocumentCollection = Application.DocumentManager
        Dim acDoc As Document
        Dim acCurDb As Database
    
        Dim d1, d2 As Boolean
    
        For Each acDoc In acadDocs
            acCurDb = acDoc.Database
            If acCurDb.Filename = "Drawing01" > 0 Then
                d1 = True
                acDocDwg01 = acDoc
            ElseIf acCurDb.Filename = "Drawing02" > 0 Then
                d2 = True
                acDocDwg02 = acDoc
            End If
            modLog.LogWrite(1, "Current Document: " & acDoc.Name)
        Next acDoc
    
        If (d1 And d2) = False Then
            MessageBox.Show("Please open both Drawing01.dwg and Drawing02.dwg before executing this function.")
            flag = False
        Else
            flag = True
        End If
    
        Return flag
    
    End Function
    

    问题是… 因为我需要在两个文档(图纸)之间切换,所以我需要使用 CommandFlags.Session . 但步骤6中的函数使用 CommandFlags.UsePickSet . 我提供的代码只运行dosomething02.dll函数的代码,而不等待用户输入(单击)。

    我读过 AutoDesk documentation 那就是:

    您可以使用vb.net中的+运算符和c_中的运算符来指定使用多个标志。

    <CommandMethod("CheckForPickfirstSelection", CommandFlags.UsePickSet + _
                                                 CommandFlags.NoBlockEditor)> _
    Public Sub CheckForPickfirstSelection()
     . . .
    End Sub
    

    我试过这样做,但没用。行为是一样的。

    更新: 我试着改变手术顺序:

        If isBothDrawingsOpened() Then
            ' Activate Drawing02 document
            acDocMgr.MdiActiveDocument = acDocDwg02
            dosomething02.createMoreStuff()
    
            ' Activate Drawing01 document
            acDocMgr.MdiActiveDocument = acDocDwg01
            dosomething01.createStuff()
        End If
    

    它实际上在继续之前等待我单击绘图。该问题可能与文档激活(切换)有关。我实际上可以看到活动文档随着代码的运行而改变,但是在它切换之后,用户就不能再以交互方式中断(?)或者我是否在如何激活或切换到文档中缺少某些内容?

    1 回复  |  直到 6 年前
        1
  •  1
  •   Alain    6 年前

    不确定,但在设置acdocdwg01当前值之后,也许可以强制将焦点放在绘图上。 例如:autodesk.autocad.applicationservices.application.mainwindow.focus();