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

Revit_Core_Engine: Element Checkout Status Query Added #1248

Merged
merged 38 commits into from
Sep 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
1d5bd54
check ownership methods
Jul 15, 2022
aad0975
update
Jul 15, 2022
af569d8
Update CheckedoutStatus.cs
Jul 15, 2022
7789cbd
Update CheckedoutStatus.cs
Jul 15, 2022
6062f5e
Update CheckedoutStatus.cs
Jul 15, 2022
5f4853d
Update CheckedoutStatus.cs
Jul 17, 2022
66a3ab1
Update CheckedoutStatus.cs
Jul 17, 2022
f1470c4
Update CheckedoutStatus.cs
Jul 17, 2022
1b2e39e
removed methods that I probably won't need YAGNI
Jul 18, 2022
e06b28e
Update CheckedoutStatus.cs
Jul 18, 2022
86f6110
Update CheckedoutStatus.cs
Jul 18, 2022
17d05c3
Refactoring
Jul 18, 2022
731c343
refactor
Jul 18, 2022
7774c22
spelling and code compliance
Jul 18, 2022
ca8079b
pr comments checks
Aug 15, 2022
955d0b8
OwnedBy Queries updated to simplify logic
Aug 15, 2022
2261422
pr changes
Aug 15, 2022
088d22a
Update Checkout.cs
Aug 15, 2022
6a4596e
updates per pr comments
Aug 16, 2022
4e8b64c
pr comments
Aug 16, 2022
d5fcc1e
Update ElementsEditablePerCheckoutStatus.cs
Aug 16, 2022
6e01512
spelling
Aug 24, 2022
b0ed293
updated for null handling
Aug 31, 2022
213d7de
added check for multiple documents on revit elements
Aug 31, 2022
5183e49
added nullable type to LINQ
Sep 2, 2022
8f9e128
LINQ over elements to check that all of same document
Sep 2, 2022
4ba086d
Small change to linq
Sep 2, 2022
8edcf48
Cange Checkout.cs method to return List<Element>
Sep 2, 2022
e3ecec5
Update Revit_Core_Engine/Query/CheckoutStatus.cs
Sep 2, 2022
2fc448e
update to be able to checkout from multiple documents.
Sep 2, 2022
599e533
Merge branch 'Revit_Toolkit-#1227-CheckOwnership' of https://github.c…
Sep 2, 2022
5434f7b
Update Revit_Core_Engine/Query/IsOwnedByCurrentUser.cs
Sep 2, 2022
0971801
Update Revit_Core_Engine/Query/IsOwnedByNone.cs
Sep 2, 2022
f263e07
Update Revit_Core_Engine/Query/IsOwnedByOtherUser.cs
Sep 2, 2022
9cf4d6d
Update Revit_Core_Engine/Query/ElementsOwnedByOtherUsers.cs
Sep 2, 2022
9fbd348
removing list empty check
Sep 2, 2022
11f5efa
updating error comments
Sep 2, 2022
ea5e866
Update IsOwnedByNone.cs
Sep 2, 2022
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
8 changes: 6 additions & 2 deletions Revit_Core_Engine/Compute/Notes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,20 @@ public static partial class Compute

internal static void MaterialNotInLibraryNote(this Material material)
{
string message = "Material could not be found in BHoM Libary.";
string message = "Material could not be found in BHoM Library.";

if (material != null)
message = string.Format("{0} Material Id: {1}", message, material.Id.IntegerValue);

BH.Engine.Base.Compute.RecordNote(message);
}

internal static void ElementOwnedByCurrentUserNote(Element element)
{
BH.Engine.Base.Compute.RecordNote($"Revit object with ElementId: {element.Id} is owned by the current user.");
}
/***************************************************/
}
}
}


7 changes: 7 additions & 0 deletions Revit_Core_Engine/Compute/Warnings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,13 @@ internal static void TransformNotImplementedWarning(this Element element)
}

/***************************************************/

internal static void ElementOwnedByOtherUserWarning(Element element)
{
BH.Engine.Base.Compute.RecordWarning($"Revit object could not be updated or modified due to its CheckoutStatus. Revit ElementId: {element.Id} is owned by another user.");
}

/***************************************************/
}
}

Expand Down
78 changes: 78 additions & 0 deletions Revit_Core_Engine/Modify/Checkout.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2022, 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 Autodesk.Revit.DB;
using BH.oM.Base.Attributes;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;

namespace BH.Revit.Engine.Core
{
public static partial class Modify
{
/***************************************************/
/**** Public methods ****/
/***************************************************/

[Description("Modifies CheckoutStatus for each element selected if element is not currently owned by the current user or others.")]
[Input("elements", "Revit elements to query for its checkout status.")]
[Output("elementsCheckedOut", "List of elements checked out (ownership modified to be by current user) by this process.")]
public static List<Element> Checkout(this List<Element> elements)
{
if (elements == null)
{
BH.Engine.Base.Compute.RecordError("Check out process of list of elements failed because the list of elements provided was null.");
return null;
}

List<Element> elementsToCheckout = new List<Element>();

foreach (Element element in elements)
{
switch (element.CheckoutStatus())
{
case CheckoutStatus.NotOwned:
elementsToCheckout.Add(element);
break;
case CheckoutStatus.OwnedByCurrentUser:
Compute.ElementOwnedByCurrentUserNote(element);
break;
case CheckoutStatus.OwnedByOtherUser:
Compute.ElementOwnedByOtherUserWarning(element);
break;
}
}

foreach (var group in elementsToCheckout.GroupBy(x => x.Document))
{
WorksharingUtils.CheckoutElements(group.Key, group.Select(x => x.Id).ToList());
}

return elementsToCheckout;
}
/***************************************************/
}
}



