- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey Everyone, Im trying to create a ray projection that finds the closest beam or slab from a column and attach it to the top to beam/slab found by the ray projection. For some reason i cant get it to find the beams i want it to attach too. It only finds the slab. Any Ideas?
using (Transaction tx = new Transaction(doc))
{
tx.Start("Adjust Column Heights");
foreach (ElementId elemId in selectedIds)
{
Element elem = uidoc.Document.GetElement(elemId);
//checks if element is column
if ((BuiltInCategory)elem.Category.Id.IntegerValue == BuiltInCategory.OST_StructuralColumns)
{
allColumns++;
//get column location
XYZ elemLoc = (elem.Location as LocationPoint).Point;
//ray direction for raybounce
XYZ newPP = new XYZ(elemLoc.X, elemLoc.Y, elemLoc.Z + 1);
XYZ rayd = new XYZ(0, 0, 1);
List<BuiltInCategory> builtInCats = new List<BuiltInCategory>();
builtInCats.Add(BuiltInCategory.OST_Floors);
builtInCats.Add(BuiltInCategory.OST_StructuralFraming);
ElementMulticategoryFilter filter = new ElementMulticategoryFilter(builtInCats);
//ElementCategoryFilter filter = new ElementCategoryFilter(BuiltInCategory.OST_Floors);
ReferenceIntersector refI = new ReferenceIntersector(filter, FindReferenceTarget.All, (View3D)doc.ActiveView);
ReferenceWithContext refC = refI.FindNearest(newPP, rayd);
if(refC != null)
{
Reference reference = refC.GetReference();
//gets reference element id & Element
ElementId refEle = reference.ElementId;
Element refElem = uidoc.Document.GetElement(refEle);
ColumnAttachment.AddColumnAttachment(doc, elem as FamilyInstance, refElem , 1, ColumnAttachmentCutStyle.None, ColumnAttachmentJustification.Minimum, 0);
successColumns++;
}
else
{
//change color of columns to red
Color color = new Color((byte)255, (byte)0, (byte)0);
OverrideGraphicSettings ogs = new OverrideGraphicSettings();
ogs.SetProjectionLineColor(color);
uidoc.ActiveView.SetElementOverrides(elem.Id, ogs);
}
}
}
TaskDialog.Show("Columns Changed", string.Format("{0} of {1} Columns Changed", successColumns, allColumns));
tx.Commit();
}
This it what it looks Like Before I run it:
This is what it looks like after i run it (it only finds the slabs): I want it to stop at the bottom of beams & slabs
Sooo... i tried to change the code to just pick up the beams
using (Transaction tx = new Transaction(doc))
{
tx.Start("Adjust Column Heights");
foreach (ElementId elemId in selectedIds)
{
Element elem = uidoc.Document.GetElement(elemId);
//checks if element is column
if ((BuiltInCategory)elem.Category.Id.IntegerValue == BuiltInCategory.OST_StructuralColumns)
{
allColumns++;
//get column location
XYZ elemLoc = (elem.Location as LocationPoint).Point;
//ray direction for raybounce
XYZ newPP = new XYZ(elemLoc.X, elemLoc.Y, elemLoc.Z + 1);
XYZ rayd = new XYZ(0, 0, 1);
//List<BuiltInCategory> builtInCats = new List<BuiltInCategory>();
//builtInCats.Add(BuiltInCategory.OST_Floors);
//builtInCats.Add(BuiltInCategory.OST_StructuralFraming);
//ElementMulticategoryFilter filter = new ElementMulticategoryFilter(builtInCats);
ElementCategoryFilter filter = new ElementCategoryFilter(BuiltInCategory.OST_StructuralFraming);
ReferenceIntersector refI = new ReferenceIntersector(filter, FindReferenceTarget.All, (View3D)doc.ActiveView);
ReferenceWithContext refC = refI.FindNearest(newPP, rayd);
if(refC != null)
{
Reference reference = refC.GetReference();
//gets reference element id & Element
ElementId refEle = reference.ElementId;
Element refElem = uidoc.Document.GetElement(refEle);
ColumnAttachment.AddColumnAttachment(doc, elem as FamilyInstance, refElem , 1, ColumnAttachmentCutStyle.None, ColumnAttachmentJustification.Minimum, 0);
successColumns++;
}
else
{
//change color of columns to red
Color color = new Color((byte)255, (byte)0, (byte)0);
OverrideGraphicSettings ogs = new OverrideGraphicSettings();
ogs.SetProjectionLineColor(color);
uidoc.ActiveView.SetElementOverrides(elem.Id, ogs);
}
}
}
TaskDialog.Show("Columns Changed", string.Format("{0} of {1} Columns Changed", successColumns, allColumns));
tx.Commit();
}
This is what i have before:
This is what i have after (circled in blue is what didnt attach to the beam above. Some did attach):
so why is this? And is there anything i can do to fix it.
Thanks ahead of time for any responses!
Solved! Go to Solution.