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