2 changes: 1 addition & 1 deletion Revit_Core_Engine/Modify/SetInsulation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static partial class Modify
/**** Public methods ****/
/***************************************************/

[Description("Add or update existing insulation of the duct or pipe with given inuslation type and thickness.")]
[Description("Add or update existing insulation of the duct or pipe with given insulation type and thickness.")]
[Input("host", "Host element to add or update the insulation on.")]
[Input("insulationType", "Type of insulation to be added or updated on the host object. Null value removes insulation from the host if it exist.")]
[Input("insulationThickness", "Thickness of insulation to be added or updated on the host object.")]
Expand Down
55 changes: 55 additions & 0 deletions Revit_Core_Engine/Query/CheckoutStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2022, 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 Autodesk.Revit.DB;
using Autodesk.Revit.DB.Analysis;
using Autodesk.Revit.UI;
using BH.Engine.Adapters.Revit;
using BH.oM.Base;
using BH.oM.Base.Attributes;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;

namespace BH.Revit.Engine.Core
{
public static partial class Query
{
/***************************************************/
/**** Public methods ****/
/***************************************************/

[Description("Returns element CheckoutStatus.")]
[Input("element", "Revit element to query for its checkout status.")]
[Output("checkoutStatus", "The worksharing ownership/CheckoutStatus of the element.")]
public static CheckoutStatus? CheckoutStatus(this Element element)
{
if (element == null)
{
BH.Engine.Base.Compute.RecordError("Querying checkout status of element failed because the element provided was null.");
return null;
}
return WorksharingUtils.GetCheckoutStatus(element.Document, element.Id);
}
/***************************************************/
}
}
70 changes: 70 additions & 0 deletions Revit_Core_Engine/Query/ElementsEditablePerCheckoutStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2022, 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 Autodesk.Revit.DB;
using Autodesk.Revit.DB.Analysis;
using Autodesk.Revit.UI;
using BH.Engine.Adapters.Revit;
using BH.oM.Base;
using BH.oM.Base.Attributes;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;

namespace BH.Revit.Engine.Core
{
public static partial class Query
{
/***************************************************/
/**** Public methods ****/
/***************************************************/
[Description("Returns a sublist of elements, from the given list of elements, that are editable per the element's CheckoutStatus. " +
"Return warnings option, if true, alerts the user of which elements are uneditable due to ownership by other users.")]
[Input("elements", "Revit elements to query for its checkout status.")]
[Input("recordWarnings", "If it is desired, a value of 'True' will raise warnings on which elements "
+ "in the list are uneditable due to ownership by other users.")]
[Output("elementsEditablePerCheckoutStatus", "List of elements that are editable per the element's CheckoutStatus.")]
public static List<Element> ElementsEditablePerCheckoutStatus(this List<Element> elements, bool recordWarnings)
{
if (elements == null)
{
BH.Engine.Base.Compute.RecordError("Querying checkout status of list of elements for editable status failed because the list of elements provided was null.");
return null;
}

List<Element> elementsOwnedByOthers = elements.ElementsOwnedByOtherUsers().ToList();

List<Element> editableElements = elements.Except(elementsOwnedByOthers).ToList();

if (recordWarnings)
{
foreach (var element in elementsOwnedByOthers)
{
Compute.ElementOwnedByOtherUserWarning(element);
}
}

return editableElements;
}
/***************************************************/
}
}
56 changes: 56 additions & 0 deletions Revit_Core_Engine/Query/ElementsOwnedByCurrentUser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2022, 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 Autodesk.Revit.DB;
using Autodesk.Revit.DB.Analysis;
using Autodesk.Revit.UI;
using BH.Engine.Adapters.Revit;
using BH.oM.Base;
using BH.oM.Base.Attributes;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;

namespace BH.Revit.Engine.Core
{
public static partial class Query
{
/***************************************************/
/**** Public methods ****/
/***************************************************/

[Description("Returns a sublist of elements, from the given list of elements, that are owned by the current user.")]
[Input("elements", "Revit elements to query for its checkout status.")]
[Output("elementsOwnedByCurrentUser", "List of elements that are owned by the current user.")]
public static List<Element> ElementsOwnedByCurrentUser(this List<Element> elements)
{
if (elements == null)
{
BH.Engine.Base.Compute.RecordError("Querying checkout status of list of elements for ownership by current user failed because the list of elements provided was null.");
return null;
}

return elements.Where(e => e.IsOwnedByCurrentUser()).ToList();
}
/***************************************************/
}
}
55 changes: 55 additions & 0 deletions Revit_Core_Engine/Query/ElementsOwnedByNone.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2022, 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 Autodesk.Revit.DB;
using Autodesk.Revit.DB.Analysis;
using Autodesk.Revit.UI;
using BH.Engine.Adapters.Revit;
using BH.oM.Base;
using BH.oM.Base.Attributes;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;

namespace BH.Revit.Engine.Core
{
public static partial class Query
{
/***************************************************/
/**** Public methods ****/
/***************************************************/
[Description("Returns a sublist of elements, from the given list of elements, that are unowned.")]
[Input("elements", "Revit elements to query for its checkout status.")]
[Output("elementsOwnedByNone", "List of elements that are unowned.")]
public static List<Element> ElementsOwnedByNone(this List<Element> elements)
{
if (elements == null)
{
BH.Engine.Base.Compute.RecordError("Querying checkout status of list of elements for ownership by none failed because the list of elements provided was null.");
return null;
}

return elements.Where(e => e.IsOwnedByNone() == true).ToList();
}
/***************************************************/
}
}
Loading