Hanging MEP runs can be a pain if you don’t have a 3D wireframe. We received a bunch of solids earlier this week which need to be DP SysRouting runs.  Unfortunately the topology VB scripting commands are good for shit, so I can’t create a solids-to-runs converter.  Probably the worst thing about VB scripting in DP/CATIA is the selection object and DS won’t fix it, which would be a great discussion for a different post.  Anyway, in the meantime, I needed a way to get the base points for manually hanging runs on the lines in-between (which are manually place for now).

This script will take the faces from a selection and place COG points on the face.  Note, this only works on flat faces, so if you have non-faceted cylinders (runs that are round in section), you’ll only get the center of the pipe in 3D.  Also, if your tubes are asymmetrical in cross-section, they will not be in the center of the pipe, but rather the centroid of the pipe section.

Also, you’ll need to make a few things prior to running this simple code.  Make a new part and call it PlaceCOG.CATPart.  Inside it, make a point with a formula of CenterOfGravity().  Make that point a PowerCopy named “COGPT.”  Save this file on your local harddrive in a folder called “PowerCopies.”  Unfortunately there is no COG command in VB other than a numerical calculation with the SPAWorkbench, which is not live.  To maintain a live connection to the extracted faces of the solids, use this PowerCopy workaround.

MEP Solids Point Instantiator Script Output

MEP Solids Point Instantiator Script Output

Code:

'******************************************************************************************************
'*****  Name:  Hanging Points for SYSRouting
'*****  Author:  Nick Pisca
'*****  Support:  nicholas.pisca@gehrytechnologies.com  &  nickpisca@gmail.com
'*****  Date:  August 4, 2009
'*****  Description:
'*****
'*****  Status:  In Prog
'*****  Advancements:
'*****  Requirements:
'*****  Compatibility:  V1R4
'******************************************************************************************************
'*****  Declarations

Code:

Dim MyDoc As Document
Dim MySel As Selection
Dim MyPart As Part
Dim TheSPAWorkbench
Dim SFactory As ShapeFactory
Dim MyHSFactory As HybridShapeFactory
Dim InstFactory As InstanceFactory
Dim instance As ShapeInstance
Dim Zaxis As HybridShapeDirection
Dim XYPl
Dim ParentSet As HybridBody

Code:

Sub CATMain()
Set TheSPAWorkbench = CATIA.ActiveDocument.GetWorkbench("SPAWorkbench")
Set MyDoc = CATIA.ActiveDocument
Set MySel = MyDoc.Selection
If MySel.Count = 0 Then
Exit Sub
End If

Code:

Set MyPart = GetContainingPart(MySel.Item(1).Value)
Set MyHSFactory = MyPart.HybridShapeFactory
Set SFactory = MyPart.ShapeFactory
Dim MyHybridBodies As HybridBodies
Set MyHybridBodies = MyPart.HybridBodies
Set Zaxis = MyHSFactory.AddNewDirectionByCoord(0, 0, 1)
Set XYPl = MyPart.OriginElements.PlaneXY

Code:

Set InstFactory = MyPart.GetCustomerFactory("InstanceFactory")
FixInstanceFactory "COGPT", "C:\PowerCopies\PlaceCOG.CATPart"

Code:

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

Code:

Dim ParentSet As HybridBody
Set ParentSet = MyPart.HybridBodies.Add
ParentSet.Name = "PARENT_SET"
Dim ConstSET As HybridBody
Set ConstSET = ParentSet.HybridBodies.Add
ConstSET.Name = "CONST_SET"
Dim DestSET As HybridBody
Set DestSET = ParentSet.HybridBodies.Add
DestSET.Name = "DEST_SET"

Code:

For X = 0 To UBound(SelArr)
StatusBarShort X, UBound(SelArr), "Making COG's...  "
If MySel.Count <> 0 Then
MySel.Clear
End If
Dim MainExt
Set MainExt = SelArr(X)
MySel.Add MainExt
TempArr = MakeArrayFromSearch("Topology.face,sel")
If UBound(TempArr) < 20 Then
For Y = 0 To UBound(TempArr) '- 1
StatusBarShort X, UBound(SelArr), "Making COG's...  "
Set hybridshapeextract1 = MyHSFactory.AddNewExtract(TempArr(Y - 0))
ConstSET.AppendHybridShape hybridshapeextract1
hybridshapeextract1.Name = MainExt.Name & "_" & X & "_" & Y
IsUpdatable hybridshapeextract1
MyHSFactory.GSMVisibility hybridshapeextract1, 0

Code:

 MyPart.InWorkObject = DestSET
InstFactory.BeginInstantiate
InstFactory.PutInputData "SURF", hybridshapeextract1
InstFactory.EndInstantiate
IsUpdatable CurSet
Dim CurUDF
Set CurUDF = DestSET.HybridShapes.Item(DestSET.HybridShapes.Count)
CurUDF.Name = CurUDF.Name & "_" & X & "_" & Y
IsUpdatable CurUDF
Next Y
End If
Next X
End Sub