Today I needed to figure out a way to manage several hundred megs of MEP solids imported from Revit into DP.  These consisted of many parts housing thousands of end surfaces and HVAC/plumbing solids.  Eventually we’ll convert these into DP SysRouting objects, but for the time being, we are redistributing them into a more coherent product structure.  The current structure coming from Revit is pretty pathetic, since it considers each level its own zone.  This process will be slow and a resource hog, both in Revit and DP.

Revit imports into DP with thousands of faceted bodies at the part level.  This is a nightmare to manage, because the tree is slow to generate and transferring geometry to other parts can be time-consuming.  Also navigating the tree is lengthy due to large amount of scrolling required.

To resolve this, I wrote up a small but universalized VB script to deleted objects based on their selection.  Also, I wrote another if the geometry had already been removed by another user, but cleans up the tree and any empty Bodies. This code below removes not just the geometry in from the selection, but if it’s in a Body, then that parent is removed as well. (Note, this code is literally 0.0004 years old, so feel free to modify or post if you run into a bug.)

Code:
Sub CATMain()
'Author Nick Pisca 2009
Dim MySel As Selection
Set MySel = CATIA.ActiveDocument.Selection
Dim SelArr()
ReDim SelArr(MySel.Count - 1)
For X = 1 To MySel.Count
StatusBarShort X - 1, MySel.Count, "Selecting...  "
Set SelArr(X - 1) = MySel.Item(X).Value
Next X

For Y = 0 To UBound(SelArr)
StatusBarShort Y, UBound(SelArr), “Deleting… ”
If MySel.Count <> 0 Then
MySel.Clear
End If
Dim Par1
If HasParent(SelArr(Y)) = True Then
Set Par1 = SelArr(Y).Parent.Parent

If TypeName(Par1) = “Body” Then
MySel.Add Par1
MySel.Delete
End If
End If
Next Y

End Sub

The next VB macro lets the user select a part (by picking anything inside it), and it will clean up the model. Any empty Partbodies generated by the Revit export or by the deletion process will be removed. I like this better, because it’s a very universalized code that can be utilized for any case where empty bodies are populated throughout a CATPart. Since it’s using the GetContainingPart function as well, it can be used in the Project or Part workbench families.

Code:
Sub CATMain()
'Author Nick Pisca 2009
Dim MySel As Selection
Set MySel = CATIA.ActiveDocument.Selection
Dim MyPart As Part
Set MyPart = GetContainingPart(MySel.Item(1).Value)

Dim SelArr()
ReDim SelArr(MyPart.Bodies.Count – 1)
For X = 1 To MyPart.Bodies.Count
StatusBarShort X – 1, MyPart.Bodies.Count, “Selecting… ”
Set SelArr(X – 1) = MyPart.Bodies.Item(X)
Next X

For X = 0 To UBound(SelArr)
StatusBarShort X – 1, MyPart.Bodies.Count, “Deleting Empties… ”

Dim CurBody As Body
Set CurBody = SelArr(X) ‘MyPart.Bodies.Item(X)

If CurBody.Shapes.Count = 0 And CurBody.HybridShapes.Count = 0 And CurBody.Name <> “PartBody” Then
If MySel.Count <> 0 Then
MySel.Clear
End If
MySel.Add CurBody
MySel.Delete
End If
Next X

End Sub

Faceted Revit MEP model imported into DP.

Faceted Revit MEP model imported into DP.