Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract properties from a .product

Status
Not open for further replies.

Lea75

Mechanical
Feb 24, 2009
51
Hello:
I'd like to know how it would be the script code for extract the properties of the parts inside the product to a .txt file.
I could obtain the code for extracting parameters of single parts, but I need to get all of them in the hole product.
Can anyone help me?
I put above my code.

Regards





+++++++++++++++++++++++++++

Sub CATMain()

Dim partDoc As PartDocument
Set partDoc = CATIA.ActiveDocument

Dim partProd As Product
Set partProd = partDoc.Product

Dim prodProps As Parameters
Set prodProps = partProd.UserRefProperties

Dim catParmP0 As Parameter
Set catParmP0 = prodProps.Item("P0")

Dim catParmP1 As Parameter
Set catParmP1 = prodProps.Item("P1")

Dim catParmP2 As Parameter
Set catParmP2 = prodProps.Item("P2")

Dim catParmP5 As Parameter
Set catParmP5 = prodProps.Item("P5")

Dim catParmP6 As Parameter
Set catParmP6 = prodProps.Item("P6")

Dim catParmP7 As Parameter
Set catParmP7 = prodProps.Item("P7")

Dim catParmP9 As Parameter
Set catParmP9 = prodProps.Item("P9")

Dim catParmP11 As Parameter
Set catParmP11 = prodProps.Item("P11")

Dim catParmP13 As Parameter
Set catParmP13 = prodProps.Item("P13")

Dim catParmP15 As Parameter
Set catParmP15 = prodProps.Item("P15")




' GUARDAR EN BLOC DE NOTAS


Dim filename As String

filename = CATIA.FileSelectionBox("Donde quiere guardar el fichero de resultado", "*.txt", CatFileSelectionModeSave)

Set Datos = CATIA.FileSystem.CreateFile(partProd.Name & ".fre" , True)

Set ostream = Datos.OpenAsTextStream("ForAppending")

ostream.Write ("P0=K") & catParmP0.Value & (" P1=K") & catParmP1.Value & (" P2=K") & catParmP2.Value & (" P5=K") & catParmP5.Value & (" P6=K") & catParmP6.Value & (" P7=K") & catParmP7.Value & (" P9=K") & catParmP9.Value& (" P11=K") & catParmP11.Value & (" P13=K") & catParmP13.Value & (" P15=K") & catParmP15.Value & (" (") & partProd.Name & (")") & Chr(10)


ostream.Close ' cierra el fichero de texto

MsgBox "PARAMETROS GENERADOS" & Chr(10) & "POR FAVOR, COMPRUEBE LOS RESULTADOS EN LA CARPETA SELECCIONADA " & chr(10)


End Sub
 
Replies continue below

Recommended for you

Hi,

You can try a custom BOM...it will give you all the properties of the parts inside a CATproduct as well.


Regards
Fernando
 
You can do it also by CATScript (I remember also your post on auxcad.com and I understood that you like to programm in CATIA).

Language="VBSCRIPT"

Sub CATMain()

Dim productDocument1 As Document
Set productDocument1 = CATIA.ActiveDocument

Dim product1 As Product
Set product1 = productDocument1.Product

Dim assemblyConvertor1 As CATBaseDispatch
Set assemblyConvertor1 = product1.GetItem("BillOfMaterial")

Dim arrayOfVariantOfBSTR1(7) 'change number if you have more custom columns/array...
arrayOfVariantOfBSTR1(0) = "Quantity"
arrayOfVariantOfBSTR1(1) = "Part Number"
arrayOfVariantOfBSTR1(2) = "Type"
arrayOfVariantOfBSTR1(3) = "Nomenclature"
arrayOfVariantOfBSTR1(4) = "Revision"
arrayOfVariantOfBSTR1(5) = "Mass" 'in addition of what is by default in BOM
arrayOfVariantOfBSTR1(6) = "Density" 'in addition of what is by default in BOM
arrayOfVariantOfBSTR1(7) = "Material" 'in addition of what is by default in BOM
assemblyConvertor1.SetCurrentFormat arrayOfVariantOfBSTR1

