Author Topic: Netloading programatically - with .dll contained in program  (Read 2837 times)

0 Members and 1 Guest are viewing this topic.

murrdpirate

  • Guest
I can programatically load a .dll into AutoCAD if the .dll exists on the user's hard drive using this:

Code: [Select]
myDWG.SendCommand("(command " & Chr(34) & "NETLOAD" & Chr(34) & " " & Chr(34) & "c:/myDLL.dll" & Chr(34) & ") ")
myDWG.SendCommand("myCommand ")

But I would like to have the .dll contained as a reference (or something) inside my program instead of separately located on the user's hard drive.  Is there a way to do this?

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Netloading programatically - with .dll contained in program
« Reply #1 on: July 10, 2010, 01:38:15 AM »
it doesn't make sense to me .. you have to be able to netload your dll into autocad in order to be able to load it into autocad ... i.e. you have to load it first so you can call the function to load another dll ...

Now, if you are talking about having multiple DLLs in one program and netloading a different dll from your program, you can do that as you show ... you could also compile the target dll as a resource in your dll, then dynamically extract that resource as required when you would like to load it ... of course, you can also sperate your files into seperate dlls that don't need to be loaded into autocad and simply call any exported functions by your loaded function.

I really dont fully understand the question .. perhaps some elaboration might help.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Peter Jamtgaard

  • Guest
Re: Netloading programatically - with .dll contained in program
« Reply #2 on: July 11, 2010, 03:33:54 PM »
In this thread

http://www.theswamp.org/index.php?topic=33538.0

I shared a function that would netload a function

The function included a line of code similar to this.

System.Reflection.Assembly.LoadFrom("c:\myDLL.dll")

Rather than calling a function from the myDWG.SendCommand, you can just call the public function directly from .net.

P

Here is some similar code including a function that checks to see if an application is loaded.

Code: [Select]
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime

Imports System
Imports System.Reflection
Imports System.Reflection.Assembly

Public Class NetloadClass

        Public Function Netload(ByVal strFileName As String) As Boolean
            Dim docThisDrawing As Document = _
                Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
            Dim blnReturn As Boolean = Boolean.FalseString
            Try
                Dim strFullName As String = _
                         HostApplicationServices.Current.FindFile(strFileName, _
                                                docThisDrawing.Database, FindFileHint.Default)
                docThisDrawing.Editor.WriteMessage(strFullName)
                If IsNetAssemblyLoaded(strFileName) = Boolean.TrueString Then
                    docThisDrawing.Editor.WriteMessage("File is already loaded")
                Else
                    System.Reflection.Assembly.LoadFrom(strFullName)
                    blnReturn = Boolean.TrueString
                End If
            Catch Ex As System.Exception
                docThisDrawing.Editor.WriteMessage("Error Loading Assembly: " + Ex.Message)
            End Try
            Return blnReturn
        End Function

' Checks to see if assembly is loaded.

        Public Function IsNetAssemblyLoaded(ByVal strFileName As String) As Boolean
            Dim objAssemblies() As Assembly = AppDomain.CurrentDomain.GetAssemblies
            Dim docThisDrawing As Document = _
                Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
            For Each objAssembly As Assembly In objAssemblies
                docThisDrawing.Editor.WriteMessage("" & objAssembly.FullName.ToString & vbLf & "")
                If UCase(objAssembly.ManifestModule.Name.ToString) = UCase(strFileName) Then
                    Return Boolean.TrueString
                End If
            Next
            Return Boolean.FalseString
        End Function
End Class
« Last Edit: July 12, 2010, 10:38:50 AM by PeterJ »

murrdpirate

  • Guest
Re: Netloading programatically - with .dll contained in program
« Reply #3 on: July 11, 2010, 04:12:21 PM »
Thanks Peter, that looks to be exactly what I need.  I have a couple of things I need to do at the moment, but I'll try that out later on and let everyone know how it went.

Keith, sorry, I should have been more clear.  I'm working on a Windows application that will open an instance of AutoCAD and then netload a .dll into it.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8753
  • AKA Daniel
Re: Netloading programatically - with .dll contained in program
« Reply #4 on: July 11, 2010, 07:10:55 PM »
I'm working on a Windows application that will open an instance of AutoCAD and then netload a .dll into it.

Then you will be working 'out of process' and Peter's routine probably won't work for you.