New LISP Expressions created with .NET (VB or C#)
Hey group,
I posted some .NET code for creating
two new lisp expressions that display
splash screens yesterday.
Would you all like to learn .NET as it relates to LISP?
We can build and share .NET applications that extend the power of LISP.
If you all are interested, I would be interested in your suggestions for new LISP expressions.
Suggestions? Ideas? Brainstorms?
P=
Re: New LISP Expressions created with .NET (VB or C#)
Expanding of LISP is what first motivated me to teach myself .NET development.
Now, I've only dabbled with .NET development (I feel), but am anxious to become more adept... I think this thread is a great idea, Peter. :beer:
2 Attachment(s)
Re: New LISP Expressions created with .NET (VB or C#)
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
Re: New LISP Expressions created with .NET (VB or C#)
Quote:
Originally Posted by
RenderMan
Expanding of LISP is what first motivated me to teach myself .NET development.
Now, I've only dabbled with .NET development (I feel), but am anxious to become more adept... I think this thread is a great idea, Peter. :beer:
Can you post a vs2010 express autocad template for .net?
Link to vs2010 express or later download?
Just in case others want to start playing with this.
Re: New LISP Expressions created with .NET (VB or C#)
Integrated Development Environment (IDE):
Visual Studio 2010 Express (Free, I have C++, C#, VB), or Visual Studio Professional (Paid)
Software Development Kit (SDK):
ObjectARX SDK for AutoCAD 2011, 2012, and 2013
AutoCAD .NET Wizards:
AutoCAD 2010-2012 .NET Wizard, and AutoCAD 2013 .NET Wizard, by ADN (Kean Walmsley), or AutoCAD .NET Add-in Wizard (AcadNetAddinWizard), by spiderinnet1
Article:
Why you should hold onto Visual Studio 2010 Express
Here's an update regarding the article I mentioned above:
Microsoft adds Windows 8 Desktop support to Visual Studio 2012 Express
... That should get you started. :beer:
Also useful:
AutoCAD .NET Developer Guide
.NET Getting Started
Autodesk My First Plug-in Training, supports AutoCAD, Inventor, and Revit (no Civil 3D)
Re: New LISP Expressions created with .NET (VB or C#)
Thanks, I would also be looking at this a lot. I've started something previously, but my aim was to extent lisp through ARX instead: http://alisp-ext.wikidot.com/
Although the more the better right?
BTW, Anyone have similar issues with that Wizzard not wanting to install properly? Neither the DotNet Wizzard, nor the ARX Wizzard wants to install (on VS2008/10). I'm on Win7-64 bit ... perhaps due to 64? I've even tried on another PC with only VS Express 2008, and then VS-E 2010, still doesn't want to install. Anyhow, it's no biggy, I simply made a template of my own - which does most of what the wizzard would have done anyway.
Re: New LISP Expressions created with .NET (VB or C#)
Quote:
Originally Posted by
irneb
BTW, Anyone have similar issues with that Wizzard not wanting to install properly? Neither the DotNet Wizzard, nor the ARX Wizzard wants to install (on VS2008/10). I'm on Win7-64 bit ... perhaps due to 64? I've even tried on another PC with only VS Express 2008, and then VS-E 2010, still doesn't want to install. Anyhow, it's no biggy, I simply made a template of my own - which does most of what the wizzard would have done anyway.
Welcome, my zef slang bro :beer:
My IT did experience an issue with the install of VSE2010 originally, until I told them to check out the instructional video included in the ZIP download. That seemed to have fixed the issue. All has been well for +/-1 year.
I could use more templates myself, at minimum for Civil 3D & AutoCAD MEP.
Re: New LISP Expressions created with .NET (VB or C#)
Thanks yes, I've gone through all the tutorials. Even any others I could find using google. Unfortunately it simply will not install properly. It either gives me an error message about not being able to install some files or simply closes without any message. I've tried all sorts of tricks (re admin rights, etc. even safe mode). But still there's nothing about AutoDesk's DotNet / ARX available in VS's Create Project dialog (not in any of the categories at all).
But as I've stated, it's not truly a big deal. A template does all those things for you. You just need to setup the template to your own desire and mapping/using to the correct assemblies. You can even get a template to do more than the wizzard does - because you can edit each file of it manually. So for me I've given up trying the wizzard and just use my template instead.