2017-06-29 9 views
0

Ich versuche sicherzustellen, dass ich Entitäten in ModelSpace adressiere, aber ich bekomme eine Ausnahme, die keinen Hinweis darauf gibt, was das Problem ist, weil es ein COM-Objekt ist. Weiß jemand, was ich falsch machen könnte? Wenn ich diese Zeile (und die Zoom-Extents-Zeile) herausnehme, funktioniert der verbleibende Code einwandfrei. Daher weiß ich, dass mein Dokumentobjekt korrekt eingestellt ist.Einstellung von AutoCAD ActiveSpace auf ModelSpace VB.NET

 Dim acDWG As AutoCAD.AcadDocument 
     ' open the drawing 
     acDWG = acApp.Documents.Open(dgvr.Cells("FullName").Value.ToString) 
     ' ensure the drawing has the modelspace tab activated (doesnt work) 
     acDWG.ActiveSpace = AutoCAD.AcActiveSpace.acModelSpace 
     ' zoom to extents (sometimes works, sometimes not)    ' 
     acApp.ZoomExtents() 
     ' build a selectionset of all blocks named 'Solid1' and then delete them all 
     Dim ss As AutoCAD.AcadSelectionSet = acDWG.SelectionSets.Add("DELETE") 
     Dim gpCode(1) As Int16 
     Dim dataValue(1) As Object 
     gpCode(0) = 0 : dataValue(0) = "Insert" 
     gpCode(1) = 2 : dataValue(1) = "Solid1" 
     ss.Select(AutoCAD.AcSelect.acSelectionSetAll,,, gpCode, dataValue) 
     ss.Erase() 
     ss.Delete() 
     ss = Nothing 

Update: Ich entdecken, warum ich die Störung erhalten. Der Code ist korrekt, aber das Problem ist, dass die Zeichnung noch nicht fertig ist. Wenn ich eine "Warte auf 5 Sekunden" Codezeile direkt nach der Open Zeile lege, funktioniert es gut. So scheint es meine Frage ist, wie man die Zeichnung öffnet und VB.Net auf ein Signal vom COM-Objekt warten lässt, dass es "bereit ist, fortzufahren"? (Nicht sicher, wie es zu Wort)

+0

Von wo sind Sie diesen Code ausgeführt wird? –

+0

Inside Visual Studio .NET 2017 – Joe

+0

genauer gesagt ... WinForms – Joe

Antwort

0

Verwenden Sie eine Kombination aus Do...Loop und ein Try...Catch Block zu „warten“ wie folgt aus:

  Dim acDWG As AutoCAD.AcadDocument 
      acDWG = acApp.Documents.Open(dgvr.Cells("FullName").Value.ToString) 
      Dim bOpen As Boolean = False 
      Do Until bOpen = True 
       Try 
        acDWG.ActiveSpace = AutoCAD.AcActiveSpace.acModelSpace 
        bOpen = True 
       Catch ex As Exception 
        ' ignore the error and try again until it is open 
       End Try 
      Loop 
+0

Funktioniert wie ein Charme, BraX !! Vielen Dank! – Joe

Verwandte Themen