.NET

Reply
Active Contributor
cokhitp
Posts: 31
Registered: ‎02-19-2011
Message 1 of 17 (687 Views)

Vb.net & Autocad: Exception from HRESULT: 0x8007007E

687 Views, 16 Replies
11-27-2012 03:58 AM

Hello to everybody.

 

I have tried to write a code that can update attribute data in block of autocad file.

 

I found alot of example in this forum, but i dont know why my programe can not work.

 

My PC is winXP, VS2008, autocad2009.

 

1. This code is work ofcouse:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        MsgBox("hello")
    End Sub

 

2. But this one does not work:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        MsgBox("hello")
        Dim myBT As DatabaseServices.BlockTable    
    End Sub

 

As long as i insert in the code which relative to reference .dll; i got error: "The specified module could not be found. (Exception from HRESULT: 0x8007007E)"

It means that problem is my PC sysem, sofware... not about the code.

 

Please help me to fix it, i spent two but still not found the reason.

 

 

Here the code i used:

 Function PopulateOIDCs(ByVal BlockName As String) _
As DatabaseServices.ObjectIdCollection
        Dim myBT As DatabaseServices.BlockTable
        Dim myBTR As DatabaseServices.BlockTableRecord
        Dim myBTRE As DatabaseServices.SymbolTableEnumerator
        Dim myDB As DatabaseServices.Database
        Dim myTransMan As DatabaseServices.TransactionManager
        Dim myTrans As DatabaseServices.Transaction
        Dim myOIDs As New DatabaseServices.ObjectIdCollection
        Dim myOIDs2 As DatabaseServices.ObjectIdCollection
        Dim I As Long
        Dim acDoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
        myDB = acDoc.Database

        myTransMan = myDB.TransactionManager
        myTrans = myTransMan.StartTransaction
        myBT = myDB.BlockTableId.GetObject(DatabaseServices.OpenMode.ForRead)
        myBTR = myBT(BlockName).GetObject(DatabaseServices.OpenMode.ForRead)
        myOIDs2 = myBTR.GetBlockReferenceIds(True, False)
        For I = 1 To myOIDs2.Count
            myOIDs.Add(myOIDs2.Item(I - 1))
        Next
        myBTRE = myBT.GetEnumerator
        While myBTRE.MoveNext
            myBTR = myBTRE.Current.GetObject(DatabaseServices.OpenMode.ForRead)
            If myBTR.IsLayout = False Then
                Select Case myBTR.IsAnonymous
                    Case True
                        myOIDs2 = myBTR.GetBlockReferenceIds(True, False)
                        If myOIDs2.Count > 0 Then
                            Dim myBRef As DatabaseServices.BlockReference
                            myBRef = myOIDs2(0).GetObject(DatabaseServices.OpenMode.ForRead)
                            Dim myBTR2 As DatabaseServices.BlockTableRecord
                            myBTR2 = myBRef.DynamicBlockTableRecord.GetObject( _
                            DatabaseServices.OpenMode.ForRead)

                            If myBTR2.Name.CompareTo(BlockName) = 0 Then
                                For I = 1 To myOIDs2.Count
                                    myOIDs.Add(myOIDs2.Item(I - 1))
                                Next
                            End If
                        End If
                End Select
            End If
        End While
        myTrans.Dispose()
        myTransMan.Dispose()
        Return myOIDs
    End Function

Valued Contributor
sszabo
Posts: 86
Registered: ‎09-05-2012
Message 2 of 17 (671 Views)

Re: Vb.net & Autocad: Exception from HRESULT: 0x8007007E

11-27-2012 06:03 AM in reply to: cokhitp

When you say "but this doesn't work" I assume you mean that's when you are getting the COM error HRESULT: 0x8007007E?  If yes, make sure that

1. acdbmgd in your project references is pointing to the correct autocad version's directory.

2. your DLL is registered with COM (regasm /tlb yourdll.dll) and you are netloading the registered version not some old version.

*Expert Elite*
norman.yuan
Posts: 997
Registered: ‎04-27-2009
Message 3 of 17 (666 Views)

Re: Vb.net & Autocad: Exception from HRESULT: 0x8007007E

11-27-2012 06:32 AM in reply to: cokhitp

Just my guess:

 

You are doing an stand-alone EXE application, aren't you? If so, you CANNOT use AutoCAD managed .NET API DLLs (acadmgd.dll/acmgd.dll).

Active Contributor
cokhitp
Posts: 31
Registered: ‎02-19-2011
Message 4 of 17 (659 Views)

Re: Vb.net & Autocad: Exception from HRESULT: 0x8007007E

11-27-2012 07:18 AM in reply to: sszabo

Dear sszabo;

 

"but this doesn't work" I assume you mean that's when you are getting the COM error HRESULT: 0x8007007E? -> Right.

 

