masamunerx
Automotive
I want to exports the name and coordinates of all "isolated points" in folders that contain the word "STRUCTURE" only, from whole document (CATIA tree).
Actually I have found the code from this forum that created by Mr.das583
But that code was not satisfied my purpose.
This is the CATIA tree:
TEST.CATPart
BOB STRUCTURE
My purpose:
I want to export the coord of all isolated points under "STRUCTURE" named folder and the geoset name of GeoSet that exactly 1 level under "STRUCTURE" named folder that contain the points).
So the data in excel would read as:
Point 1 | x-coord | y-coord | z-coord | GeoSet2 |
Point 2 | x-coord | y-coord | z-coord | GeoSet2 |
Point 3 | x-coord | y-coord | z-coord | GeoSet4 |
But what I get :
Point 1 | x-coord | y-coord | z-coord | TEST.CATPart|
Point 2 | x-coord | y-coord | z-coord | TEST.CATPart|
Point 3 | x-coord | y-coord | z-coord | TEST.CATPart|
Here is the code that created by Mr.das583:
Sub CATMain()
On Error Resume Next
Dim docPart As Document
Dim myPart As Part
Dim hybBodies As HybridBodies
Dim hybBody As HybridBody
Dim hybShapes As HybridShapes
Dim hybShape As HybridShape
Dim arrXYZ(2)
Dim s As Long
Const Separator As String = ";"
Set docPart = CATIA.ActiveDocument
Set MyWkBnch = CATIA.ActiveDocument.GetWorkbench("SPAWorkbench")
'If no doc active
If Err.Number <> 0 Then
MsgBox "No Active Document", vbCritical
Exit Sub
End If
'Start Excel
'******************************************************************************
Err.Clear
On Error Resume Next
Set objGEXCELapp = GetObject(, "EXCEL.Application")
If Err.Number <> 0 Then
Err.Clear
Set objGEXCELapp = CreateObject("EXCEL.Application")
End If
objGEXCELapp.Application.Visible = True
Set objGEXCELwkBks = objGEXCELapp.Application.WorkBooks
Set objGEXCELwkBk = objGEXCELwkBks.Add
Set objGEXCELwkShs = objGEXCELwkBk.Worksheets(1)
Set objGEXCELSh = objGEXCELwkBk.Sheets(1)
objGEXCELSh.cells(1, "A") = "Name"
objGEXCELSh.cells(1, "B") = "X"
objGEXCELSh.cells(1, "C") = "Y"
objGEXCELSh.cells(1, "D") = "Z"
' What do you want to select - in this case a Geometrical Set
'Dim EnableSelectionFor(0)
'EnableSelectionFor(0) = "HybridBody"
' Reset the Selection
Set sSel = CATIA.ActiveDocument.Selection
sSel.Clear
AppActivate ("CATIA V5")
' Define Selection
'MsgBox "Please Select the Geometrical Set where you have the POINTS"
'userselection = sSel.SelectElement2(EnableSelectionFor, "Please select another Geometrical Set", False)
sSel.Search "(Name=*STRUCTURE* & CATPrtSearch.OpenBodyFeature),all"
' Evaluation if the selection is correct or not
'If userselection <> "Normal" Then
' MsgBox "Error with the selection"
' Exit Sub
'Else
' Set oHybridBody = sSel.Item(1).Value
'End If
Set oHybridBody = sSel.Item(1).Value
Set partDocument1 = CATIA.ActiveDocument
Dim selection1 As Selection
Set selection1 = partDocument1.Selection
selection1.Search "CATPrtSearch.Point,sel"
Dim part1 As Part
Set part1 = partDocument1.Part
Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = part1.HybridBodies
Dim hybridBody1 As HybridBody
'***********************************************************************************************************************
For s = 1 To selection1.Count
'Set Measure = MyWkBnch.GetMeasurable(selection1.Item(s).Reference)
Set hybShape = selection1.Item(s).Value
Set hybShapes = hybBody.HybridShapes
'MsgBox hybShape.Name 'returns point name
'Extract coordinates
hybShape.GetCoordinates arrXYZ
Set hybridBody1 = hybridBodies1.Item(s).Value
objGEXCELSh.cells(s + 1, "A") = hybShape.Name
objGEXCELSh.cells(s + 1, "B") = arrXYZ(0)
objGEXCELSh.cells(s + 1, "C") = arrXYZ(1)
objGEXCELSh.cells(s + 1, "D") = arrXYZ(2)
objGEXCELSh.cells(s + 1, "E") = hybridBodies1.Item(s).Value.Parent.Parent.ParentName
Next s
objGEXCELSh.columns("A").autofit
objGEXCELSh.columns("E").autofit
AppActivate ("Microsoft Excel")
End Sub
Please help me guys...
Note :
1. The code is okay if the points is not isolated points
2.sorry My English is terrible
Actually I have found the code from this forum that created by Mr.das583
But that code was not satisfied my purpose.
This is the CATIA tree:
TEST.CATPart
BOB STRUCTURE
GeoSet2
GeoSet3
Point 1
Point 2
GeoSet4
GeoSet5
Point 3
My purpose:
I want to export the coord of all isolated points under "STRUCTURE" named folder and the geoset name of GeoSet that exactly 1 level under "STRUCTURE" named folder that contain the points).
So the data in excel would read as:
Point 1 | x-coord | y-coord | z-coord | GeoSet2 |
Point 2 | x-coord | y-coord | z-coord | GeoSet2 |
Point 3 | x-coord | y-coord | z-coord | GeoSet4 |
But what I get :
Point 1 | x-coord | y-coord | z-coord | TEST.CATPart|
Point 2 | x-coord | y-coord | z-coord | TEST.CATPart|
Point 3 | x-coord | y-coord | z-coord | TEST.CATPart|
Here is the code that created by Mr.das583:
Sub CATMain()
On Error Resume Next
Dim docPart As Document
Dim myPart As Part
Dim hybBodies As HybridBodies
Dim hybBody As HybridBody
Dim hybShapes As HybridShapes
Dim hybShape As HybridShape
Dim arrXYZ(2)
Dim s As Long
Const Separator As String = ";"
Set docPart = CATIA.ActiveDocument
Set MyWkBnch = CATIA.ActiveDocument.GetWorkbench("SPAWorkbench")
'If no doc active
If Err.Number <> 0 Then
MsgBox "No Active Document", vbCritical
Exit Sub
End If
'Start Excel
'******************************************************************************
Err.Clear
On Error Resume Next
Set objGEXCELapp = GetObject(, "EXCEL.Application")
If Err.Number <> 0 Then
Err.Clear
Set objGEXCELapp = CreateObject("EXCEL.Application")
End If
objGEXCELapp.Application.Visible = True
Set objGEXCELwkBks = objGEXCELapp.Application.WorkBooks
Set objGEXCELwkBk = objGEXCELwkBks.Add
Set objGEXCELwkShs = objGEXCELwkBk.Worksheets(1)
Set objGEXCELSh = objGEXCELwkBk.Sheets(1)
objGEXCELSh.cells(1, "A") = "Name"
objGEXCELSh.cells(1, "B") = "X"
objGEXCELSh.cells(1, "C") = "Y"
objGEXCELSh.cells(1, "D") = "Z"
' What do you want to select - in this case a Geometrical Set
'Dim EnableSelectionFor(0)
'EnableSelectionFor(0) = "HybridBody"
' Reset the Selection
Set sSel = CATIA.ActiveDocument.Selection
sSel.Clear
AppActivate ("CATIA V5")
' Define Selection
'MsgBox "Please Select the Geometrical Set where you have the POINTS"
'userselection = sSel.SelectElement2(EnableSelectionFor, "Please select another Geometrical Set", False)
sSel.Search "(Name=*STRUCTURE* & CATPrtSearch.OpenBodyFeature),all"
' Evaluation if the selection is correct or not
'If userselection <> "Normal" Then
' MsgBox "Error with the selection"
' Exit Sub
'Else
' Set oHybridBody = sSel.Item(1).Value
'End If
Set oHybridBody = sSel.Item(1).Value
Set partDocument1 = CATIA.ActiveDocument
Dim selection1 As Selection
Set selection1 = partDocument1.Selection
selection1.Search "CATPrtSearch.Point,sel"
Dim part1 As Part
Set part1 = partDocument1.Part
Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = part1.HybridBodies
Dim hybridBody1 As HybridBody
'***********************************************************************************************************************
For s = 1 To selection1.Count
'Set Measure = MyWkBnch.GetMeasurable(selection1.Item(s).Reference)
Set hybShape = selection1.Item(s).Value
Set hybShapes = hybBody.HybridShapes
'MsgBox hybShape.Name 'returns point name
'Extract coordinates
hybShape.GetCoordinates arrXYZ
Set hybridBody1 = hybridBodies1.Item(s).Value
objGEXCELSh.cells(s + 1, "A") = hybShape.Name
objGEXCELSh.cells(s + 1, "B") = arrXYZ(0)
objGEXCELSh.cells(s + 1, "C") = arrXYZ(1)
objGEXCELSh.cells(s + 1, "D") = arrXYZ(2)
objGEXCELSh.cells(s + 1, "E") = hybridBodies1.Item(s).Value.Parent.Parent.ParentName
Next s
objGEXCELSh.columns("A").autofit
objGEXCELSh.columns("E").autofit
AppActivate ("Microsoft Excel")
End Sub
Please help me guys...
Note :
1. The code is okay if the points is not isolated points
2.sorry My English is terrible