Bit of a newb to VB in Catia and still working to get my head around the object structure.
I urgently need to put something together like the one in the thread560-308328 from ntweisen to loop through the bodies in a part and pull out parameters.
The code below is a combination of parts of the above but it misses the loops and steps straight to writing the file and fails there as the datum isn't set.
Sub CATTextOuput()
Dim partDoc As PartDocument
Set partDoc = CATIA.ActiveDocument
Dim partProd As Product
Set partProd = partDoc.Product
Dim filename As String
filename = partDoc.Name
Version = partProd.Revision
Description = partProd.DescriptionRef
'Dim partcount As Integer
Dim Namebody As String
Dim bodynumber As Integer
Dim Part1 As Part
Set Part1 = partDoc.Part
Dim i As Integer
For i = 1 To partcount
Dim j As Integer
bodynumber = Part1.Bodies.Count
For j = 1 To bodynumber
Dim Body1 As Body
Set Body1 = Part1.Bodies.Item(j)
Namebody = Body1.HybridBodies(1)
Next 'j
Next 'i
Dim path As String
path = CATIA.ActiveDocument.path
Set Datos = CATIA.FileSystem.CreateFile(path & "\" & CATIA.ActiveDocument.Name & ".txt", True)
Set ostream = Datos.OpenAsTextStream("ForAppending")
'ostream.Write CATIA.ActiveDocument.Name & Chr(10)
ostream.Write "Name: " & filename & Chr(10)
ostream.Write "Version: " & Version & Chr(10)
ostream.Write "Description: " & Description & Chr(10)
ostream.Write "Namebody: " & Namebody & Chr(10)
ostream.Close
MsgBox "Check results in folder " & Chr(10) & path & "\" & Chr(10) & Chr(10) & "File:" & Chr(10) & partDoc.Name & ".txt" & Chr(10)
End Sub
Thanks in advance
I urgently need to put something together like the one in the thread560-308328 from ntweisen to loop through the bodies in a part and pull out parameters.
The code below is a combination of parts of the above but it misses the loops and steps straight to writing the file and fails there as the datum isn't set.
Sub CATTextOuput()
Dim partDoc As PartDocument
Set partDoc = CATIA.ActiveDocument
Dim partProd As Product
Set partProd = partDoc.Product
Dim filename As String
filename = partDoc.Name
Version = partProd.Revision
Description = partProd.DescriptionRef
'Dim partcount As Integer
Dim Namebody As String
Dim bodynumber As Integer
Dim Part1 As Part
Set Part1 = partDoc.Part
Dim i As Integer
For i = 1 To partcount
Dim j As Integer
bodynumber = Part1.Bodies.Count
For j = 1 To bodynumber
Dim Body1 As Body
Set Body1 = Part1.Bodies.Item(j)
Namebody = Body1.HybridBodies(1)
Next 'j
Next 'i
Dim path As String
path = CATIA.ActiveDocument.path
Set Datos = CATIA.FileSystem.CreateFile(path & "\" & CATIA.ActiveDocument.Name & ".txt", True)
Set ostream = Datos.OpenAsTextStream("ForAppending")
'ostream.Write CATIA.ActiveDocument.Name & Chr(10)
ostream.Write "Name: " & filename & Chr(10)
ostream.Write "Version: " & Version & Chr(10)
ostream.Write "Description: " & Description & Chr(10)
ostream.Write "Namebody: " & Namebody & Chr(10)
ostream.Close
MsgBox "Check results in folder " & Chr(10) & path & "\" & Chr(10) & Chr(10) & "File:" & Chr(10) & partDoc.Name & ".txt" & Chr(10)
End Sub
Thanks in advance