Author Topic: [Boo] Simple Boo acad application  (Read 1892 times)

0 Members and 1 Guest are viewing this topic.

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
[Boo] Simple Boo acad application
« 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.
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien