From 315fc944061a72eb185af4082f2274c4764e04b7 Mon Sep 17 00:00:00 2001 From: Fraser Greenroyd Date: Mon, 22 May 2023 16:07:51 +0100 Subject: [PATCH 1/2] Add a Query method to get the currently active canvas file path --- Grasshopper_Engine/Grasshopper_Engine.csproj | 1 + Grasshopper_Engine/Query/CanvasFilePath.cs | 50 ++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 Grasshopper_Engine/Query/CanvasFilePath.cs diff --git a/Grasshopper_Engine/Grasshopper_Engine.csproj b/Grasshopper_Engine/Grasshopper_Engine.csproj index 93f2c704..3cf9fe1d 100644 --- a/Grasshopper_Engine/Grasshopper_Engine.csproj +++ b/Grasshopper_Engine/Grasshopper_Engine.csproj @@ -137,6 +137,7 @@ + diff --git a/Grasshopper_Engine/Query/CanvasFilePath.cs b/Grasshopper_Engine/Query/CanvasFilePath.cs new file mode 100644 index 00000000..78411f92 --- /dev/null +++ b/Grasshopper_Engine/Query/CanvasFilePath.cs @@ -0,0 +1,50 @@ +/* + * This file is part of the Buildings and Habitats object Model (BHoM) + * Copyright (c) 2015 - 2023, the respective contributors. All rights reserved. + * + * Each contributor holds copyright over their respective contributions. + * The project versioning (Git) records all such contribution source information. + * + * + * The BHoM is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3.0 of the License, or + * (at your option) any later version. + * + * The BHoM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + */ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using GH = Grasshopper; +using Grasshopper.Kernel; +using System.ComponentModel; +using BH.oM.Base.Attributes; + +namespace BH.Engine.Grasshopper +{ + public static partial class Query + { + [Description("Gets the saved file path of the currently open Grasshopper Document for the active canvas.")] + [Output("filePath", "The local file path for the active canvas.")] + public static string CanvasFilePath() + { + var ghDoc = GH.Instances.ActiveCanvas.Document; + if (ghDoc != null && ghDoc.IsFilePathDefined) + return ghDoc.FilePath; + + BH.Engine.Base.Compute.RecordWarning("Document has not been saved and does not yet have a file path defined."); + return ""; + } + } +} From f4f6270e3ce1bc44b1d4c7b6c83a71c79995e217 Mon Sep 17 00:00:00 2001 From: BHoMBot Date: Mon, 22 May 2023 16:11:30 +0100 Subject: [PATCH 2/2] Update project compliance --- Grasshopper_Engine/Grasshopper_Engine.csproj | 32 ++++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Grasshopper_Engine/Grasshopper_Engine.csproj b/Grasshopper_Engine/Grasshopper_Engine.csproj index 3cf9fe1d..b1043319 100644 --- a/Grasshopper_Engine/Grasshopper_Engine.csproj +++ b/Grasshopper_Engine/Grasshopper_Engine.csproj @@ -1,4 +1,4 @@ - + @@ -35,26 +35,26 @@ False - C:\ProgramData\BHoM\Assemblies\BHoM.dll + $(ProgramData)\BHoM\Assemblies\BHoM.dll False False - C:\ProgramData\BHoM\Assemblies\BHoM_Engine.dll + $(ProgramData)\BHoM\Assemblies\BHoM_Engine.dll False - C:\ProgramData\BHoM\Assemblies\BHoM_UI.dll + $(ProgramData)\BHoM\Assemblies\BHoM_UI.dll False False - C:\ProgramData\BHoM\Assemblies\Data_Engine.dll + $(ProgramData)\BHoM\Assemblies\Data_Engine.dll False False - C:\ProgramData\BHoM\Assemblies\Dimensional_oM.dll + $(ProgramData)\BHoM\Assemblies\Dimensional_oM.dll False False @@ -63,11 +63,11 @@ False - C:\ProgramData\BHoM\Assemblies\Geometry_Engine.dll + $(ProgramData)\BHoM\Assemblies\Geometry_Engine.dll False - C:\ProgramData\BHoM\Assemblies\Geometry_oM.dll + $(ProgramData)\BHoM\Assemblies\Geometry_oM.dll False False @@ -75,7 +75,7 @@ ..\packages\Grasshopper.6.33.20343.16431\lib\net45\GH_IO.dll - C:\ProgramData\BHoM\Assemblies\Graphics_oM.dll + $(ProgramData)\BHoM\Assemblies\Graphics_oM.dll False False @@ -83,13 +83,13 @@ ..\packages\Grasshopper.6.33.20343.16431\lib\net45\Grasshopper.dll - C:\ProgramData\BHoM\Assemblies\Programming_oM.dll + $(ProgramData)\BHoM\Assemblies\Programming_oM.dll False False False - C:\ProgramData\BHoM\Assemblies\Reflection_Engine.dll + $(ProgramData)\BHoM\Assemblies\Reflection_Engine.dll False @@ -97,7 +97,7 @@ False - C:\ProgramData\BHoM\Assemblies\Rhinoceros_Engine.dll + $(ProgramData)\BHoM\Assemblies\Rhinoceros_Engine.dll False @@ -105,7 +105,7 @@ False - C:\ProgramData\BHoM\Assemblies\Serialiser_Engine.dll + $(ProgramData)\BHoM\Assemblies\Serialiser_Engine.dll False @@ -118,12 +118,12 @@ - C:\ProgramData\BHoM\Assemblies\UI_Engine.dll + $(ProgramData)\BHoM\Assemblies\UI_Engine.dll False False - C:\ProgramData\BHoM\Assemblies\UI_oM.dll + $(ProgramData)\BHoM\Assemblies\UI_oM.dll False False @@ -175,4 +175,4 @@ Copy /Y "$(TargetDir)$(TargetName).dll" "C:\ProgramData\BHoM\Assemblies\$(Target --> - \ No newline at end of file +