Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Query method to get the currently active canvas file path #681

Merged
merged 2 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions Grasshopper_Engine/Grasshopper_Engine.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
Expand Down Expand Up @@ -35,26 +35,26 @@
<ItemGroup>
<Reference Include="BHoM">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\ProgramData\BHoM\Assemblies\BHoM.dll</HintPath>
<HintPath>$(ProgramData)\BHoM\Assemblies\BHoM.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="BHoM_Engine">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\ProgramData\BHoM\Assemblies\BHoM_Engine.dll</HintPath>
<HintPath>$(ProgramData)\BHoM\Assemblies\BHoM_Engine.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="BHoM_UI">
<HintPath>C:\ProgramData\BHoM\Assemblies\BHoM_UI.dll</HintPath>
<HintPath>$(ProgramData)\BHoM\Assemblies\BHoM_UI.dll</HintPath>
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="Data_Engine">
<HintPath>C:\ProgramData\BHoM\Assemblies\Data_Engine.dll</HintPath>
<HintPath>$(ProgramData)\BHoM\Assemblies\Data_Engine.dll</HintPath>
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="Dimensional_oM">
<HintPath>C:\ProgramData\BHoM\Assemblies\Dimensional_oM.dll</HintPath>
<HintPath>$(ProgramData)\BHoM\Assemblies\Dimensional_oM.dll</HintPath>
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
Expand All @@ -63,49 +63,49 @@
</Reference>
<Reference Include="Geometry_Engine">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\ProgramData\BHoM\Assemblies\Geometry_Engine.dll</HintPath>
<HintPath>$(ProgramData)\BHoM\Assemblies\Geometry_Engine.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Geometry_oM">
<HintPath>C:\ProgramData\BHoM\Assemblies\Geometry_oM.dll</HintPath>
<HintPath>$(ProgramData)\BHoM\Assemblies\Geometry_oM.dll</HintPath>
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="GH_IO, Version=6.33.20343.16430, Culture=neutral, PublicKeyToken=6a29997d2e6b4f97, processorArchitecture=MSIL">
<HintPath>..\packages\Grasshopper.6.33.20343.16431\lib\net45\GH_IO.dll</HintPath>
</Reference>
<Reference Include="Graphics_oM">
<HintPath>C:\ProgramData\BHoM\Assemblies\Graphics_oM.dll</HintPath>
<HintPath>$(ProgramData)\BHoM\Assemblies\Graphics_oM.dll</HintPath>
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="Grasshopper, Version=6.33.20343.16430, Culture=neutral, PublicKeyToken=dda4f5ec2cd80803, processorArchitecture=MSIL">
<HintPath>..\packages\Grasshopper.6.33.20343.16431\lib\net45\Grasshopper.dll</HintPath>
</Reference>
<Reference Include="Programming_oM">
<HintPath>C:\ProgramData\BHoM\Assemblies\Programming_oM.dll</HintPath>
<HintPath>$(ProgramData)\BHoM\Assemblies\Programming_oM.dll</HintPath>
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="Reflection_Engine">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\ProgramData\BHoM\Assemblies\Reflection_Engine.dll</HintPath>
<HintPath>$(ProgramData)\BHoM\Assemblies\Reflection_Engine.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Rhino.UI, Version=6.33.20343.16430, Culture=neutral, PublicKeyToken=552281e97c755530, processorArchitecture=MSIL">
<HintPath>..\packages\RhinoCommon.6.33.20343.16431\lib\net45\Rhino.UI.dll</HintPath>
</Reference>
<Reference Include="Rhinoceros_Engine">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\ProgramData\BHoM\Assemblies\Rhinoceros_Engine.dll</HintPath>
<HintPath>$(ProgramData)\BHoM\Assemblies\Rhinoceros_Engine.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="RhinoCommon, Version=6.33.20343.16430, Culture=neutral, PublicKeyToken=552281e97c755530, processorArchitecture=MSIL">
<HintPath>..\packages\RhinoCommon.6.33.20343.16431\lib\net45\RhinoCommon.dll</HintPath>
</Reference>
<Reference Include="Serialiser_Engine">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\ProgramData\BHoM\Assemblies\Serialiser_Engine.dll</HintPath>
<HintPath>$(ProgramData)\BHoM\Assemblies\Serialiser_Engine.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
Expand All @@ -118,12 +118,12 @@
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="UI_Engine">
<HintPath>C:\ProgramData\BHoM\Assemblies\UI_Engine.dll</HintPath>
<HintPath>$(ProgramData)\BHoM\Assemblies\UI_Engine.dll</HintPath>
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="UI_oM">
<HintPath>C:\ProgramData\BHoM\Assemblies\UI_oM.dll</HintPath>
<HintPath>$(ProgramData)\BHoM\Assemblies\UI_oM.dll</HintPath>
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
Expand All @@ -137,6 +137,7 @@
<Compile Include="Create\DataTree.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Query\CanvasID.cs" />
<Compile Include="Query\CanvasFilePath.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Compute\" />
Expand Down Expand Up @@ -174,4 +175,4 @@ Copy /Y "$(TargetDir)$(TargetName).dll" "C:\ProgramData\BHoM\Assemblies\$(Target
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
50 changes: 50 additions & 0 deletions Grasshopper_Engine/Query/CanvasFilePath.cs
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

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 "";
}
}
}