TheSwamp
Code Red => VB(A) => Topic started by: Amsterdammed on November 12, 2007, 04:37:24 AM
-
Hello everybody,
I'm busy with a Link between an Acad drawing and a dbase in excel. I need to do it in Excel because of my collages, they have access phobics.
I allready have (thanks to this forum) made my link from Acad to excel, written the info including the acad handle to Excel. What would be a nice feature is to zoom to the object by selecting it in Excel, so i must open the dwg , and get a macro run there in the dwg that looks for the entity and zooms to it.
Any Ideas?
Thanks in Advance,
Bernd
-
If you have the handle, you can get the entity, then get the BoundingBox, then ZoomWindow using the BoundingBox.
Something like
Public Sub ZoomBB(pHandle As String)
Dim oEnt As AcadEntity
Dim vMin As Variant
Dim vMax As Variant
Set oEnt = ThisDrawing.HandleToObject(pHandle)
oEnt.GetBoundingBox vMin, vMax
ThisDrawing.Application.ZoomWindow vMin, vMax
End Sub
UCS and various others thing will probably impact the zooming and the code will have to incorporate that
-
Dave,
I understand that part, the thing is that i want to trigger this out of an Excel file, so I know the filename and location of the dwg and the handle-> so what i need is to know hoe to open the drawing AND go on with the code i the drawing
Thanks,
Bernd
-
I have never (up until now) operated AutoCad from within Excel
But I created 2 Command Buttons in Excel. I have the handle of a few objects in some cells.
I click CommandButton1 to create a running instance of Excel. Then click in one of the 'handle' cells to make that cell active.
Then click CommandButton2 to zoom to the current obejct. Then you can select another handle and click CommandButton2 to zoom to that one....
I'm sure some of the experts can show a MUCH better way to handle the creation of the AutoCad instance and control the closing of AutoCAD
Option Explicit
Public acadapp As AcadApplication
Public oDwg As AcadDocument
Private Sub CommandButton1_Click()
'Create new instance of AutoCad
Dim strAcadFile As String
Set acadapp = CreateObject("Autocad.Application")
acadapp.Visible = True
strAcadFile = "c:\jobs\XLtest.dwg"
Set oDwg = acadapp.Documents.Open(strAcadFile)
End Sub
Private Sub CommandButton2_Click()
'zoom to the object whose handle is in the current cell
Dim strHandle As String
Dim vMax As Variant
Dim vMin As Variant
Dim oEnt As AcadEntity
If acadapp Is Nothing Then
CommandButton1_Click
End If
strHandle = ActiveCell.Value
Set oEnt = oDwg.HandleToObject(strHandle)
oEnt.GetBoundingBox vMin, vMax
acadapp.ZoomWindow vMin, vMax
End Sub
-
Dave,
sorry for the late reply but I was out in the field on the construction site. I get a problem withPublic acadapp As AcadApplication
I know there is some box I have to check to load the library, but which one??
Thanks
Bernd
-
Dave,
i found that, but i egt now an error when it decares the entity,
code 13, types don't match?
Any Idea what is going wrong?