Dim arrayOfVariantOfBSTR2(1) 'change number if you have more custom columns/array...this part is for Recapitulation
arrayOfVariantOfBSTR2(0) = "Quantity"
arrayOfVariantOfBSTR2(1) = "Part Number"

assemblyConvertor1.SetSecondaryFormat arrayOfVariantOfBSTR2

assemblyConvertor1.Print "TXT", "c:\tempy\Custom_BOM.txt", product1 'change the path and name of the file according to your needs...

End Sub

Regards
Fernando
 
Hi Ferdo, yes, I am Leo75 from Auxcad. I asked for this issue there, but I can't solve my doubt yet.
Then, I ask for it here because it seems that this forum develops programing tasks more widely. Perhaps I will have better luck.
I know that I can obtain all the parameters of a product with the standar Catia's BOM and I know how to customize it and how to script it but in fact I need a tuned BOM.
For example, the script that I published yesterday gives me the following result (from a CatPart file):

P0=K40 P1=K53,94 P2=K66,5 P5=K12 P6=K5,47 P7=K51,47 P9=K30 P11=K0 P13=K2 P15=K12 (Part1)

- The values before "K" are the parameters stored in the properties of the part
- Part 1 is the instance name of the part

What I need is to extract this datas from the whole product, for example:

P0=K40 P1=K53,94 P2=K66,5 P5=K12 P6=K5,47 P7=K51,47 P9=K30 P11=K0 P13=K2 P15=K12 (Part1)
P0=K50 P1=K23,94 P2=K56,5 P5=K12 P6=K6,47 P7=K71,47 P9=K20 P11=K0 P13=K2 P15=K11 (Part2)
P0=K25 P1=K93,94 P2=K64,5 P5=K11 P6=K5,89 P7=K11,47 P9=K25 P11=K0 P13=K2 P15=K12 (Part3)
....and so on... keeping this structure or format.

Do you know how to do this? Can you help me with a Catscript?
Thank you in advance.
Regards
 
Hi Ferdo!
This is absolutely a good alternative but I have 2 problems:

1º) I tryed several times to modify the code, in order to extract my customized properties, but I couldn't get them.
I obtain errros and erros. Could you help me a bit more?

2º) It is not a problem at all, but I see that this method doesn't give me the "Quantity" information. Not now, but I think that in a near future I'll need to add this data too.
Any suggestion?

I see that we are near the solution. I hope you can help me with it.
Regards
 
Hi DBezaire, thank you for your reply, but I don't need a standar BOM.
Please, read my message of 25 Feb 09 14:36.
I need the datas in the following format:

P0=K40 P1=K53,94 P2=K66,5 P5=K12 P6=K5,47 P7=K51,47 P9=K30 P11=K0 P13=K2 P15=K12 (Part1)
P0=K50 P1=K23,94 P2=K56,5 P5=K12 P6=K6,47 P7=K71,47 P9=K20 P11=K0 P13=K2 P15=K11 (Part2)
P0=K25 P1=K93,94 P2=K64,5 P5=K11 P6=K5,89 P7=K11,47 P9=K25 P11=K0 P13=K2 P15=K12 (Part3)
....and so on... keeping this structure where:

- The values before "K" are the parameters stored in the properties of the part
- Part 1 is the instance name of the part

Regards
 
if you don't want a standard BOM then recursively walk the tree and get the data you require from the individual parts. I will however be up to you to handle multiple instances etc yourself. there are examples of this sort of code on the forum and the
 
Ok, thank you.
I'll look there, but if you have any example code which works, please, send it to me.
¿Is it possible to do this method with a simple Catscript?
I wouldn't like to use Visual Basic.
Regards
 
yes I have code, no you cannot have it, as I work for a CATIA var and write code as part of commercial arrangements.

This can be coded in VB, VBA, CATVBS etc. you may find it more difficult but not impossible in catscript & catvbs due to some of the restrictions of script.
 
Ok, no problem, I will continue looking for it.
Thank you for your links.
Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor