I need to extract the data from the Geometrical Set. Like product structure will have many Geometrical Set and wanted to extract the values from each Geometrical Set.
Structure is like below.
oSel.Item(i)
---HybridBodies
---Item(1)
---Name "ABS123545-05-02"
---Item(2)
---Name "EN6045-05-08"
Here is the code which i am trying to get the data from the selected Geometrical set.
Sub GetGeoData()
'--------------------Define CATIA------------------------------------------
Dim CATIA
Dim MyDocument
Dim MyProduct
'Get CATIA or Launch it if necessary.
On Error Resume Next
Set CATIA = GetObject(, "CATIA.Application")
If CATIA Is Nothing Then
Set CATIA = CreateObject("CATIA.Application")
CATIA.Visible = True
End If
On Error GoTo 0
Set CATIA = GetObject("", "CATIA.Application")
Set MyDocument = CATIA.ActiveDocument
Set MyProduct = MyDocument.Product
MyRootPN = MyProduct.PartNumber
MyRootInstanceName = MyProduct.Name
Set oProductDoc = CATIA.ActiveDocument
Set oProdParameters = oProductDoc.Product.Parameters
Set oSel = oProductDoc.selection
'Only Select the Geometrical sets with name "Protection Set*"
oSel.Search "Name=Protection Set*,all"
oCount = oSel.count
j = 3
For i = 1 To oSel.count
Debug.Print oSel.Item(i).LeafProduct.PartNumber
Debug.Print oSel.Item(i).Value.HybridBodies.Item2(i).Name
**From each HybridBodies not able to get the item Name.**
j = j + 1
Next
oSel.Clear
End Sub
Need to extract the above values below the Geometrical Set.1 Please help me to get the same
You get the features (sketches, wireframe, surface) of a hybridbody by looping over the two collections HybridSketches
and Hybridshapes
.
Sub CATMain()
Dim oProductDoc as ProductDocument
Dim oSel as Selection
Dim i as Long
Dim j as Long
Dim oHybridBody as Hybridbody
Dim oSketch as Sketch
Dim oHybridShape as HybridShape
Set oProductDoc = CATIA.ActiveDocument
Set oSel = oProductDoc.Selection
oSel.Clear
' Only Select the Geometrical sets with name "Protection Set*"
oSel.Search "CATGmoSearch.OpenBodyFeature.Name=Protection Set*,all"
For i = 1 To oSel.count
MsgBox oSel.Item(i).LeafProduct.Name
Set oHybridBody = oSel.Item2(i).Value
MsgBox oHybridBody.Name
' loop over all hybridshapes
for j = 1 to oHybridBody.HybridShapes.Count
Set oHybridShape = oHybridBody.HybridShapes.Item(j)
MsgBox oHybridShape.Name
Next
' loop over all sketches
for j = 1 to oHybridBody.HybridSketches.Count
Set oSketch = oHybridBody.HybridSketches.Item(j)
MsgBox oSketch.Name
next
Next
oSel.Clear
End Sub
If you need both type of elements in the order like in the tree it is getting more complex.