Skip to content

Commit

Permalink
Merge pull request #1173 from mcneel/1.24
Browse files Browse the repository at this point in the history
  • Loading branch information
kike-garbo authored Aug 27, 2024
2 parents c646348 + 1245bbf commit 475f5d5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
43 changes: 31 additions & 12 deletions src/RhinoInside.Revit.External/DB/Extensions/Category.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.DB;

namespace RhinoInside.Revit.External.DB.Extensions
Expand Down Expand Up @@ -54,6 +52,37 @@ public static bool IsEquivalent(this Category self, Category other)
}
}

public static class CategoryNaming
{
const char CS = '\\'; // Category Separator

/// <summary>
/// Return the <paramref name="category"/> full name.
/// </summary>
/// <param name="category"></param>
/// <remarks>If it is a Subcategory this will be "ParentName\SubcategoryName".</remarks>
/// <returns></returns>
public static string FullName(this Category category)
{
return category.Parent is null ? category.Name : $"{category.Parent.Name}{CS}{category.Name}";
}

internal static string SplitFullName(string fullName, out string parent)
{
if (fullName is null)
{
parent = null;
return null;
}
else
{
var index = fullName.IndexOf(CS);
parent = fullName.Substring(0, index);
return fullName.Substring(index + 1, fullName.Length - index - 1);
}
}
}

public static class CategoryExtension
{
/// <summary>
Expand Down Expand Up @@ -119,16 +148,6 @@ public static BuiltInCategory ToBuiltInCategory(this Category category)
#endif
}

/// <summary>
/// Return the <paramref name="category"/> full name. If it is a subCategory this will be "{ParentName}\{SubcategoryName}"
/// </summary>
/// <param name="category"></param>
/// <returns></returns>
public static string FullName(this Category category)
{
return category.Parent is null ? category.Name : $"{category.Parent.Name}\\{category.Name}";
}

/// <summary>
/// Return the <paramref name="category"/> discipline. If it is a subCategory this will be the parent discipline"
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/RhinoInside.Revit.External/Extensions/RhinoCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public PlanarBrepFace(BrepFace f)

public NurbsCurve Loop
{
get { if (Plane.IsValid && loop is null) loop = Curve.ProjectToPlane(Face.OuterLoop.To3dCurve(), Plane).ToNurbsCurve(); return loop; }
get { if (Plane.IsValid && loop is null) loop = Curve.ProjectToPlane(Face.OuterLoop.To3dCurve()?.ToNurbsCurve(), Plane) as NurbsCurve; return loop; }
}
public Point3d Centroid
{
Expand Down
2 changes: 1 addition & 1 deletion src/RhinoInside.Revit.GH/Types/ObjectStyles/Category.cs
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ public override string NextIncrementalNomen(string prefix)

public override string Nomen
{
get => FullName?.Split('\\').Last() ?? base.Nomen;
get => CategoryNaming.SplitFullName(FullName, out var _) ?? base.Nomen;
set
{
base.Nomen = value;
Expand Down

0 comments on commit 475f5d5

Please sign in to comment.