gm2gabriel
Aerospace
Hello,
First of all, this is a great forum, it already helped me a lot in the past. So, I would like to ask for help in this specific subject:
I have a few Parts inside a Product and I would like to export to Excel XYZ coordinates of a few notable points. Those notable points are all inside the same .CATPart.
Looking in the forum, I have already found a macro (CATScript) to this, however it only works in the Part Design environment, i.e. when the .CATPart is open in a new window.
I have no programming skills in Catia... Is it possible to adapt this macro to work in the Assembly Design environment? Or even when a CATPart is active in the tree, but opened in a new window?
What I am really trying to do is put this macro inside another macro that will run in a .CATProduct, this Product have a Design Table and for each line of this design table I would like to export XYZ of a few points inside a .CATPart.
In the attached image are the two points I am trying to export XYZ coordinates. Note they are under a Part and I am in the Assembly Design environment.
The following CATScript macro only works with a .CATPart
------
Dim objGEXCELapp As Object
Dim objGEXCELwkBks As Object
Dim objGEXCELwkBk As Object
Dim objGEXCELwkShs As Object
Dim objGEXCELSh As Object
Dim FS, f, f1, fc, s
Dim coords(2) As Variant
Dim partDocument1
Sub CATMain()
CATIA.ActiveDocument.Selection.Search "CATGmoSearch.Point,all"
StartEXCEL
ExportPoint
End Sub
'******************************************************************************
Sub StartEXCEL()
'******************************************************************************
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"
End Sub
'******************************************************************************
Sub ExportPoint()
'******************************************************************************
For i = 1 To CATIA.ActiveDocument.Selection.Count
Set Selection = CATIA.ActiveDocument.Selection
Set Element = Selection.Item(i)
Set Point = Element.Value
'Write PointData to Excel Sheet
Point.GetCoordinates (coords)
objGEXCELSh.Cells(i + 1, "A") = Point.Name
objGEXCELSh.Cells(i + 1, "B") = coords(0)
objGEXCELSh.Cells(i + 1, "C") = coords(1)
objGEXCELSh.Cells(i + 1, "D") = coords(2)
Next
End Sub
------
First of all, this is a great forum, it already helped me a lot in the past. So, I would like to ask for help in this specific subject:
I have a few Parts inside a Product and I would like to export to Excel XYZ coordinates of a few notable points. Those notable points are all inside the same .CATPart.
Looking in the forum, I have already found a macro (CATScript) to this, however it only works in the Part Design environment, i.e. when the .CATPart is open in a new window.
I have no programming skills in Catia... Is it possible to adapt this macro to work in the Assembly Design environment? Or even when a CATPart is active in the tree, but opened in a new window?
What I am really trying to do is put this macro inside another macro that will run in a .CATProduct, this Product have a Design Table and for each line of this design table I would like to export XYZ of a few points inside a .CATPart.
In the attached image are the two points I am trying to export XYZ coordinates. Note they are under a Part and I am in the Assembly Design environment.
The following CATScript macro only works with a .CATPart
------
Dim objGEXCELapp As Object
Dim objGEXCELwkBks As Object
Dim objGEXCELwkBk As Object
Dim objGEXCELwkShs As Object
Dim objGEXCELSh As Object
Dim FS, f, f1, fc, s
Dim coords(2) As Variant
Dim partDocument1
Sub CATMain()
CATIA.ActiveDocument.Selection.Search "CATGmoSearch.Point,all"
StartEXCEL
ExportPoint
End Sub
'******************************************************************************
Sub StartEXCEL()
'******************************************************************************
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"
End Sub
'******************************************************************************
Sub ExportPoint()
'******************************************************************************
For i = 1 To CATIA.ActiveDocument.Selection.Count
Set Selection = CATIA.ActiveDocument.Selection
Set Element = Selection.Item(i)
Set Point = Element.Value
'Write PointData to Excel Sheet
Point.GetCoordinates (coords)
objGEXCELSh.Cells(i + 1, "A") = Point.Name
objGEXCELSh.Cells(i + 1, "B") = coords(0)
objGEXCELSh.Cells(i + 1, "C") = coords(1)
objGEXCELSh.Cells(i + 1, "D") = coords(2)
Next
End Sub
------