Application: FabricationPartLayout
Revit Platform: MEP
Revit Version: 2017.0
First Released For: 2016.0
Programming Language: C#
Skill Level: Medium
Category: MEP
Type: ExternalCommand

Subject: Fabrication Part
Summary: 
This sample shows how to use the Fabrication Part API to create a sample layout and make modifications to fabrication data in the model. This includes:
•	rectangular and round ductwork
•	tap placement
•	rotations
•	straight optimizations
•	connections to a generic Revit family instance
•	stretch fabrication part fitting to a target element
•	converting design elements into fabrication parts
•	renumbering the straight/coupling fabrication parts
•	loading and unloading of item files
•	exporting fabrication parts to PCF and MAJ
•	accessing fabrication part mesh geometry.

Classes: 
Autodesk.Revit.DB.Connector
Autodesk.Revit.DB.ConnectorSet
Autodesk.Revit.DB.Document
Autodesk.Revit.DB.ElementId
Autodesk.Revit.DB.FabricationAncillaryUsage
Autodesk.Revit.DB.FabricationConfiguration
Autodesk.Revit.DB.FabricationDimensionDefinition
Autodesk.Revit.DB.FabricationItemFile
Autodesk.Revit.DB.FabricationItemFolder
Autodesk.Revit.DB.FabricationRodInfo
Autodesk.Revit.DB.FabricationPart
Autodesk.Revit.DB.FabricationService
Autodesk.Revit.DB.FabricationServiceButton
Autodesk.Revit.DB.FamilyInstance
Autodesk.Revit.DB.Level
Autodesk.Revit.DB.MEPConnectorInfo
Autodesk.Revit.DB.Parameter
Autodesk.Revit.DB.Fabrication.CustomDataType
Autodesk.Revit.DB.Fabrication.DesignToFabricationConverter
Autodesk.Revit.DB.Fabrication.DesignToFabricationConverterResult
Autodesk.Revit.DB.Fabrication.FabricationAncillaryType
Autodesk.Revit.DB.Fabrication.FabricationAncillaryUsageType
Autodesk.Revit.DB.Fabrication.FabricationPartCompareType
Autodesk.Revit.DB.Fabrication.FabricationPartFitResult
Autodesk.Revit.DB.Fabrication.FabricationPartRouteEnd
Autodesk.Revit.DB.Fabrication.FabricationUtils
Autodesk.Revit.UI.IExternalCommand

Project Files: 
FabricationPartLayout.cs
It contains the class FabricationPartLayout which inherits from interface IExternalCommand and implements the Execute method. This class shows the user how to create a sample layout containing fabrication parts.

OptimizeStraights.cs
It contains the class OptimizeStraights which inherits from interface IExternalCommand and implements the Execute method. This class shows the user how to use the Optimize Lengths method based on a user selection.

StretchAndFit.cs
It contains the class StretchAndFit which inherits from interface IExternalCommand and implements the Execute method. This class shows the user how to use the StretchAndFit method based on a user selection.

ConvertToFabrication.cs
It contains the class ConvertToFabrication which inherits from interface IExternalCommand and implements the Execute method. This class shows the user how to use the DesignToFabrication method based on a user selection.

PartRenumber.cs
It contains the class PartRenumber which inherits from interface IExternalCommand and implements the Execute method. This class shows the user how to use the FabricationPart.ItemNumber and renumber a selection of parts, and using the Fabrication.IsSameAs method.

ButtonPaletteExclusions.cs
It contains the class ButtonPaletteExclusions which inherits from interface IExternalCommand and implements the Execute method. This class shows the user how to override the default fabrication service palette and button exclusions for routing operations.

Ancillaries.cs
It contains the class Ancillaries which inherits from interface IExternalCommand and implements the Execute method. This class shows the user how to obtain the ancillary information for a selected fabrication part.

CustomData.cs
It contains the classes GetCustomData and SetCustomData which inherit from the interface IExternalCommand and implements the Execute method. This class shows the user how to obtain the ancillary information for a selected fabrication part. The GetCustomData class shows a user how to obtain fabrication custom data on a fabrication part, whilst the SetCustomData class shows a user how to set fabrication custom data.

ExportToPCF.cs
It contains the class ExportToPCF which inherits from interface IExternalCommand and implements the Execute method. This class shows the user how to export a selection of fabrication parts to a PCF file.

FabPartGeometry.cs
It contains the class FabPartGeometry which inherits from interface IExternalCommand and implements the Execute method. This class shows the user how to access fabrication part mesh geometry.

PartInfo.cs
It contains the class PartInfo which inherits from interface IExternalCommand and implements the Execute method. This class shows the user how to get a variety of fabrication part properties.

HangerRods.cs
It contains the classes DetachRods, DoubleRodLength, HalveRodLength, IncreaseRodStructureExtension and DecreaseRodStructureExtension which inherit from the interface IExternalCommand and implements the Execute method. These classes show a user how to detach hanger rods from their hosted structure, how to change the size of the rod lengths and also the size of the rod structure extensions.

SplitStraight.cs
It contains the class SplitStraight which inherits from interface IExternalCommand and implements the Execute method. This class shows the user how to split a straight into two segments.

ItemFile.cs
    It contains the classes LoadAndPlaceNextItemFile and UnloadUnusedItemFiles which inherit from the interface IExternalCommand and implements the Execute command. These classes show a user how to load and unload fabrication item files from within the configuration’s item folders structure.

