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!

Exporting Geometrical Set Name of Isolated Point to Excel 2

Status
Not open for further replies.

rhooshchow

New member
Jul 22, 2020
2
SG
Hi, I have a code that exports the name and coordinate of all points and its the geometrical set and part name along with it. However, the name of the geometrical does not appear correctly if the point is isolated, and i cant figure out how to solve for this.

Example of tree diagram:
TEST.CATPart
---GeoSet2
------Point 1

Data in Excel that i got:
Point 1 | x-coord | y-coord |z-coord | Parameters | Test

Data in Excel that i need:
Point 1 | x-coord | y-coord |z-coord | GeoSet2 | Test

Here is the code i have so far:
Sub CATMain()

On Error Resume Next

Dim hybBodies As HybridBodies
Dim hybBody As HybridBody
Dim hybShapes As HybridShapes
Dim hybShape As HybridShape

Dim arrXYZ(2)
Dim s As Long

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"
objGEXCELSh.cells(1, "E") = "Geometrical Set"
objGEXCELSh.cells(1, "F") = "Part"

'Export to Excel
'******************************************************************************

Set partDocument1 = CATIA.ActiveDocument
Dim selection1 As Selection
Set selection1 = partDocument1.Selection

selection1.Search "CATPrtSearch.Point,sel"

For s = 1 To selection1.Count
Set hybShape = selection1.Item(s).Value
hybShape.GetCoordinates arrXYZ

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") = hybShape.Parent.name
objGEXCELSh.cells(s + 1, "F") = hybShape.Parent.Parent.name

Next s

objGEXCELSh.columns("A").autofit
objGEXCELSh.columns("B").autofit
objGEXCELSh.columns("C").autofit
objGEXCELSh.columns("D").autofit
objGEXCELSh.columns("E").autofit
objGEXCELSh.columns("F").autofit

AppActivate ("Microsoft Excel")

End Sub

Any help you can provide is very much appreciated!!
 
Replies continue below

Recommended for you

Hi.

Try:

set hybShapes = hybShape.Parent
set hybBody = hybShapes.Parent

objGEXCEL..."E") = hybBody.Name
 
if a point is isolated, it is part of the parameters collection.
What you can do is set "define in work object" on the point-- that will set the geometrical set containing the point as the active hybridbody.
then you can get that geo set's name...

regards,
LWolf
 
Much thanks guys,
I combined both Little Cthullu and LWolf suggestions and got what i wanted, i will leave the code below.

Cheers

Option Explicit

Sub CATMain()

Dim ObjEXCELapp As Object
Dim ObjEXCELwkBks As Object
Dim ObjEXCELwkBk As Object
Dim ObjEXCELwkShs As Object
Dim ObjEXCELSh As Object
Dim FileSys As Object
Dim FilePath As String
Dim FileObj As File
Dim FoldObj As Folder
Dim Files1 As Files
Dim OpenDoc As Document
Dim i, g, s, o As Long
Dim ArrXYZ(2) As Variant

Set ObjEXCELapp = CreateObject("EXCEL.Application")
Set ObjEXCELwkBks = ObjEXCELapp.Application.WorkBooks
Set ObjEXCELwkBk = ObjEXCELwkBks.Add
Set ObjEXCELwkShs = ObjEXCELwkBk.Worksheets(1)
Set ObjEXCELSh = ObjEXCELwkBk.Sheets(1)

ObjEXCELSh.cells(1, "A") = "Number"
ObjEXCELSh.cells(1, "B") = "Point Name"
ObjEXCELSh.cells(1, "C") = "X"
ObjEXCELSh.cells(1, "D") = "Y"
ObjEXCELSh.cells(1, "E") = "Z"
ObjEXCELSh.cells(1, "F") = "Geometrical Set"
ObjEXCELSh.cells(1, "G") = "Part"

Set FileSys = CATIA.FileSystem

FilePath = CATIA.FileSelectionBox("Select a Catalog Part File.", "*.CATPart", CatFileSelectionModeOpen)

Set FileObj = FileSys.GetFile(FilePath)

Set FoldObj = FileObj.ParentFolder

Set Files1 = FoldObj.Files

o = 1

For i = 1 To Files1.Count

Set OpenDoc = CATIA.Documents.Open(Files1.Item(i).Path)

Dim PartDocument1 As Document
Set PartDocument1 = CATIA.ActiveDocument
Dim Part1 As Part
Set Part1 = PartDocument1.Part

Dim HybBodies1 As HybridBodies
Set HybBodies1 = Part1.HybridBodies
Dim Selection1 As Selection
Set Selection1 = PartDocument1.Selection
Dim HybBody1 As HybridBody
Dim HybShape1 As HybridShape

For g = 1 To HybBodies1.Count

Set HybBody1 = HybBodies1.Item(g)

Part1.InWorkObject = HybBody1

Selection1.Clear
Selection1.Add HybBody1
Selection1.Search "CATPrtSearch.Point,sel"

For s = 1 To Selection1.Count

Set HybShape1 = Selection1.Item(s).Value
HybShape1.GetCoordinates ArrXYZ

ObjEXCELSh.cells(o + 1, "A") = o
ObjEXCELSh.cells(o + 1, "B") = HybShape1.Name
ObjEXCELSh.cells(o + 1, "C") = ArrXYZ(0)
ObjEXCELSh.cells(o + 1, "D") = ArrXYZ(1)
ObjEXCELSh.cells(o + 1, "E") = ArrXYZ(2)
ObjEXCELSh.cells(o + 1, "F") = HybBody1.Name
ObjEXCELSh.cells(o + 1, "G") = HybShape1.Parent.Parent.Name

o = o + 1

Next s

Next g

CATIA.ActiveDocument.Close

Next i

ObjEXCELSh.columns("A").autofit
ObjEXCELSh.columns("B").autofit
ObjEXCELSh.columns("C").autofit
ObjEXCELSh.columns("D").autofit
ObjEXCELSh.columns("E").autofit
ObjEXCELSh.columns("F").autofit
ObjEXCELSh.columns("G").autofit

ObjEXCELapp.Application.Visible = True

End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top