TheSwamp

Code Red => .NET => Topic started by: MickD on December 16, 2009, 05:52:16 PM

Title: [Boo] Simple Boo acad application
Post by: MickD on December 16, 2009, 05:52:16 PM
A simple Boo app to whet the appetite :)

Just like Python it's quite easy and enjoyable to write and easy to implement.
I used shapdev 3.1.1

The one and only App class, don't forget to ref in the acmgd.dll and acdbmgd.dll

App.boo
Code: [Select]
namespace BOOAcad1

import System
import System.IO
import System.Reflection
import Autodesk.AutoCAD.Runtime
import Autodesk.AutoCAD.DatabaseServices
import Autodesk.AutoCAD.EditorInput
import Autodesk.AutoCAD.ApplicationServices

import Autodesk.AutoCAD.ApplicationServices.Application as acadApp

# the one and only app class, here you can do any program initialisation etc.
public class App(IExtensionApplication):

public static appPath as string

public def Initialize():
try:
appPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)

//load the hlr api, an example of getting the version to load version specific modules/app's
// note you can also use the C style of commenting.
ed = acadApp.DocumentManager.MdiActiveDocument.Editor
ed.WriteMessage(('\nAutoCAD Version: ' +
Autodesk.AutoCAD.ApplicationServices.Application.Version.ToString()
+ ' '))
# seems to handle multiple lines for a single line of code pretty well :)

if Autodesk.AutoCAD.ApplicationServices.Application.Version.Major == 17:
Autodesk.AutoCAD.Runtime.SystemObjects.DynamicLinker.LoadModule('AsdkHlrApi17.dbx', true, true)
else:
ed.WriteMessage('\nSorry, hlr engine not available in this version yet!')

ed.WriteMessage('\n Loading BOOAcad application...\n')

except acEx as Autodesk.AutoCAD.Runtime.Exception:
ed = acadApp.DocumentManager.MdiActiveDocument.Editor
ed.WriteMessage(('\nError: ' + acEx.Message))
return

public def Terminate():
pass

# another gotcha! this would normally be placed at the top but needs to be here for some reason(?)
[assembly: ExtensionApplication(typeof(BOOAcad1.App))]
[assembly: CommandClass(typeof(BOOAcad1.Commands))]

And a simple commands class - Commands.boo
Code: [Select]
# note where our namespace is placed, in C# it would be just before our
# class def's after the imports!
namespace BOOAcad1

import System
import System.IO
import System.Runtime.InteropServices
import Autodesk.AutoCAD.ApplicationServices
import Autodesk.AutoCAD.DatabaseServices
import Autodesk.AutoCAD.Geometry
import Autodesk.AutoCAD.Runtime
import Autodesk.AutoCAD.EditorInput

# this is similar to the 'using' directive in C# to save some typing ;)
import Autodesk.AutoCAD.ApplicationServices.Application as acadApp

# Our basic class to house all of our commands
class Commands:
"""Description of Commands Class."""

public def constructor():
pass

# a simple test command
[CommandMethod('BOO1')] #our command attribute
public def BOOtest1(): #and the method to run
ed = acadApp.DocumentManager.MdiActiveDocument.Editor
ed.WriteMessage("\n BOO! it works!!")

I'll post some more examples of the trickier aspects as I come to them.
Cheers.