Using ironscheme to script with Autodesk Revit

Dec 15, 2012 at 4:20 AM
Edited Dec 16, 2012 at 1:13 PM

As Autodesk AutoCAD supporting Autolisp programing, I recently try to embed ironscheme into Autodesk Revit application inspired by the RevitPythonShell and RevitRubyShell project. It almost works.  Because I am not quite good at programing, I have some questions.

(import
   (rnrs)
   (ironscheme clr)
   (ironscheme clr shorthand)
)

(clr-reference RevitAPI)
(clr-reference RevitAPIUI)

(clr-using Autodesk.Revit)
(clr-using Autodesk.Revit.UI)
(clr-using Autodesk.Revit.DB)

(define doc
   (with-clr-type ((_app UIApplication))
      (_app : ActiveUIDocument : Document)))

(let-clr-type ((t (DB.Transaction doc "Create Line")))
   (t : Start ())
   (let ((origin (clr-static-prop-get DB.XYZ Zero))
         (normal (clr-static-prop-get DB.XYZ BasisZ)))
      (with-clr-type ((_app UIApplication) (doc DB.Document))
         (doc : FamilyCreate : NewSketchPlane 
                ((_app : Application : Create : NewPlane (normal origin))))))
   (t : Commit ()))

 

1. Althongh I use (clr-using Autodesk.Revit.DB),  I still need to specify the namespace as "DB.XYZ". But RevitAddin in C#, after referencing the RevitAPI.dll and RevitAPIUI.dll and specify "using Autodesk.Revit.DB", I can use the property just as "XYZ".

2. The Above code works OK. But I would like to change

      (with-clr-type ((_app UIApplication) (doc DB.Document))
         (doc : FamilyCreate : NewSketchPlane 
                ((_app : Application : Create : NewPlane (normal origin))))))

to something like this

      (with-clr-type ((_app UIApplication) (doc DB.Document))
         (set! plane (_app : Application : Create : NewPlane (normal origin)))
         (doc : FamilyCreate : NewSketchPlane (plane))))

It fails with

error: &who: "clr-call"

&message: "member could not be resovled on type: FamilyItemFactory"

&syntax:

form: ('#f 'NewSketchPlane (clr-call-internal 'DB.Document 'get_FamilyCreate g$doc$1056$ERaTk) g$plane$2377$ERaTk)

subform: "NewSketchPlane"

The "NewSketchPlane" method is overloaded. 

Any suggestions?

Thanks,

Wu Baorong

Coordinator
Dec 18, 2012 at 5:50 PM

Hi

Sorry for replying so late.

I have been looking for the API (class reference) of the mentioned assemblies, but it seems 'very' proprietary (and not publicly available).

For the first issue, it might be related to to nested classes or duplicate classes in both namespaces.

As for the second, due to the overload (thanks for mentioning that!) it fails to find a candidate (I think).

This might be resolvable by hinting the type to the compiler, but unfortunately this is not that easy with the shorthand library.

Adding (with-clr-type ((plane <the actual type>)) (doc : ...)) might do the job.

Sorry I cannot help more.

leppie

Dec 20, 2012 at 5:24 AM

Hi, leppie.

Thanks for your explaination and help. I'll try.

Disregarding the two issues mentioned above, writing ironscheme scripts to manipulate Revit (the wide-used 3D BIM software) is really interesting.  It gives me the feel as writing Autolisp code for AutoCAD. :-)

Thanks for your great job!

Wu Baorong