2

I want to write a VBScript, which outputs the position of a CAD part (x,y,z). The Input should be the partnumber. This is what I tried.

Sub CATMain()

    dim pos(11)
    for n = 1 to CATIA.Documents.Count
        set Dokument = CATIA.Documents.Item(n)
        for i = 1 to Dokument.product.products.Count
            set InstDokument = Dokument.product.products.item(i)
            If InstDokument = "my_part" Then
                msgbox InstDokument.Name
                InstDokument.Position.GetComponents pos
                msgbox "Origin Point: X= " &pos(9) &" Y= " &pos(10) &" Z= " &pos(11)
            End If
        next
    next
End Sub

I got an error in line 8 column 2. The object does not have the property or method.: Dokument.product How can I solve that?

1 Answers1

2

There are several problems with your code.

At the root is probably this:

set Dokument = CATIA.Documents.Item(n)

The CATIA documents collection will contain many documents which do not have windows and which the CATIA application maintains for it's own various internal purposes. So it is not assured that CATIA.Documents.Item(n) actually contains a CATProduct.

In most cases one is interested in the current active document, and it is retrieved like this:

Set Dokument = CATIA.ActiveDocument

Otherwise you can test for it

Set Dokument = CATIA.Documents.Item(n)
if typename(Dokument) = "ProductDocument" Then ...

Even after that you have problems. You are comparing the Document object to a string... and other things. Also without recursion you may never find your target instance if it is deeper then at the first level. It may also be possible that search may be a better way to find your instance then "Reading the tree".

Once you have corrected all your infrastructure errors your method for getting the transformation matrix is basically correct.

C R Johnson
  • 964
  • 1
  • 5
  • 12