TheSwamp
Code Red => .NET => Topic started by: MDONUT12 on April 11, 2009, 01:34:23 PM
-
Hi everyone,
I have this code I've been using for a couple years that worked fine inside VBA. Now inside AutoCAD 2010, I'm trying to port all my code to .net. Its mainly still using COM for everything as you can see. My main issue is the code opens the xref i selected, however it switches back to the original drawing. Then when it runs the zoom operation, its running in the original drawing and not the xref host drawing. I'm trying to keep it on xref host file so the zoom can take effect on that drawing not, the original drawing.
The idea is to have the user issue the command select a line inside an xref, then open the xref, then zoom to that object. (Think for a civil plan with thousands of similar lines, you can get right to the one you picked regardless of where the xref host drawing was saved at in model space).
Here is where I'm at, thanks for any help!!
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices.Application
Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common
Public Class vbstudentClass
<CommandMethod("NXOPEN")> _
Public Sub NewCmd1()
Dim ThisDrawing As AcadDocument
ThisDrawing = DocumentManager.MdiActiveDocument.AcadDocument
Dim MyApp As AcadApplication
MyApp = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication
' myapp = inter
Dim PickPoint As Object
Dim objEntity As AcadEntity
Dim Object2 As AcadEntity
Dim PickedPoint As Object, TransMatrix As Object, ContextData As Object
ThisDrawing.Utility.GetSubEntity(Object2, PickedPoint, TransMatrix, ContextData, "Select Object in Xref to Open to: ")
Dim X As AcadExternalReference
X = ThisDrawing.ObjectIdToObject(ContextData(0))
Debug.Print(X.Path)
Dim DWGpath As String
DWGpath = X.Path
Dim Mytrue As Boolean
Dim Fullpath As String
Dim MyDWG As AcadDocument
Mytrue = True
Dim magnification As Double
Dim zoomScale As Double
Dim min, max
Try
If Mytrue = True Then
Mytrue = False
Fullpath = ThisDrawing.Path & "\" & DWGpath
MyApp.Application.Documents.Open(X.Path)
magnification = 10
Object2.GetBoundingBox(min, max)
MyApp.ZoomWindow(min, max)
MyApp.Application.ZoomExtents()
If MyApp.Application.ActiveDocument.ReadOnly = True Then
MsgBox("This file is read only")
Exit Sub
End If
zoomScale = 0.9
MyApp.ZoomScaled(zoomScale, AcZoomScaleType.acZoomScaledRelative)
Exit Sub
End If
'Else
Catch ex As Exception
MyDWG = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open(X.Path, False)
End Try
End Sub
End Class
-
I don't know about VB .Net, but with C# you have CommandMethod flags, and one of them is Session. What the Session flag does is allow the command to active within the whole session of acad instead of just the calling document, which seems to be the case here. Adding the Session flag may be all you need to do do have it stay within the current document. If not, then just make a check to see if the current document is the one you opened or is the one the routine was called from, and if it's not the one you want, change it before you issue the Zoom method.