diff --git a/Revit_Core_Engine/Compute/Notes.cs b/Revit_Core_Engine/Compute/Notes.cs index 0ad77d0e5..eb078af0e 100644 --- a/Revit_Core_Engine/Compute/Notes.cs +++ b/Revit_Core_Engine/Compute/Notes.cs @@ -35,7 +35,7 @@ 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); @@ -43,8 +43,12 @@ internal static void MaterialNotInLibraryNote(this Material material) 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."); + } /***************************************************/ } -} +} diff --git a/Revit_Core_Engine/Compute/Warnings.cs b/Revit_Core_Engine/Compute/Warnings.cs index 65c7ba210..bb11ab987 100644 --- a/Revit_Core_Engine/Compute/Warnings.cs +++ b/Revit_Core_Engine/Compute/Warnings.cs @@ -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."); + } + + /***************************************************/ } } diff --git a/Revit_Core_Engine/Modify/Checkout.cs b/Revit_Core_Engine/Modify/Checkout.cs new file mode 100644 index 000000000..99634b24e --- /dev/null +++ b/Revit_Core_Engine/Modify/Checkout.cs @@ -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 . + */ + +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 Checkout(this List 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 elementsToCheckout = new List(); + + 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; + } + /***************************************************/ + } +} + + + diff --git a/Revit_Core_Engine/Modify/SetInsulation.cs b/Revit_Core_Engine/Modify/SetInsulation.cs index 95428d390..eb6a59f5c 100644 --- a/Revit_Core_Engine/Modify/SetInsulation.cs +++ b/Revit_Core_Engine/Modify/SetInsulation.cs @@ -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.")] diff --git a/Revit_Core_Engine/Query/CheckoutStatus.cs b/Revit_Core_Engine/Query/CheckoutStatus.cs new file mode 100644 index 000000000..485c1c845 --- /dev/null +++ b/Revit_Core_Engine/Query/CheckoutStatus.cs @@ -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 . + */ + +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); + } + /***************************************************/ + } +} diff --git a/Revit_Core_Engine/Query/ElementsEditablePerCheckoutStatus.cs b/Revit_Core_Engine/Query/ElementsEditablePerCheckoutStatus.cs new file mode 100644 index 000000000..abcf8ebe1 --- /dev/null +++ b/Revit_Core_Engine/Query/ElementsEditablePerCheckoutStatus.cs @@ -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 . + */ + +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 ElementsEditablePerCheckoutStatus(this List 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 elementsOwnedByOthers = elements.ElementsOwnedByOtherUsers().ToList(); + + List editableElements = elements.Except(elementsOwnedByOthers).ToList(); + + if (recordWarnings) + { + foreach (var element in elementsOwnedByOthers) + { + Compute.ElementOwnedByOtherUserWarning(element); + } + } + + return editableElements; + } + /***************************************************/ + } +} diff --git a/Revit_Core_Engine/Query/ElementsOwnedByCurrentUser.cs b/Revit_Core_Engine/Query/ElementsOwnedByCurrentUser.cs new file mode 100644 index 000000000..87609f5a8 --- /dev/null +++ b/Revit_Core_Engine/Query/ElementsOwnedByCurrentUser.cs @@ -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 . + */ + +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 ElementsOwnedByCurrentUser(this List 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(); + } + /***************************************************/ + } +} diff --git a/Revit_Core_Engine/Query/ElementsOwnedByNone.cs b/Revit_Core_Engine/Query/ElementsOwnedByNone.cs new file mode 100644 index 000000000..78df508f0 --- /dev/null +++ b/Revit_Core_Engine/Query/ElementsOwnedByNone.cs @@ -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 . + */ + +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 ElementsOwnedByNone(this List 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(); + } + /***************************************************/ + } +} diff --git a/Revit_Core_Engine/Query/ElementsOwnedByOtherUsers.cs b/Revit_Core_Engine/Query/ElementsOwnedByOtherUsers.cs new file mode 100644 index 000000000..b96ee5b0c --- /dev/null +++ b/Revit_Core_Engine/Query/ElementsOwnedByOtherUsers.cs @@ -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 . + */ + +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 other users.")] + [Input("elements", "Revit elements to query for its checkout status.")] + [Output("elementsOwnedByUsers", "List of elements that are owned by other users.")] + public static List ElementsOwnedByOtherUsers(this List elements) + { + if (elements == null) + { + BH.Engine.Base.Compute.RecordError("Querying checkout status of list of elements for ownership by others failed because the list of elements provided was null."); + return null; + } + + return elements.Where(e => e.IsOwnedByOtherUser()).ToList(); + } + /***************************************************/ + } +} diff --git a/Revit_Core_Engine/Query/IsOwnedByCurrentUser.cs b/Revit_Core_Engine/Query/IsOwnedByCurrentUser.cs new file mode 100644 index 000000000..f42ae66cb --- /dev/null +++ b/Revit_Core_Engine/Query/IsOwnedByCurrentUser.cs @@ -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 . + */ + +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("Check if element is owned by the current user.")] + [Input("element", "Revit element to query for its checkout status.")] + [Output("ownedByCurrentUser", "True if the input Revit element is owned by current user, otherwise false.")] + public static bool IsOwnedByCurrentUser(this Element element) + { + if (element == null) + { + BH.Engine.Base.Compute.RecordError("Querying checkout status of element for ownership by current user failed because the element provided was null."); + return false; + } + + return element.CheckoutStatus() == Autodesk.Revit.DB.CheckoutStatus.OwnedByCurrentUser; + } + /***************************************************/ + } +} diff --git a/Revit_Core_Engine/Query/IsOwnedByNone.cs b/Revit_Core_Engine/Query/IsOwnedByNone.cs new file mode 100644 index 000000000..d62cdeb35 --- /dev/null +++ b/Revit_Core_Engine/Query/IsOwnedByNone.cs @@ -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 . + */ + +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("Check if element is currently unowned.")] + [Input("element", "Revit element to query for its checkout status.")] + [Output("ownedByNone", "True if the input Revit element is not owned, otherwise false.")] + public static bool IsOwnedByNone(this Element element) + { + if (element == null) + { + BH.Engine.Base.Compute.RecordError("Querying checkout status of element for ownership by none failed because the element provided was null."); + return false; + } + + return element.CheckoutStatus() == Autodesk.Revit.DB.CheckoutStatus.NotOwned; + } + /***************************************************/ + } +} diff --git a/Revit_Core_Engine/Query/IsOwnedByOtherUser.cs b/Revit_Core_Engine/Query/IsOwnedByOtherUser.cs new file mode 100644 index 000000000..10d36a421 --- /dev/null +++ b/Revit_Core_Engine/Query/IsOwnedByOtherUser.cs @@ -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 . + */ + +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("Check if element is owned by another user.")] + [Input("element", "Revit element to query for its checkout status.")] + [Output("ownedByOtherUser", "True if the input Revit element is owned by another user, otherwise false.")] + public static bool IsOwnedByOtherUser(this Element element) + { + if (element == null) + { + BH.Engine.Base.Compute.RecordError("Querying checkout status of element for ownership by others failed because the element provided was null."); + return false; + } + + return element.CheckoutStatus() == Autodesk.Revit.DB.CheckoutStatus.OwnedByOtherUser; + } + /***************************************************/ + } +} diff --git a/Revit_Core_Engine/Revit_Core_Engine.csproj b/Revit_Core_Engine/Revit_Core_Engine.csproj index 527cfc0e8..0c7e5ce71 100644 --- a/Revit_Core_Engine/Revit_Core_Engine.csproj +++ b/Revit_Core_Engine/Revit_Core_Engine.csproj @@ -333,6 +333,7 @@ + @@ -401,6 +402,14 @@ + + + + + + + +