And then just for fun ... here's the VB code converted to Ruby. No errors noted as per the C# conversion, though from the code I'm a bit concerned that it didn't even note a warning
Code:
require "mscorlib"
require "Autodesk.AutoCAD.ApplicationServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
require "Autodesk.AutoCAD.DatabaseServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
require "Autodesk.AutoCAD.EditorInput, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
require "Autodesk.AutoCAD.Runtime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" #Imports objACADApplication = Autodesk.AutoCAD.ApplicationServices.Application
require "System.Reflection, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
class NetloadClass
def Netload(rbfNetAssemblyFile) # <summary> # Lisp function for loading a .net dll # LISP Syntax: (netload "mynetassembly.dll") # </summary>
begin
arrNetAssemblyFile = rbfNetAssemblyFile.AsArray()
if arrNetAssemblyFile.Length > 0 then
strFileName = self.arrNetAssemblyFile(0).Value.ToString
if self.Netload(strFileName) then
return TypedValue.new(LispDataType.T_atom, -1)
end
end
rescue System.Exception => Ex
self.WriteMessage("; error Loading Assembly: " + Ex.Message + vbLf)
ensure
end
return TypedValue.new(LispDataType.Nil, -1)
end
# <summary> # Function to load a net assembly (over load of lisp version for .net) # </summary>
def Netload(strFileName)
docThisDrawing = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
begin
strFullName = HostApplicationServices.Current.FindFile(strFileName, docThisDrawing.Database, FindFileHint.Default)
self.WriteMessage(strFullName + vbLf)
System.Reflection.Assembly.LoadFrom(strFullName)
return true
rescue System.Exception => Ex
self.WriteMessage("Error Loading Assembly: " + Ex.Message + vbLf)
ensure
end
return false
end
# <summary> # Simple print to command window function # </summary>
def WriteMessage(strPrintString)
docThisDrawingP = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
docThisDrawingP.Editor.WriteMessage("" + strPrintString + vbLf + "")
return true
return false
end
end
And then the Python version:
Code:
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.AutoCAD.EditorInput import *
from Autodesk.AutoCAD.Runtime import * #Imports objACADApplication = Autodesk.AutoCAD.ApplicationServices.Application
from System.Reflection import *
class NetloadClass(object):
def Netload(self, rbfNetAssemblyFile): # <summary> # Lisp function for loading a .net dll # LISP Syntax: (netload "mynetassembly.dll") # </summary>
try:
arrNetAssemblyFile = rbfNetAssemblyFile.AsArray()
if arrNetAssemblyFile.Length > 0:
strFileName = self.arrNetAssemblyFile(0).Value.ToString
if self.Netload(strFileName):
return TypedValue(LispDataType.T_atom, -1)
except System.Exception, Ex:
self.WriteMessage("; error Loading Assembly: " + Ex.Message + vbLf)
finally:
return TypedValue(LispDataType.Nil, -1)
def Netload(self, strFileName):
""" <summary>
Function to load a net assembly (over load of lisp version for .net)
</summary>
"""
docThisDrawing = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
try:
strFullName = HostApplicationServices.Current.FindFile(strFileName, docThisDrawing.Database, FindFileHint.Default)
self.WriteMessage(strFullName + vbLf)
System.Reflection.Assembly.LoadFrom(strFullName)
return True
except System.Exception, Ex:
self.WriteMessage("Error Loading Assembly: " + Ex.Message + vbLf)
finally:
return False
def WriteMessage(self, strPrintString):
""" <summary>
Simple print to command window function
</summary>
"""
docThisDrawingP = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
docThisDrawingP.Editor.WriteMessage("" + strPrintString + vbLf + "")
return True
return False
Also didn't mention any conversion problems (similar to Ruby), though I'd expect something along the same lines (Python & Ruby are slightly related).
I've tried converting to the other built-in language "Boo", but it seems there are issues since Boo doesn't allow for the Option statement (Switch in C#):
Code:
8 conversion errors:
Class.vb(72,9): BCE0000: old VB-style exception handling is not supported.
My Project\Application.Designer.vb(11,1): BCE0000: Option statement is not supported.
My Project\Application.Designer.vb(12,1): BCE0000: Option statement is not supported.
My Project\Resources.Designer.vb(11,1): BCE0000: Option statement is not supported.
My Project\Resources.Designer.vb(12,1): BCE0000: Option statement is not supported.
My Project\Settings.Designer.vb(11,1): BCE0000: Option statement is not supported.
My Project\Settings.Designer.vb(12,1): BCE0000: Option statement is not supported.
My Project\Settings.Designer.vb(59,1): BCE0000: Only one namespace declaration per file is supported.
Note, I've not yet tested the code. Will do so after work