Skip to content

Commit

Permalink
Fix on conversion from ARDB.FamilySymbol to ModelInstanceDefinition.
Browse files Browse the repository at this point in the history
  • Loading branch information
kike-garbo committed May 4, 2024
1 parent e818ac3 commit 7021f63
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 50 deletions.
45 changes: 20 additions & 25 deletions src/RhinoInside.Revit.GH/Types/GeometricElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -778,9 +778,7 @@ ARDB.GeometryElement geometryElement
if (idMap.TryGetValue(element.Id, out var modelContent))
return modelContent as ModelInstanceDefinition;

var geometryElementContent = geometryElement.ToArray();
if (geometryElementContent.Length < 1)
return null;
var geometryElementContent = geometryElement?.ToArray() ?? Array.Empty<ARDB.GeometryObject>();

if
(
Expand Down Expand Up @@ -905,31 +903,28 @@ internal override ModelContent ToModelContent(IDictionary<ARDB.ElementId, ModelC
{
using (var geometry = element.GetGeometry(options))
{
if (geometry is object)
using (var context = GeometryDecoder.Context.Push())
{
using (var context = GeometryDecoder.Context.Push())
{
context.Element = element;
context.Category = element.Category;
context.Material = element.Category?.Material;
context.Element = element;
context.Category = element.Category;
context.Material = element.Category?.Material;

var location = element.Category is null || element.Category.Parent is object ?
Plane.WorldXY :
Location;
var location = element.Category is null || element.Category.Parent is object ?
Plane.WorldXY :
Location;

var worldToElement = Transform.PlaneToPlane(location, Plane.WorldXY);
if (ToModelInstanceDefinition(idMap, worldToElement, element, geometry) is ModelInstanceDefinition definition)
{
var elementToWorld = Transform.PlaneToPlane(Plane.WorldXY, location);
var attributes = ModelObject.Cast(new GH_InstanceReference(new InstanceReferenceGeometry(Guid.Empty, elementToWorld), definition)).ToAttributes();
attributes.Name = element.get_Parameter(ARDB.BuiltInParameter.ALL_MODEL_MARK)?.AsString() ?? string.Empty;
attributes.Url = element.get_Parameter(ARDB.BuiltInParameter.ALL_MODEL_URL)?.AsString() ?? string.Empty;
attributes.Layer = Category.ToModelContent(idMap) as ModelLayer;

modelContent = attributes.ToModelData() as ModelContent;
//idMap.Add(Id, modelContent);
return modelContent;
}
var worldToElement = Transform.PlaneToPlane(location, Plane.WorldXY);
if (ToModelInstanceDefinition(idMap, worldToElement, element, geometry) is ModelInstanceDefinition definition)
{
var elementToWorld = Transform.PlaneToPlane(Plane.WorldXY, location);
var attributes = ModelObject.Cast(new GH_InstanceReference(new InstanceReferenceGeometry(Guid.Empty, elementToWorld), definition)).ToAttributes();
attributes.Name = element.get_Parameter(ARDB.BuiltInParameter.ALL_MODEL_MARK)?.AsString() ?? string.Empty;
attributes.Url = element.get_Parameter(ARDB.BuiltInParameter.ALL_MODEL_URL)?.AsString() ?? string.Empty;
attributes.Layer = Category.ToModelContent(idMap) as ModelLayer;

modelContent = attributes.ToModelData() as ModelContent;
//idMap.Add(Id, modelContent);
return modelContent;
}
}
}
Expand Down
55 changes: 30 additions & 25 deletions src/RhinoInside.Revit.GH/Types/Instances/FamilyInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
namespace RhinoInside.Revit.GH.Types
{
using Convert.Geometry;
using External.DB;
using External.DB.Extensions;

[Kernel.Attributes.Name("Component")]
Expand Down Expand Up @@ -118,24 +119,21 @@ internal override ModelContent ToModelContent(IDictionary<ARDB.ElementId, ModelC

using (var geometry = element.GetGeometry(options))
{
if (geometry is ARDB.GeometryElement geometryElement)
{
var transform = element.GetTransform();
var location = new Plane(transform.Origin.ToPoint3d(), transform.BasisX.ToVector3d(), transform.BasisY.ToVector3d());
var worldToElement = Transform.PlaneToPlane(location, Plane.WorldXY);
var transform = element.GetTransform();
var location = new Plane(transform.Origin.ToPoint3d(), transform.BasisX.ToVector3d(), transform.BasisY.ToVector3d());
var worldToElement = Transform.PlaneToPlane(location, Plane.WorldXY);

if (ToModelInstanceDefinition(idMap, worldToElement, element, geometry) is ModelInstanceDefinition definition)
{
var elementToWorld = Transform.PlaneToPlane(Plane.WorldXY, location);
var attributes = ModelObject.Cast(new GH_InstanceReference(new InstanceReferenceGeometry(Guid.Empty, elementToWorld), definition)).ToAttributes();
attributes.Name = element.get_Parameter(ARDB.BuiltInParameter.ALL_MODEL_MARK)?.AsString() ?? string.Empty;
attributes.Url = element.get_Parameter(ARDB.BuiltInParameter.ALL_MODEL_URL)?.AsString() ?? string.Empty;
attributes.Layer = Category?.ToModelContent(idMap) as ModelLayer;

modelContent = attributes.ToModelData() as ModelContent;
//idMap.Add(Id, modelContent);
return modelContent;
}
if (ToModelInstanceDefinition(idMap, worldToElement, element, geometry) is ModelInstanceDefinition definition)
{
var elementToWorld = Transform.PlaneToPlane(Plane.WorldXY, location);
var attributes = ModelObject.Cast(new GH_InstanceReference(new InstanceReferenceGeometry(Guid.Empty, elementToWorld), definition)).ToAttributes();
attributes.Name = element.get_Parameter(ARDB.BuiltInParameter.ALL_MODEL_MARK)?.AsString() ?? string.Empty;
attributes.Url = element.get_Parameter(ARDB.BuiltInParameter.ALL_MODEL_URL)?.AsString() ?? string.Empty;
attributes.Layer = Category?.ToModelContent(idMap) as ModelLayer;

modelContent = attributes.ToModelData() as ModelContent;
//idMap.Add(Id, modelContent);
return modelContent;
}
}
}
Expand Down Expand Up @@ -453,18 +451,25 @@ internal ModelContent ToModelContent(IDictionary<ARDB.ElementId, ModelContent> i

if (Value is ARDB.FamilySymbol element)
{
using (var options = new ARDB.Options() { DetailLevel = ARDB.ViewDetailLevel.Fine })
var active = element.IsActive;
using (var scope = active ? null : element.Document.RollBackScope())
{
using (var context = GeometryDecoder.Context.Push())
if (!active)
{
context.Element = element;
context.Category = element.Category;
context.Material = element.Category?.Material;
element.Activate();
element.Document.Regenerate();
}

using (var geometry = element.GetGeometry(options))
using (var options = new ARDB.Options() { DetailLevel = ARDB.ViewDetailLevel.Fine })
{
using (var context = GeometryDecoder.Context.Push())
{
if (geometry is ARDB.GeometryElement geometryElement)
return GeometricElement.ToModelInstanceDefinition(idMap, Transform.Identity, element, geometryElement);
context.Element = element;
context.Category = element.Category;
context.Material = element.Category?.Material;

using (var geometry = element.GetGeometry(options))
return GeometricElement.ToModelInstanceDefinition(idMap, Transform.Identity, element, geometry);
}
}
}
Expand Down

0 comments on commit 7021f63

Please sign in to comment.