Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/gileCAD/AutoCAD-Fsharp-Project-Template

An F# Visual Studio Project Template for an AutoCAD Plugin.
https://github.com/gileCAD/AutoCAD-Fsharp-Project-Template

Last synced: 2 months ago
JSON representation

An F# Visual Studio Project Template for an AutoCAD Plugin.

Lists

README

        

# AutoCAD-Fsharp-Project-Template
### F# Visual Studio Project Template for an AutoCAD Plugin.
These templates allow to start a F# project for an AutoCAD plugin in Visual Studio . They are designed to automatically start the specified AutoCAD version and load the assemby when starting the debugging.
'AutoCAD R24 Fsharp Project Template' is to be used with AutoCAD prior to 2025 (targets .NET Framework).
'AutoCAD R25 Fsharp Project Template' is to be used with AutoCAD 2025 and later (targets .NET 8).

For AutoCAD 2016 and later versions it is imperative that the LEGACYCODESEARCH system variable is set to 1 to allow automatic loading of the assembly.

The helpers.fs file contains helpers to write some common AutoCAD tasks in a more declarative functional style.
The command.fs file contains an example of command.

Example using pipeline style to erase lines shorter than a supplied value
```F#
let eraseShortLines minLength =
use tr = Active.db.TransactionManager.StartTransaction()

Active.db
|> getModelSpace OpenMode.ForRead
|> getObjects OpenMode.ForRead
|> Seq.filter (fun l -> l.Length < minLength)
|> upgradeOpen
|> Seq.iter (fun l -> l.Erase())

tr.Commit()
```

Example using a prompts workflow to get the center and radius of a circle
```F#
[]
let drawCircle () =
let inputs =
prompt {
let! ppr = Active.ed.GetPoint("\nCenter: ")
let! pdr = Active.ed.GetDistance(ppr.Value, "\nRadius: ")
return (ppr.Value, pdr.Value)
}

match inputs with
| None -> ()
| Some (center, radius) ->
use tr = Active.db.TransactionManager.StartTransaction()

Active.db.CurrentSpaceId
|> getObject OpenMode.ForWrite
|> addEntity (new Circle(center, Vector3d.ZAxis, radius))
|> ignore

tr.Commit()
```

### Editing the template files
In order for the template to work, the paths to the acad.exe file and to the autoCAD libraries must match those on the local computer.

#### Properties\launchSettings.json
The path to the acad.exe file of the AutoCAD version to be launched at debugging startup must be consistent with that of the local computer.
``` json
{
"profiles": {
"$safeprojectname$": {
"commandName": "Executable",
"executablePath": "C:\\Program Files\\Autodesk\\AutoCAD 2022\\acad.exe",
"commandLineArgs": "/nologo /b \"start.scr\""
}
}
}
```

#### FsharpPluginNetFramework.fsproj / FsharpPluginNet8.fsproj
The MSBuild project file (.fsproj) is an xml file that describe and control the process of generation of the applications.

The paths to the AutoCAD libraries referenced by the project must be consistent with those of the local computer.
```xml



F:\ObjectARX 2022\inc\AcCoreMgd.dll
false


F:\ObjectARX 2022\inc\AcDbMgd.dll
false


F:\ObjectARX 2022\inc\AcMgd.dll
false


```
It is preferable that the required version of .NET (Framework) is the one installed by the targeted AutoCAD version (see [this page](https://help.autodesk.com/view/OARX/2024/ENU/?guid=GUID-450FD531-B6F6-4BAE-9A8C-8230AAC48CB4)).
```xml

net48
```
#### MyTemplate.vstemplate
This file describes the template.

Name and Desription of the template.
```xml

Fsharp Plugin for AutoCAD R24
Fsharp Plugin for AutoCAD R24 (.NET Framework)
```
Default name of the assembly.
```xml

AcadR24FsharpPlugin
```
### Installation of the template
The 'AutoCAD Plugin Template' folder (possibly zipped) have to be pasted in the 'Visual Studio 20XX\Templates\ProjectTemplates' directory.