VB program to export name, value, parent and current product to excel
VB program to export name, value, parent and current product to excel
(OP)
Hi everyone
I am going to make a macro which can export the name, value, parent and current product to excel.
This is my code. It will take one hour then no responding when I run it.
I am really new to CATIA VBA and just start to learn it.
Any body can go through my code and tell me anything I missed.
Many thanks
L
Dim objGEXCELapp As Object
Dim objGEXCELwkBks As Object
Dim objGEXCELwkBk As Object
Dim objGEXCELwkShs As Object
Dim objGEXCELSh As Object
Dim PartDocument1
Sub CATMain()
Dim productDocument1 As ProductDocument
Set productDocument1 = CATIA.ActiveDocument
Dim selection1 As Selection
Set selection1 = productDocument1.Selection
selection1.Search "Name = Radius,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") = "Parent"
objGEXCELSh.Cells(1, "B") = "Size"
objGEXCELSh.Cells(1, "C") = "SubAssemly"
End Sub
'******************************************************************************
Sub ExportPoint()
'******************************************************************************
Dim productDocument1 As ProductDocument
Set productDocument1 = CATIA.ActiveDocument
Dim selection1 As Selection
Set selection1 = productDocument1.Selection
selection1.Search "Name = Radius,all"
For i = 1 To selection1.Count
objGEXCELSh.Cells(i + 1, "A") = selection1.Item(i).Value.Parent.Name 'the parent name
objGEXCELSh.Cells(i + 1, "B") = selection1.Item(i).Value.PartNumber 'the value of this parameter including unit
objGEXCELSh.Cells(i + 1, "C") = selection1.SubAssemly 'which CATProudcut is it below
Next
End Sub
I am going to make a macro which can export the name, value, parent and current product to excel.
This is my code. It will take one hour then no responding when I run it.
I am really new to CATIA VBA and just start to learn it.
Any body can go through my code and tell me anything I missed.
Many thanks
L
Dim objGEXCELapp As Object
Dim objGEXCELwkBks As Object
Dim objGEXCELwkBk As Object
Dim objGEXCELwkShs As Object
Dim objGEXCELSh As Object
Dim PartDocument1
Sub CATMain()
Dim productDocument1 As ProductDocument
Set productDocument1 = CATIA.ActiveDocument
Dim selection1 As Selection
Set selection1 = productDocument1.Selection
selection1.Search "Name = Radius,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") = "Parent"
objGEXCELSh.Cells(1, "B") = "Size"
objGEXCELSh.Cells(1, "C") = "SubAssemly"
End Sub
'******************************************************************************
Sub ExportPoint()
'******************************************************************************
Dim productDocument1 As ProductDocument
Set productDocument1 = CATIA.ActiveDocument
Dim selection1 As Selection
Set selection1 = productDocument1.Selection
selection1.Search "Name = Radius,all"
For i = 1 To selection1.Count
objGEXCELSh.Cells(i + 1, "A") = selection1.Item(i).Value.Parent.Name 'the parent name
objGEXCELSh.Cells(i + 1, "B") = selection1.Item(i).Value.PartNumber 'the value of this parameter including unit
objGEXCELSh.Cells(i + 1, "C") = selection1.SubAssemly 'which CATProudcut is it below
Next
End Sub





RE: VB program to export name, value, parent and current product to excel
CODE --> VBA
indocti discant et ament meminisse periti
RE: VB program to export name, value, parent and current product to excel
It still doesn't work. In the left bottom of window it counts the selection, and it will be no responding after something like 100.
I read my code a lot of times. Everything is ok but section of Sub ExportPoint()' looks like the reason why it doesn't work.
'******************************************************************************
Sub ExportPoint()
'******************************************************************************
Dim productDocument1 As ProductDocument
Set productDocument1 = CATIA.ActiveDocument
Dim selection1 As Selection
Set selection1 = productDocument1.Selection
selection1.Search "Name = Radius,all"
For i = 1 To selection1.Count
objGEXCELSh.Cells(i + 1, "A") = selection1.Item(i).Value.Parent.Name 'the parent name
objGEXCELSh.Cells(i + 1, "B") = selection1.Item(i).Value.PartNumber 'the value of this parameter including unit
objGEXCELSh.Cells(i + 1, "C") = selection1.SubAssemly 'which CATProudcut is it below
Any idea of these code?
Many many many thanks
L
RE: VB program to export name, value, parent and current product to excel
indocti discant et ament meminisse periti
RE: VB program to export name, value, parent and current product to excel
Use selection1.Item(i).LeafProduct.PartNumber ....instead of selection1.Item(i).Value.PartNumber for example and see what is going on.
Where did you find SubAssembly ? There is no topic in v5automation.chm file regarding this (or at least I wasn't able to find it).
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...
RE: VB program to export name, value, parent and current product to excel
I am new to VBA, and what I can do now is get some similar code,go through it, find something I can use and learn in this process.
one more question.
I've made one and I can run it. sometimes CATIA will be no responding because a 'search' section in code. How can I make a variable to take the place of 'search'? My aims are all parameter named by 'radius'.
Many thanks
L
RE: VB program to export name, value, parent and current product to excel
When you are running the Search, maybe you don't use the right syntax or you are not in the right workbench or can be some other issues, is difficult to say where is the mistake without having a small sample.
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...