- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi All,
I know stacked walls are not easy to work with. I, however, am trying to align a family instance, say a desk, to the interior face of a stacked wall. For getting the interior face, I am getting the interior face of the first wall of the stacked wall members, which is the bottom wall. But this approach throws error saying;
"The two references are not geometrically aligned"
Here is the code (I am in Macro environnment);
using System;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
using System.Collections.Generic;
using System.Linq;
namespace FamilyInstanceStudy
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.DB.Macros.AddInId("6380B2D3-2530-414B-9253-2BE5EDE6EA3A")]
public partial class ThisDocument
{
UIDocument uidoc;
Document doc;
private void Module_Startup(object sender, EventArgs e)
{
uidoc = Application.ActiveUIDocument;
doc = uidoc.Document;
}
private void Module_Shutdown(object sender, EventArgs e)
{
}
#region Revit Macros generated code
private void InternalStartup()
{
this.Startup += new System.EventHandler(Module_Startup);
this.Shutdown += new System.EventHandler(Module_Shutdown);
}
#endregion
public void AlignTest()
{
Wall stackedWall = doc.GetElement(uidoc.Selection.PickObject(ObjectType.Element, new WallFilter(), "Pick a stacked wall")) as Wall;
FamilyInstance familyInstance = doc.GetElement(uidoc.Selection.PickObject(ObjectType.Element, new FamilyInstanceFilter(), "Pick the desk")) as FamilyInstance;
Reference frontBack = familyInstance.GetReferences(FamilyInstanceReferenceType.CenterFrontBack).FirstOrDefault();
if (stackedWall != null)
{
Wall bottomWall = doc.GetElement(stackedWall.GetStackedWallMemberIds().FirstOrDefault()) as Wall;
Reference sideFaceInterior = HostObjectUtils.GetSideFaces(bottomWall, ShellLayerType.Interior).FirstOrDefault();
using (Transaction t = new Transaction(doc, "al;ign family instance"))
{
t.Start();
doc.Create.NewAlignment(doc.ActiveView, frontBack, sideFaceInterior);
t.Commit();
}
}
}
}
public class WallFilter : ISelectionFilter
{
public bool AllowElement(Element elem)
{
return elem is Wall && ((Wall)elem).IsStackedWall;
}
public bool AllowReference(Reference reference, XYZ position)
{
return false;
}
}
public class FamilyInstanceFilter : ISelectionFilter
{
public bool AllowElement(Element elem)
{
return elem is FamilyInstance;
}
public bool AllowReference(Reference reference, XYZ position)
{
return false;
}
}
}
Solved! Go to Solution.