TheSwamp

Code Red => VB(A) => Topic started by: Amsterdammed on November 12, 2007, 04:37:24 AM

Title: Zoom into acad object out off Excel
Post 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
Title: Re: Zoom into acad object out off Excel
Post by: SomeCallMeDave on November 12, 2007, 09:11:46 AM
If you have the handle,  you can get the entity, then get the BoundingBox, then ZoomWindow using the BoundingBox.

Something like

Code: [Select]
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
Title: Re: Zoom into acad object out off Excel
Post by: Amsterdammed on November 12, 2007, 09:19:51 AM
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
Title: Re: Zoom into acad object out off Excel
Post by: SomeCallMeDave on November 12, 2007, 10:56:00 AM
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

Code: [Select]
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

Title: Re: Zoom into acad object out off Excel
Post by: Amsterdammed on November 14, 2007, 04:20:29 AM
Dave,

sorry for the late reply but I was out in the field on the construction site. I get a problem with
Code: [Select]
Public acadapp As AcadApplication

I know there is some box I have to check to load the library, but which one??

Thanks

Bernd
Title: Re: Zoom into acad object out off Excel
Post by: Amsterdammed on November 14, 2007, 05:22:53 AM
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?