1

I am trying to export points coordinates in Excel with code I found online.
It works until it gets to points in the shape of intersection in my Catia file.
These intersection points are well selected but I can't get their coordinates.

The error message is:

Source:Microsoft VBScript runtime error
Description: Object doesn't support this property or method:'point.GetCoordinates'
Line: 56

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 Integer
Dim PartDocument1

Sub CATMain()

CATIA.ActiveDocument.Selection.Search "CATGmoSearch.Point,all"

StartEXCEL

ExportPoint

'objGEXCELSh.Application.ActiveWorkbook.SaveAs (ExcelFolder & Left(CATIA.ActiveDocument.Name,Len(CATIA.ActiveDocument.Name)-8) & ".xls")
'objGEXCELSh.Application.ActiveWorkbook.Close

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

I tried changing the name of the intersection points but that had no effect.

3
  • I don't see where you defined what point is? (You just Set it without Dim) I don't think the computer knows either. Use Option Explicit to catch things like this. Commented Jun 10, 2024 at 7:55
  • 2
    I guess GetCoordinates is only valid for HybridShapePoint not for intersects. So you may have to use a measurement. Commented Jun 10, 2024 at 10:08
  • An easy work around would be just isolate the points, GetCoordinates will work on HybridShapePointExplicit. Commented Sep 13, 2024 at 21:08

2 Answers 2

0

One way to solve this problem would be to convert your points to explicit points.

Something like this, I don't have access to CATIA on weekends so I couldn't check the code :

Option Explicit

Sub ExportPoint(selectionInput As Selection, objGEXCELSh As Object)

    Dim oDoc As Document                                        'Document Anchor
    Dim oPart As Part                                           'Part Abchor
    Dim Index As Integer                                        'Index for loops
    Dim Point As HybridShape                                    'Point Object
    Dim coords(2) As Variant                                    'Array of coords
    Dim selCount As Integer                                     'Number of selections
    Dim geoSet As HybridBody
    
    Set oDoc = CATIA.ActiveDocument                             'Anchor document
    Set oPart = oDoc.Part                                       'Anchor Part
    
    selCount = selectioInput.Count2                             'Number of selections
    
    'Copy Points to new geonetric set to cover them to exlicit points
    SelectionInput.Copy                                         'Copy Selection
    SelectionInput.Clear                                        'Clear Selection
    geoSet = oPart.HybridBodies.Add()                           'Add new goemetric set
    SelectionInput.Search "(NAME =" & geoSet.Name & "),all"     'select new geometric set
    SelectionInput.PasteSpecial ("CATPrtResultWithOutLink")     'Paste all of the selection
    
    For Index = 1 To selCount                                   'Loop though all selection
        Set Point = geoSet.HybridShapes.Item(Index)             'Get the point

        Point.GetCoordinates (coords)                           'Get coords

        objGEXCELSh.Cells(Index + 1, "A") = Point.Name              'Export name
        objGEXCELSh.Cells(Index + 1, "B") = coords(0)               'Export X
        objGEXCELSh.Cells(Index + 1, "C") = coords(1)               'Export Y
        objGEXCELSh.Cells(Index + 1, "D") = coords(2)               'Export Z

    Next

    SelectionInput.Delete                                       'Delete geometric set we created

End Sub

GetCoordinates will fail on some of the point types you will come across. It will work on isolated/explicit points. You could create datums of the points, isolate them before you run the macro, copy paste them or use measurable.

Sign up to request clarification or add additional context in comments.

Comments

0

You can measure the coordinates of your Point

Create a reference on your point

Dim refItem As Reference = Part.CreateReferenceFromObject(selectionInput .Value)

Then measure its position

Dim myCoord(2)
Dim oSpaworkbench As SPAWorkbench
oSpaworkbench = oPart .GetWorkbench("SPAWorkbench")
Dim oMeas = oSpaworkbench.GetMeasurable(refItem )
oMeas.GetPoint(myCoord)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.