Here is place to start.
Currently a lisp programmer must use the command pipe to load a dotnet assembly
(command "netload" <myassemblyfullname>)
The code below creates a lisp expression for netloading (including in reactors)
(netload <myassemblyfullname>)
Compiled for AutoCAD 2010-12.
NetloadAssembly.dll can be loaded if it is in the search path or a full path is supplied
(command "netload" (findfile "netloadassembly.dll"))
The netload.zip is the project.
P=
Code:
' (C) Copyright 2002-2005 by Autodesk, Inc.
'
' Permission to use, copy, modify, and distribute this software in
' object code form for any purpose and without fee is hereby granted,
' provided that the above copyright notice appears in all copies and
' that both that copyright notice and the limited warranty and
' restricted rights notice below appear in all supporting
' documentation.
'
' AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
' AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
' MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
' DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
' UNINTERRUPTED OR ERROR FREE.
'
' Use, duplication, or disclosure by the U.S. Government is subject to
' restrictions set forth in FAR 52.227-19 (Commercial Computer
' Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
' (Rights in Technical Data and Computer Software), as applicable.
'
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
Imports objACADApplication = Autodesk.AutoCAD.ApplicationServices.Application
Imports System
Imports System.Reflection
Imports System.Reflection.Assembly
Imports System.Security.Permissions
Imports System.Threading
'<Assembly: AssemblyVersion("6.12.2010.0")>
' Lisp function for loading a .net dll
Public Class vbvlClass
<LispFunction("Netload")> _
Public Function Netload(ByVal rbfNetAssemblyFile As ResultBuffer)
Dim tpvReturn As TypedValue = New TypedValue(LispDataType.Nil, -1)
Try
Dim arrNetAssemblyFile As TypedValue() = rbfNetAssemblyFile.AsArray()
If arrNetAssemblyFile.Length > 0 Then
Dim strFileName As String = arrNetAssemblyFile(0).Value.ToString
If Netload(strFileName) = Boolean.TrueString Then
Return New TypedValue(LispDataType.T_atom, -1)
tpvReturn = New TypedValue(LispDataType.T_atom, -1)
End If
Else
Princ("; error: too few arguments")
End If
Catch Ex As System.Exception
Princ("; error Loading Assembly: " & Ex.Message)
End Try
Return tpvReturn
End Function
' Function to load a net assembly if a .net assembly is loaded
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)
Princ(strFullName)
If IsNetAssemblyLoaded(strFileName) = Boolean.TrueString Then
Princ("; file is already loaded")
Else
System.Reflection.Assembly.LoadFrom(strFullName)
blnReturn = Boolean.TrueString
End If
Catch Ex As System.Exception
Princ("Error Loading Assembly: " + Ex.Message)
End Try
Return blnReturn
End Function
' Function ResultBuffer In TypedValue Out to test if a .net assembly is loaded
<LispFunction("IsNetAssemblyLoaded")> _
Public Function IsNetAssemblyLoaded(ByVal rbfNetAssemblyFile As ResultBuffer)
Dim tpvReturn As TypedValue = New TypedValue(LispDataType.Nil, -1)
Dim objAssemblies() As Assembly = AppDomain.CurrentDomain.GetAssemblies
' Const strDelimiter As String = "Version="
Try
Dim arrNetAssemblyFile As TypedValue() = rbfNetAssemblyFile.AsArray()
If arrNetAssemblyFile.Length > 0 Then
Dim strFileName As String = arrNetAssemblyFile(0).Value.ToString
If IsNetAssemblyLoaded(strFileName) = Boolean.TrueString Then
tpvReturn = New TypedValue(LispDataType.T_atom, -1)
End If
End If
Catch Ex As System.Exception
Princ("Error Testing Assembly: ")
End Try
Return tpvReturn
End Function
' Overload Function String In Boolean Out to test if a .net assembly is loaded
Public Function IsNetAssemblyLoaded(ByVal strFileName As String) As Boolean
'MsgBox("IsNetAssemblyLoaded")
Dim objAssemblies() As Assembly = AppDomain.CurrentDomain.GetAssemblies
For Each objAssembly As Assembly In objAssemblies
If UCase(objAssembly.ManifestModule.Name.ToString) = UCase(strFileName) Then
Princ(objAssembly.FullName.ToString)
Return Boolean.TrueString
End If
Next
Return Boolean.FalseString
End Function
' Simple print to command window function
Public Function Princ(ByVal strPrintString) As Boolean
Dim docThisDrawingP As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
docThisDrawingP.Editor.WriteMessage("" & strPrintString & vbLf & "")
Return Nothing
End Function
End Class