- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey, Revit friends need some help with this one!
I've been building a plugin that will insert flow arrows onto piping by using the "Attached To" under the pipe accessories family type. So far, I can select the pipe and place the arrows on the pipe in the X&Y location along the pipe curve, but the Z elevation doesn't seem to be copying from the picked point location. I believe part of the problem is that I don't have a pipe connector on this family; the reason being is I don't want to cut the pipe into smaller segments as I plan on using this for fabrication parts too. I have seen many Revit hangar plugins from DeWalt, Super-hangers, and Victaulic where we are able to place a hanger along the curve of a pipe without breaking having to break the pipe segment. In Victaulic's case, they have their own shared parameter that appears to be copied from the picked pipe's "Z" elevation, which ends up being the center-line elevation parameter of their hangar, and I am looking to try something of the same by changing the Flow Arrows built-in Parameter "Elevation from Level." Can someone help me to identify how I can extract the Z from the picked section of my pipe and overwrite the "Elevation from Level" parameter?
For those who look at this later, I plan to parlay this into other pipe accessories like hangers, sleeves, pipe guilds, and pipe stands once I get this elevation thing out. Below is the code I have so so far.
Below is my code so far:
using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.UI.Selection;
using System.Linq;
using Autodesk.Revit.DB.Plumbing;
namespace myRevitCommands
{
[Transaction(TransactionMode.Manual)]
public class FlowArrows : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
//Get Application ns document objects
UIApplication uiApp = commandData.Application;
UIDocument uiDoc = uiApp.ActiveUIDocument;
Document doc = uiApp.ActiveUIDocument.Document;
//HPSettings gpset = HPSetting.Default;
ElementId activeviewId = doc.ActiveView.Id;
Categories Cats = doc.Settings.Categories;
Selection sel= uiApp.ActiveUIDocument.Selection;
Transaction t = new Transaction(doc);
FamilySymbol familyPart = new FilteredElementCollector(doc)
.OfClass(typeof(FamilySymbol))
.OfCategory(BuiltInCategory.OST_PipeAccessory)
.Cast<FamilySymbol>()
.Where<FamilySymbol>(fam => fam.Family.Name.Contains("Flow Arrow"))
.FirstOrDefault<FamilySymbol>();
try
{
Reference reference = sel.PickObject(ObjectType.Element);
Pipe pipe = doc.GetElement(reference.ElementId) as Pipe;
LocationCurve locCurve = pipe.Location as LocationCurve;
Curve pipeCurve = locCurve.Curve;
XYZ point = sel.PickPoint("Please pick a location along pipe place the Flow Arrow");
Level level = doc.ActiveView.GenLevel;
if (level == null)
{
return Result.Failed;
}
t.Start("Flow Arrow");
if( !familyPart.IsActive)
{
familyPart.Activate();
doc.Regenerate();
}
//Code to create flow arrow on the Curve of the pipe
doc.Create.NewFamilyInstance(point, familyPart, pipe, level, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
t.Commit();
//Ends Command if user Right clicks or presses Esc
}
catch (Autodesk.Revit.Exceptions.OperationCanceledException)
{
return Result.Cancelled;
}
//Catch all other exceptions errors
catch (Exception ex)
{
message = ex.Message + " " + ex.StackTrace + " " + ex.Data + " " + ex.HResult;
return Result.Failed;
}
return Result.Succeeded;
}
}
public class MEPPickFilter : ISelectionFilter
{
public bool AllowElement(Element e)
{
bool IsMep = e.Category.Id.IntegerValue.Equals((int)BuiltInCategory.OST_PipeCurves) ||
e.Category.Id.IntegerValue.Equals((int)BuiltInCategory.OST_DuctCurves);
//e.Category.Id.IntegerValue.Equals((int)BuiltInCategory.OST_FabricationDuctwork);
//e.Category.Id.IntegerValue.Equals((int)BuiltInCategory.OST_FabricationPipework);
return IsMep;
}
public bool AllowReference(Reference r, XYZ p)
{
return false;
}
}
}
Solved! Go to Solution.
Developer Advocacy and Support +