SaveAsFabricationJob.cs
    It contains the class ExportToMAJ which inherits from interface IExternalCommand and implements the Execute method. This class shows the user how to export a selection of fabrication parts to a MAJ file.

Description: 
This sample provides the following functionalities.
-	Creates a sample layout from fabrication parts
-	Access fabrication configuration information
-	Connects fabrication taps to fabrication straight parts
-	Rotates fabrication parts about its connected end
-	Modify specification
-	Modify insulation specification
- 	Modify fabrication material
-	Modify fabrication connector
-	Place fabrication taps on fabrication straight parts
-   	Place fabrication hangers on fabrication straight parts
-	Optimize the lengths of fabrication straight parts based on user selection
-	Stretch and fit a fabrication part to a target connector.
-	Convert design elements into fabrication parts
-	Renumber a selection of fabrication parts
-	View ancillary data
-	Set service palette and button exclusions
-	View and set part custom data
-	Export a selection of fabrication parts to a PCF file
-	View fabrication part data
-	Adjust hanger rod lengths, structural extensions and detach from their structural hosts
-	Split straights into two equal segments
-	Load and place additional parts
-	Unload unused additional parts
-	Export a selection of fabrication parts to a MAJ file
-	Access fabrication part mesh geometry.

Instructions: 
Open Revit application.
1.	Fabrication Part Layout
a.   Load FabricationPartLayout.rvt
b.   Execute the command.
Expected result: Draws a sample layout containing fabrication parts connected to the existing Revit AHU instance.

2.	Optimize Straights
a.	Load FabricationPartLayout.rvt or add some fabrication part straights.
b.	Make a selection of the fabrication parts, making sure to select some of the longer fabrication part straights.
c.	Execute the command

Expected result: Fabrication part lengths longer than the standard length will be optimized into smaller straight parts.

3.	Stretch and Fit
a.	Load StretchAndFit.rvt.
b.	Select the two radius bends in the model.
c.	Execute the command

Expected result: The radius bend should stretch and fit and connect to the selected straight.

4. 	Convert To Fabrication
a.	ConvertToFabrication.rvt.
b.	Select the duct layout
c.	Execute the command

Expected result: The duct layout should convert to fabrication parts.

5. Part Renumber
	a. Make a selection of fabrication parts
	b. Execute the command
	
Expected result: The fabrication parts Item Number property should be filled in and all parts that are the same have the same number. The fields ignored are based on ignoring the part’s notes, order number and service.

6. Button and Palette Exclusions
	a. Load ButtonPaletteExclusions.rvt
	b. Execute the command

Expected result: The Square Bend button is excluded and the Round Bought Out service palette is excluded.

7. Ancillaries
	a. Execute the command
	b. Select a fabrication part

Expected result: A dialog should be presented with the ancillary information for the selected fabrication part.

8. Get Custom Data
	a. Load CustomData.rvt
	b. Execute the command
	c. Select a fabrication part

Expected result: A dialog should be presented with the custom data information for the selected fabrication part.

9. Set Custom Data
	a. Load CustomData.rvt
	b. Execute the command
	c. Select a fabrication part

Expected result: A dialog should be presented with the custom data information for the selected fabrication part, detailing the before and after values.

10. Export to PCF
	a. Select some fabrication parts
	b. Execute the command

	Expected result: A PCF file will be created at the specified location.

11. Display Part Info
	a. Execute the command
	b. Select a fabrication part

	Expected result: A dialog should be presented with fabrication part information.

12. Detach Hanger Rods
	a. Load HangerRods.rvt
	b. Execute the command
	c. Select a fabrication part hanger

	Expected result: The hanger rods should no longer be hosted by their structural host.

13. Double Rod Lengths
	a. Load HangerRods.rvt
	b. Execute the command
c. Select a fabrication part hanger that is not attached to structure. Use the Detach Hanger Rods command first, if necessary

	Expected result: The hanger rod lengths should double in size.

14. Halve Rod Lengths
	a. Load HangerRods.rvt
b. Execute the command
c. Select a fabrication part hanger that is not attached to structure. Use the Detach Hanger Rods command first, if necessary

Expected result: The hanger rod lengths should halve in size.

15. Increase Rod Structure Extension
	a. Load HangerRods.rvt
	b. Execute the command
	c. Select a fabrication part hanger that is attached to structure. 

Expected result: The hanger rod lengths will increase by 1 foot in length and are still attached to structure.

16. Decrease Rod Structure Extension
	a. Load HangerRods.rvt
	b. Execute the command
	c. Select a fabrication part hanger that is attached to structure. 

Expected result: The hanger rod lengths will decrease by 1 foot in length and are still attached to structure.

17. Split Straight
	a. Execute the command
	b. Select a fabrication part straight segment

	Expected result: The straight will split into two equal segments. 
18. Load and Place Next Item File
	a. Load a project with a valid fabrication configuration that you have access to the source.
	b. Execute the command.

Expected result: The first item file that has not been previously loaded will be loaded into the configuration. A new fabrication part will be created from the loaded item file, placed and selected into the model.

19. Unload Unused Item Files
a. Load a project that has item files that have been loaded into the configuration but have not been used.
b. Execute the command.

Expected result: The unused loaded item files will be unloaded from the configuration.

20. Export to MAJ
	a. Make a selection of fabrication parts.
	b. Execute the command

	Expected result: A MAJ file will be created at the specified location. 

21. Access Fabrication Part Geometry
	a. Select some fabrication parts
	b. Execute the command

	Expected result: Mesh triangle face geometry will be exported to CSV files.