Skip to content

Commit 2893909

Browse files
committed
cleanup
1 parent 1878969 commit 2893909

File tree

4 files changed

+37
-34
lines changed

4 files changed

+37
-34
lines changed

Fesh.Revit/Src/Addin.fs

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace Fesh.Revit
1+
namespace Fesh.Revit
22

33
open Autodesk.Revit.UI
44
open Autodesk.Revit.DB
@@ -57,7 +57,7 @@ type DebugUtils private () =
5757
static member logToFile filePrefix (content:string) =
5858
let checkedPrefix = if isNull filePrefix then "NULL-PREFIX" else filePrefix
5959
let checkedContent = if String.IsNullOrWhiteSpace content then "content is String.IsNullOrWhiteSpace" else content
60-
let time = DateTime.UtcNow.ToString("yyyy-MM-dd_HH-mm-ss-fff") // ensure unique name
60+
let time = DateTime.UtcNow.ToString "yyyy-MM-dd_HH-mm-ss-fff" // ensure unique name
6161
let filename = sprintf "%sFesh.AutoCAD.Log-%s.txt" checkedPrefix time
6262
async {
6363
try
@@ -80,12 +80,12 @@ type DebugUtils private () =
8080
DebugUtils.logToFile "App.alertFailed-" errMsg
8181
TaskDialog.Show("Fesh AddIn. normal alert failed", errMsg) |> ignore
8282

83-
| _ when logFileOnDesktopCount.Value < 10 ->
83+
| _ when logFileOnDesktopCount.Value < 5 ->
8484
incr logFileOnDesktopCount
8585
DebugUtils.logToFile "App.alert-" msg
8686
TaskDialog.Show("Fesh AddIn alert", msg) |> ignore
8787

88-
| _ -> () // do nothing , there are already 10 log files on the desktop
88+
| _ -> () // do nothing , there are already 5 log files on the desktop
8989

9090

9191
/// logs text to Fesh editor window in green
@@ -101,6 +101,7 @@ type DebugUtils private () =
101101
[<Transaction(TransactionMode.Manual)>]
102102
type internal FsiRunEventHandler (fesh:Fesh, queue: ConcurrentQueue< UIApplication->unit >) =
103103
member this.GetName() = "Run in Fesh"
104+
104105
member this.Execute(app:UIApplication) =
105106
let f = ref Unchecked.defaultof<UIApplication->unit>
106107
while queue.TryDequeue(f) do //using a queue is only needed if a single script calls into a transaction more than once
@@ -111,7 +112,7 @@ type internal FsiRunEventHandler (fesh:Fesh, queue: ConcurrentQueue< UIApplicati
111112

112113
interface IExternalEventHandler with
113114
member this.GetName() = this.GetName()
114-
member this.Execute(app:UIApplication) = this.Execute(app)
115+
member this.Execute(app:UIApplication) = this.Execute app
115116

116117

117118
[<Regeneration(RegenerationOption.Manual)>]
@@ -128,8 +129,8 @@ type FeshAddin()= // : IExternalApplication = // don't rename ! This is referenc
128129

129130
/// Runs a F# function via the IExternalEventHandler pattern for mode-less dialogs
130131
/// This is the only way to run code from mode-less dialogs such as Fesh editor
131-
member this.RunOnApp (f:UIApplication -> unit) =
132-
this.RequestQueue.Enqueue(f)
132+
member this.RunOnApp (transaction:UIApplication -> unit) =
133+
this.RequestQueue.Enqueue transaction
133134
match this.ExternalEv with
134135
|None ->
135136
DebugUtils.alert "ExternalEvent not set up yet"
@@ -143,8 +144,8 @@ type FeshAddin()= // : IExternalApplication = // don't rename ! This is referenc
143144

144145
/// runs a F# function via the IExternalEventHandler pattern for mode-less dialogs
145146
/// this is the only way to run code from mode-less dialogs such as Fesh editor
146-
member this.RunOnDoc (f:Document->unit) =
147-
this.RunOnApp (fun app -> f app.ActiveUIDocument.Document)
147+
member this.RunOnDoc (transaction:Document->unit) =
148+
this.RunOnApp (fun app -> transaction app.ActiveUIDocument.Document)
148149

149150

150151
member this.OnStartup(uiConApp:UIControlledApplication) =
@@ -157,15 +158,15 @@ type FeshAddin()= // : IExternalApplication = // don't rename ! This is referenc
157158
let button = new PushButtonData("Fesh", "Open Fesh F# Editor", thisAssemblyPath, "Fesh.Revit.StartEditorCommand") // a reference to type StartEditorCommand()
158159
button.ToolTip <- "This will open Fesh in a new window, the F# Scripting Editor."
159160

160-
let uriImage32 = new Uri("pack://application:,,,/Fesh.Revit;component/Media32/logo32.png") // build from VS not via "dotnet build" to include. <Resource Include="Media\LogoCursorTr32.png" />
161-
let uriImage16 = new Uri("pack://application:,,,/Fesh.Revit;component/Media32/logo16.png")
162-
button.LargeImage <- Media.Imaging.BitmapImage(uriImage32)//for ribbon in tab
163-
button.Image <- Media.Imaging.BitmapImage(uriImage16)//for quick access toolbar
161+
let uriImage32 = new Uri "pack://application:,,,/Fesh.Revit;component/Media32/logo32.png" // build from VS not via "dotnet build" to include. <Resource Include="Media\LogoCursorTr32.png" />
162+
let uriImage16 = new Uri "pack://application:,,,/Fesh.Revit;component/Media32/logo16.png"
163+
button.LargeImage <- Media.Imaging.BitmapImage uriImage32 //for ribbon in tab
164+
button.Image <- Media.Imaging.BitmapImage uriImage16 //for quick access toolbar
164165

165166
let tabId = "Fesh"
166167
uiConApp.CreateRibbonTab(tabId)
167168
let panel = uiConApp.CreateRibbonPanel(tabId,"Fesh")
168-
panel.AddItem(button) |> ignore
169+
panel.AddItem button |> ignore
169170

170171
Result.Succeeded
171172

@@ -192,8 +193,8 @@ type FeshAddin()= // : IExternalApplication = // don't rename ! This is referenc
192193

193194

194195
interface IExternalApplication with
195-
member this.OnStartup(uiConApp:UIControlledApplication) = this.OnStartup(uiConApp)
196-
member this.OnShutdown(app:UIControlledApplication) = this.OnShutdown(app)
196+
member this.OnStartup(uiConApp:UIControlledApplication) = this.OnStartup uiConApp
197+
member this.OnShutdown(app:UIControlledApplication) = this.OnShutdown app
197198

198199
//member this.Queue = queue
199200

@@ -237,18 +238,18 @@ type StartEditorCommand() = // don't rename ! string referenced in OnStartup ->
237238
// If Document.IsModifiable returns TRUE, then there is an active transaction open in that document.
238239
// https://thebuildingcoder.typepad.com/blog/2015/06/archsample-active-transaction-and-adnrme-for-revit-mep-2016.html#3
239240

240-
let appName = AppName.get(commandData.Application.Application.VersionNumber)
241-
let logo = new Uri("pack://application:,,,/Fesh.Revit;component/Media32/logo.ico")
241+
let appName = AppName.get commandData.Application.Application.VersionNumber
242+
let logo = new Uri "pack://application:,,,/Fesh.Revit;component/Media32/logo.ico"
242243
let hostData = {
243244
hostName = appName
244245
mainWindowHandel = winHandle
245246
fsiCanRun = canRun
246247
logo = Some logo
247-
defaultCode = Some (DefaultCode.get(appName))
248-
hostAssembly = Some (Reflection.Assembly.GetAssembly(typeof<FeshAddin>))
248+
defaultCode = Some (DefaultCode.get appName)
249+
hostAssembly = Some (Reflection.Assembly.GetAssembly typeof<FeshAddin>)
249250
}
250251

251-
let feshApp = Fesh.App.createEditorForHosting(hostData)
252+
let feshApp = Fesh.App.createEditorForHosting hostData
252253
DebugUtils.Fesh <- Some feshApp
253254

254255
//TODO make a C# plugin that loads Fesh.addin once uiConApp.ControlledApplication.ApplicationInitialized to avoid missing method exceptions in FSI

Fesh.Revit/Src/ScriptingSyntax.fs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module ScriptingSyntax =
1111

1212
/// Runs a function in a transaction
1313
/// Will log errors to Fesh Log if transaction has problems
14-
let run (f: Document-> unit) =
14+
let run (transaction: Document-> unit) =
1515
FeshAddin.Instance.RunOnDoc (fun (doc:Document) ->
1616
use t = new Transaction(doc, "Fesh F# script")
1717
let s = t.Start()
@@ -28,7 +28,7 @@ module ScriptingSyntax =
2828
|_ -> eprintfn "Transaction.Start returned unknown state: %A" s
2929

3030
try
31-
f(doc)
31+
transaction doc
3232
with ex ->
3333
match DebugUtils.Fesh with
3434
|None -> ()
@@ -50,7 +50,7 @@ module ScriptingSyntax =
5050

5151
/// Runs a function in a transaction
5252
/// Will log errors to Fesh Log if transaction has problems
53-
let runApp (f: UIApplication-> unit) =
53+
let runApp (transaction: UIApplication-> unit) =
5454
FeshAddin.Instance.RunOnApp (fun (app:UIApplication) ->
5555
let doc = app.ActiveUIDocument.Document
5656
use t = new Transaction(doc, "Fesh F# script")
@@ -68,10 +68,10 @@ module ScriptingSyntax =
6868
|_ -> eprintfn "Transaction.Start returned unknown state: %A" s
6969

7070
try
71-
f(app)
71+
transaction app
7272
with ex ->
73-
match DebugUtils.Fesh with
74-
|None -> ()
73+
match DebugUtils.Fesh with
74+
|None -> ()
7575
|Some fesh -> fesh.Log.PrintfnColor 240 0 0 "Function in transaction failed with:\r\n%A" ex
7676

7777
let r = t.Commit()

Fesh.Revit/Src/Velo.fs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,25 +101,27 @@ module Velo =
101101

102102
with e ->
103103
updateManager <- None
104-
fesh.Log.PrintfnInfoMsg "Could not check for Velopack updates:\r\n%A" e
104+
fesh.Log.PrintfnAppErrorMsg "Checking for updates of Fesh.Revit via Velopack failed."
105+
fesh.Log.PrintfnAppErrorMsg "If this error keeps repeating, reintall Fesh.Revit from https://github.com/goswinr/Fesh.Revit/releases"
106+
fesh.Log.PrintfnInfoMsg "Details:\r\n%A" e
105107

106108
} |> Async.Start
107109

108110

109-
let updateOnRevitClose(revit:UIApplication, alert: string -> unit) =
111+
let updateOnRevitClose(revit:UIApplication, alert: string -> unit) =
110112
// This event is raised when the Revit application is just about to be closed.
111113
// Event is not cancellable. The 'Cancellable' property of event's argument is always False.
112114
// No document may be modified at the time of the event.
113115
// The sender object of this event is UIControlledApplication object.
114116
revit.ApplicationClosing.Add(fun _ ->
115117
if updatesDownloaded then
116-
let revitProcesses = System.Diagnostics.Process.GetProcessesByName("Revit")
118+
let revitProcesses = System.Diagnostics.Process.GetProcessesByName "Revit"
117119
if revitProcesses.Length = 1 then
118120
let exe = Reflection.Assembly.GetAssembly(typeof<FeshRevitDummy>).Location
119-
let exeFolder = IO.Path.GetDirectoryName(exe)
120-
let parentFolder = IO.Path.GetDirectoryName(exeFolder)
121+
let exeFolder = IO.Path.GetDirectoryName exe
122+
let parentFolder = IO.Path.GetDirectoryName exeFolder
121123
let updater = IO.Path.Combine(parentFolder, "Update.exe")
122-
if IO.File.Exists(updater) then
124+
if IO.File.Exists updater then
123125
match updateManager with
124126
| Some um ->
125127
if isNull um.UpdatePendingRestart then

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Fesh.Revit
55
[![Build](https://github.com/goswinr/Fesh.Revit/actions/workflows/build.yml/badge.svg?event=push)](https://github.com/goswinr/Fesh.Revit/actions/workflows/build.yml)
66
[![Check NuGet](https://github.com/goswinr/Fesh.Revit/actions/workflows/outdatedNuget.yml/badge.svg)](https://github.com/goswinr/Fesh.Revit/actions/workflows/outdatedNuget.yml)
7-
[![Hits](https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Fgoswinr%2FFesh.Revit&count_bg=%2379C83D&title_bg=%23555555&icon=github.svg&icon_color=%23E7E7E7&title=hits&edge_flat=false)](https://hits.seeyoufarm.com)
7+
88
![code size](https://img.shields.io/github/languages/code-size/goswinr/Fesh.Revit.svg)
99
[![license](https://img.shields.io/github/license/goswinr/Fesh.Revit)](LICENSE)
1010

0 commit comments

Comments
 (0)