Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting geometrical set name of Isolated points to excel 2

Status
Not open for further replies.

masamunerx

Automotive
Sep 22, 2020
2
JP
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
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
 
Replies continue below

Recommended for you

the reason why the code is not working on isolated points, is because CATIA considers those as parameters.
what you could do is set define-in-work-object on that very point (CATIA will then set define-in-work-object onto the GeoSet containing the point)
take the name of the Active GeoSet into your excel

I hope you can try this on your own--this forum is NOT for delivering ready to use code, rather to help you become better at scripting...

regards,
LWolf
 
Mr. LWolf
Thank you for your advice,
I understand what you're suggesting,
however I don't really know how to put your suggestion into the code.
Since I just started learning VBA.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top