Skip to content

Commit

Permalink
Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
johnpierson committed Apr 18, 2024
1 parent b1cdcf1 commit 5c25403
Show file tree
Hide file tree
Showing 11 changed files with 258 additions and 47 deletions.
Binary file modified _Release/Revit2025/Relay/Relay.dll
Binary file not shown.
1 change: 1 addition & 0 deletions _Release/Revit2025/Relay/RelaySettings.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[Settings]
Path=default
ResetRibbon=false
29 changes: 26 additions & 3 deletions src/App.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows.Media.Imaging;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.UI;
using Autodesk.Windows;
using Relay.Classes;
using Relay.Utilities;

namespace Relay
Expand All @@ -17,8 +16,32 @@ public Result OnStartup(UIControlledApplication a)
//set the Revit version for reuse
Globals.RevitVersion = a.ControlledApplication.VersionNumber;

//read the ini file
if (File.Exists(Path.Combine(Globals.ExecutingPath,"RelaySettings.ini")))
{
try
{
var relayIni = new RelayIniFile();
var path = relayIni.Read("Path", "Settings");
var resetRibbon = relayIni.Read("ResetRibbon", "Settings");
//it the path is default, read that
Globals.BasePath = path.ToLower().Equals("default") ? Globals.ExecutingPath : path;

Globals.ResetRibbonOnSync = bool.Parse(resetRibbon);
}
//you screwed up the path mapping, sorry this tool is using the default then
catch (Exception)
{
Globals.BasePath = Globals.ExecutingPath;
}
}
else
{
Globals.BasePath = Globals.ExecutingPath;
}

// parse the location for the potential tab name
Globals.PotentialTabDirectories = Directory.GetDirectories(Globals.ExecutingPath);
Globals.PotentialTabDirectories = Directory.GetDirectories(Globals.BasePath);

if (Globals.PotentialTabDirectories.Any())
{
Expand Down
7 changes: 1 addition & 6 deletions src/Classes/RelayGraph.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Security.RightsManagement;
using System.Text;

namespace Relay.Classes
namespace Relay.Classes
{
internal class RelayGraph
{
Expand Down
58 changes: 58 additions & 0 deletions src/Classes/RelayIniFile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using Relay.Utilities;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace Relay.Classes
{
internal class RelayIniFile
{
string Path;
bool ResetRibbon;
string EXE = Assembly.GetExecutingAssembly().GetName().Name;

[DllImport("kernel32", CharSet = CharSet.Unicode)]
static extern long WritePrivateProfileString(string Section, string Key, string Value, string FilePath);

[DllImport("kernel32", CharSet = CharSet.Unicode)]
static extern int GetPrivateProfileString(string Section, string Key, string Default, StringBuilder RetVal, int Size, string FilePath);

public RelayIniFile()
{
Path = new FileInfo(Globals.ExecutingPath + "//RelaySettings.ini").FullName;
}

public string Read(string Key, string Section = null)
{
var RetVal = new StringBuilder(255);
GetPrivateProfileString(Section ?? EXE, Key, "", RetVal, 255, Path);
return RetVal.ToString();
}

public void Write(string Key, string Value, string Section = null)
{
WritePrivateProfileString(Section ?? EXE, Key, Value, Path);
}

public void DeleteKey(string Key, string Section = null)
{
Write(Key, null, Section ?? EXE);
}

public void DeleteSection(string Section = null)
{
Write(null, null, Section ?? EXE);
}

public bool KeyExists(string Key, string Section = null)
{
return Read(Key, Section).Length > 0;
}

}
}
16 changes: 10 additions & 6 deletions src/Command.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
using System;
using System.IO;
using System.Linq;
using System.Windows.Input;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Windows;
using Relay.Utilities;
using Application = Autodesk.Revit.ApplicationServices.Application;
using TaskDialog = Autodesk.Revit.UI.TaskDialog;
using TaskDialogCommonButtons = Autodesk.Revit.UI.TaskDialogCommonButtons;
using TaskDialogIcon = Autodesk.Revit.UI.TaskDialogIcon;
Expand All @@ -23,7 +17,17 @@ public Result Execute(ExternalCommandData commandData, ref string message, Eleme
{
UIApplication uiapp = commandData.Application;

#if DEBUG
//if (Globals.ResetRibbonOnSync)
//{
// RibbonUtils.ClearRibbon();
//}
#endif

RibbonUtils.SyncGraphs(uiapp);
RibbonUtils.HideUnused();



return Result.Succeeded;
}
Expand Down
3 changes: 1 addition & 2 deletions src/Methods/DynamoMethods.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI;
using Dynamo.Applications;
using Relay.Utilities;

Expand Down
3 changes: 1 addition & 2 deletions src/Utilities/DynamoUtils.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.IO;
using System.IO;
using Autodesk.Revit.UI;
using Dynamo.Applications;

Expand Down
22 changes: 13 additions & 9 deletions src/Utilities/Globals.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
using System;
using System.IO;
using System.Linq;
using System.IO;
using System.Reflection;

namespace Relay.Utilities
{
public partial class Globals
{
public static readonly string Version =
System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
public static string ExecutingPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
public static Assembly ExecutingAssembly = Assembly.GetExecutingAssembly();
public static readonly string Version = ExecutingAssembly.GetName().Version.ToString();

public static string ExecutingPath = Path.GetDirectoryName(ExecutingAssembly.Location);
public static string BasePath { get; set; } = ExecutingPath;

public static string UserTemp = Environment.GetEnvironmentVariable("TMP", EnvironmentVariableTarget.User);
public static string RevitVersion { get; set; }
public static Assembly ExecutingAssembly = Assembly.GetExecutingAssembly();

public static string[] EmbeddedLibraries = ExecutingAssembly.GetManifestResourceNames().Where(x => x.EndsWith(".dll")).ToArray();
public static string[] PotentialTabDirectories { get; set; }
public static string RibbonTabName = "Relay";
public static string RelayGraphs = Path.Combine(Globals.ExecutingPath, RibbonTabName);

public static string RibbonTabName { get; set; } = "Relay";
public static string RelayGraphs = Path.Combine(ExecutingPath, RibbonTabName);

public static string CurrentGraphToRun { get; set; } = "";

public static bool ResetRibbonOnSync { get; set; } = false;

}
}
Loading

0 comments on commit 5c25403

Please sign in to comment.