I am currently working on a project in Revit and need to place mechanical fabrication hangers at specific points within the model. However, these parts cannot be used as family symbols.
// Collect all ducts
FilteredElementCollector ductshanger = new FilteredElementCollector(doc)
.OfCategory(BuiltInCategory.OST_FabricationHangers)
.WhereElementIsNotElementType();
// Initialize a list to store hanger names
List<string> hangerNames = new List<string>();
foreach (Element item in ductshanger)
{
FamilySymbol hangerSymbol2 = item as FamilySymbol;
TaskDialog.Show("Fabrication Hangers", $"Hanger :\n{hangerSymbol2 != null}");
if (hangerSymbol2 != null)
{
// Add the hanger name to the list
hangerNames.Add(hangerSymbol2.Name);
}
}
I used the task.dialog and the result was false.
Could you provide guidance or suggest an alternative approach?
Thank you in advance for your assistance.
Solved! Go to Solution.
Solved by jeremy_tammik. Go to Solution.
You cannot place fabrication parts in the same manner as family instances.
You can use the FabricationPart.CreateHanger method:
Its use is demonstrated by the FabricationPartLayout SDK sample.
hi @jeremy_tammik thank you for your reply,
I was just wondering is do you have any sample of using create hanger in some codes?
Yes. Look at the official Revit SDK samples. FabricationPartLayout is your man.
@jeremy_tammik Thank you, I checked those samples, but another problem is when I want to select my fabrication services it doesn't find it, while the item exists in the project.
// Step 1: Collect all Fabrication Parts in the project
FilteredElementCollector collector = new FilteredElementCollector(doc)
.OfClass(typeof(FabricationService));
// Step 4: Display the message in a TaskDialog
TaskDialog.Show("Fabrication Services", "f" + collector.Count());
// Assuming Services is initialized elsewhere or modify it here
FabricationService sb = Services?.FirstOrDefault(x => x.Name.Contains("(500PA)"));
if (sb == null)
{
TaskDialog.Show("Error", " FabricationService not found.");
return Result.Failed;
}
Hello, @jeremy_tammik . I tried to edit my code based on the sdk .
but when i select my hanger to placed the erorr that i faced in revit is "Please use FabricationPart.CreateHanger to create fabrication hanger.
Parameter name: button"
// Access the Fabrication Configuration
FabricationConfiguration config = FabricationConfiguration.GetFabricationConfiguration(doc);
if (config == null)
{
message = "Cannot retrieve the fabrication configuration.";
return Result.Failed;
}
m_services = config.GetAllLoadedServices();
if (m_services.Count == 0)
return Result.Failed;
// Get the FabricationService associated with the selected FabricationPart
int serviceId = part.ServiceId;
FabricationService partService = config.GetService(serviceId);
if (partService == null)
{
message = "Cannot retrieve fabrication service for the selected part.";
return Result.Failed;
}
// Locate the required service button
FabricationServiceButton sbButton = LocateButton(partService, 4, "Strut Hanger");
if (sbButton == null)
{
message = "The required button was not found in the selected service.";
return Result.Failed;
}
FabricationPart pt_rectStraight1 = CreateStraightPart(sbButton, 0, viewLevel.Id, 15.0);
if (pt_rectStraight1 == null)
{
message = "Failed to create hanger part.";
trans.RollBack();
return Result.Failed;
}
Connector conn1_straight1 = GetPrimaryConnector(pt_rectStraight1.ConnectorManager);
FabricationPart.CreateHanger(doc, sbButton, element.Id, conn1_straight1, 5.0, true);
I really appreciated that give me about about it.
Can't find what you're looking for? Ask the community or share your knowledge.