1. acdbmgd in your project references is pointing to the correct autocad version's directory. --> I add .dll reference from the folder that install autocad.

 

2. your DLL is registered with COM (regasm /tlb yourdll.dll) and you are netloading the registered version not some old version. -> could you explain more?

 

Note: i format my PC, install VS and autocad. Can not happen that there is old .dll version.

 

Please help!

Active Contributor
cokhitp
Posts: 31
Registered: ‎02-19-2011
Message 5 of 17 (659 Views)

Re: Vb.net & Autocad: Exception from HRESULT: 0x8007007E

11-27-2012 07:22 AM in reply to: norman.yuan

Dear mornan.yuan

 

Yes, im making an stand-alone .exe application.

 

Which case i can use "AutoCAD managed .NET API DLLs (acadmgd.dll/acmgd.dll)"?

 

Now, for my application / stand-alone .exe which way i should follow?

 

Please help!

Valued Contributor
sszabo
Posts: 86
Registered: ‎09-05-2012
Message 6 of 17 (651 Views)

Re: Vb.net & Autocad: Exception from HRESULT: 0x8007007E

11-27-2012 07:42 AM in reply to: cokhitp

I assumed you were working on an in-process DLL project.  norman.yuan is correct: you cannot do this from standalone EXE.  If you must control ACAD session from standalone EXE you have several options:

1. Write an In - PROC COM dll and expose it through .NET remoting or WCF to standalone applications

2. Write in proc .NET dll and do the same as above.

 

There is no way you can avoid the NETLOAD command either way.  You cannot use acdbmgd, accoremgd acmgd etc from standalone exe projects.

*Expert Elite*
norman.yuan
Posts: 997
Registered: ‎04-27-2009
Message 7 of 17 (646 Views)

Re: Vb.net & Autocad: Exception from HRESULT: 0x8007007E

11-27-2012 07:52 AM in reply to: cokhitp

Just my opinion:

 

1. Doing an EXE to automate AutoCAD is rarely an best solution, especailly the target user is AutoCAD user: If they use AutoCAD with their computer, why they have to run another application, which requires AutoCAD being running?

 

2. If you determined the external EXE app is the way to go, you can easily talk to AutoCAD from your app via AutoCAD's COM API. For your task (update attribute in block), the COM API is easy enough and more than enough to your task;

 

3. If you do not mind to make thing unnecessarily complicated, you can create DLL in .NET API and expose it to COM. Then you need to NETLOAD the DLL into AutoCAD before your app can communicate to your code running inside AutoCAD via COM.

 

4. You can also do DLL in .NET API and expose it via WCF endpoint. Then you can create a pure NET EXE app that communicate to your code in AutoCAD via WCF. Again, if you do not mind to make things more complicated to the task in hand.

 

Better and easy solution might be just doing it inside AutoCAD, because you need to run AutoCAD anyway.

Active Contributor
cokhitp
Posts: 31
Registered: ‎02-19-2011
Message 8 of 17 (642 Views)

Re: Vb.net & Autocad: Exception from HRESULT: 0x8007007E

11-27-2012 07:58 AM in reply to: norman.yuan

Dear norman and sszabo

 

The reason is i want to have a programe that automactic open alot of autocad drawing and take data from database and put data to attribute value.

 

And also after change attribute value, it can connect to printer to print.

 

Could you help me to define which way is the best?

 

 

 

Valued Contributor
sszabo
Posts: 86
Registered: ‎09-05-2012
Message 9 of 17 (629 Views)

Re: Vb.net & Autocad: Exception from HRESULT: 0x8007007E

11-27-2012 08:22 AM in reply to: cokhitp

Just write your code that calls into ACAD core functionality as a COM DLL, register it using regasm yourdll.dll and write a standalone APP that connects to the running ACAD session, netloads your DLL and calls your functions such as PopulateOIDCs inside that DLL either via COM or .NET:

 

 

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim progID As String = "AutoCAD.Application.17"

        Dim acApp As AcadApplication

        acApp = Marshal.GetActiveObject(progID)

        acApp.Visible = True

        acApp.ActiveDocument.SendCommand("(command " & Chr(34) + "NETLOAD" & Chr(34) & ConvertToDoubleSlash("yourfull/path/to/yourdll.dll") & ")")

    End Sub

 

 

 You might have to fiddle with the exact command syntax, haven't actually ran it.

Active Contributor
cokhitp
Posts: 31
Registered: ‎02-19-2011
Message 10 of 17 (614 Views)

Re: Vb.net & Autocad: Exception from HRESULT: 0x8007007E

11-27-2012 03:46 PM in reply to: sszabo

Dear sszabo

 

The code got this error: "ConvertToDoubleSlash is not declared". Could you fix it?

 

Honestly, im newbie with this.

 

Thank so much.

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.