CAD编辑时出现eNotApplicable - 小众知识

CAD编辑时出现eNotApplicable

2019-03-03 13:39:34 苏内容
  标签: ObjectARX/AutoCAD
阅读:7927

I am trying to open a DWG file, read the number of specific blocks found inside, and then close the drawing.  The problem I am having is that after opening my file from a form using the OpenFileDialog component, I get the eNotApplicable Error on the following line:

 

           Dim dwg As Document = Application.DocumentManager.Open(fileName, True)
            Using tr As Transaction = dwg.TransactionManager.StartTransaction
                Dim tv(0 To 1) As TypedValue
                tv(0) = New TypedValue(0, "INSERT")
                tv(1) = New TypedValue(2, "SB128")
                Dim fil As New SelectionFilter(tv)
                Dim psr As PromptSelectionResult = dwg.Editor.SelectAll(fil)     'FAILS HERE (eNotApplicable )
                If psr.Value IsNot Nothing Then
                    newAttribCnt = psr.Value.Count
                End If
            End Using            dwg.CloseAndDiscard()

 

I thought it might have something to do with my filter or Typed value so to confirm I tried similar code, but this time instead of opening the target drawing like above, I *manually* opened my file first then ran the following code:

 

         Dim dwg As Document = Application.DocumentManager.MdiActiveDocument
            Using tr As Transaction = dwg.TransactionManager.StartTransaction
                Dim tv(0 To 1) As TypedValue
                tv(0) = New TypedValue(0, "INSERT")
                tv(1) = New TypedValue(2, "SB128")
                Dim fil As New SelectionFilter(tv)
                Dim psr As PromptSelectionResult = dwg.Editor.SelectAll(fil)      'WORKS FINE HERE
                If psr.Value IsNot Nothing Then
                    newAttribCnt = psr.Value.Count
                End If
            End Using

 As you can see the only difference is it works when opening the file first and using MdiActiveDocument but does not when opening the file via DocumentManager.Open.  When I check "dwg.name" during debugging on the failed code, I can see that "dwg" does reference the file just opened and not the drawing I opened my form from.  I bet this is really something simple and fundamental that I just don't know about.  I also have made sure that I am calling form.Hide before calling SelectAll, just to make sure that the active form isn't blocking the selection.  But even in my MdiActiveDocument example, I am hiding the form and am able to return a valid filtered selection.

 

Any ideas?



将命令添加线程有效

<CommandMethod("XX", CommandFlags.Session)> _
        Public Sub Main()

        End Sub

扩展阅读
相关阅读
© CopyRight 2010-2021, PREDREAM.ORG, Inc.All Rights Reserved. 京ICP备13045924号-1