Author Topic: F# script (fsx-file) & AutoCAD  (Read 2216 times)

0 Members and 1 Guest are viewing this topic.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
F# script (fsx-file) & AutoCAD
« on: October 19, 2011, 12:17:50 AM »
Hi all.
Whether it is possible to run in AutoCAD a fsx-file of F# script? For example - the script, which will print all layer names for the current drawing in AutoCAD console.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: F# script (fsx-file) & AutoCAD
« Reply #1 on: October 20, 2011, 02:20:22 PM »
I have experience of a spelling of plug-ins for AutoCAD in C# language (i.e. I not the beginner in this question). But I never wrote in language F#. Now me all interests F#, but only its scripts.

It is interesting to me, whether it is possible in AutoCAD to launch the scripts written on F#. Not the dll-files written on F#, namely scripts (fsx-files). A script such which could work with documents AutoCAD as the dll-files loaded by command NETLOAD can do it.

I read the book about language F#. Has written such script (I hope that without errors):

HelloWorld.fsx file:
Code: [Select]
(*
This script can lie anywhere. However it somehow should find always the necessary dll-files
for the operation, for example: AcDbMgd.dll, AcMgd.dll and others.
*)

//Path to AcDbMgd.dll and AcMgd.dll libraries
#I @"C:\Program Files\AutoCAD 2009"

//Loading libraries
#r "AcMgd.dll"
#r "AcDbMgd.dll"

//namespace
open Autodesk.AutoCAD.ApplicationServices

//Print message in AutoCAD console
Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage "Hello AutoCAD from F# script!!!"

How can I run it script in AutoCAD?
I haven't found at KEAN WALMSLEY the information on the question specified by me.

Thank you.

n.yuan

  • Bull Frog
  • Posts: 348
Re: F# script (fsx-file) & AutoCAD
« Reply #2 on: October 20, 2011, 03:31:57 PM »
No, you cannot (as if it is AutoCAD script or LISP). It must be compiled as .NET DLL and be NETLOADed. After all, F# is a .NET language, in spite is functional nature. The only place you can use like a script (enter a or more line of code and execute immediately), AFAIK, in the F# interactive window in VS, which would not be useful in your case.

kaefer

  • Guest
Re: F# script (fsx-file) & AutoCAD
« Reply #3 on: October 20, 2011, 03:47:10 PM »
It is interesting to me, whether it is possible in AutoCAD to launch the scripts written on F#. Not the dll-files written on F#, namely scripts (fsx-files). A script such which could work with documents AutoCAD as the dll-files loaded by command NETLOAD can do it.

It isn't, unless you are prepared to integrate FSI (the F# REPL interactive environment) into AutoCAD. This hasn't been done, to my knowledge, FSI being intended to run inside Visual Studio or on the console.

On the other hand you could use F# script (.fsx) files as a kind of lightweight project system and compile them into standard assemblies loadable from AutoCAD, even without Visual Studio.