Problem with VBA programmation in CATIA V5
Problem with VBA programmation in CATIA V5
(OP)
Hello,
I'm writing a litte VBA macro in CATIA V5. I had an error message by adding a file into a product in using the function : AddComponentsFromFiles. The error message is "Function or interface marked as restricted, or the function uses an Automation type not supported in Visual Basic ".
CATIA Version : V5R18
VB 6.0
References of VBA project :
htt p://files. engineerin g.com/getf ile.aspx?f older=961e ad90-fa48- 4a50-98f0- 233ad445b0 da&fil e=Referenc es_VBA.JPG
Here is the code :
Sub CATMain()
If (False = Inits()) Then
Exit Sub
End If
Dim objProducts As Products
Dim objProduct As Product
Dim iProduct As Product
Dim iProducts As Products
Dim arrayOfVariantOfBSTR1(0)
arrayOfVariantOfBSTR1(0) = "X:\3113261-CGR-200900825-11521.cgr"
Set objProduct = objCATIAV5CurrentDoc.Product
Set objProducts = objProduct.Products
objProducts.AddComponentsFromFiles arrayOfVariantOfBSTR1, "All"
End Sub
Can anyone help me in this sujet?
Thank you in advanced.
I'm writing a litte VBA macro in CATIA V5. I had an error message by adding a file into a product in using the function : AddComponentsFromFiles. The error message is "Function or interface marked as restricted, or the function uses an Automation type not supported in Visual Basic ".
CATIA Version : V5R18
VB 6.0
References of VBA project :
htt
Here is the code :
Sub CATMain()
If (False = Inits()) Then
Exit Sub
End If
Dim objProducts As Products
Dim objProduct As Product
Dim iProduct As Product
Dim iProducts As Products
Dim arrayOfVariantOfBSTR1(0)
arrayOfVariantOfBSTR1(0) = "X:\3113261-CGR-200900825-11521.cgr"
Set objProduct = objCATIAV5CurrentDoc.Product
Set objProducts = objProduct.Products
objProducts.AddComponentsFromFiles arrayOfVariantOfBSTR1, "All"
End Sub
Can anyone help me in this sujet?
Thank you in advanced.





RE: Problem with VBA programmation in CATIA V5
Do a search of any CATIA forum to get the full answer or read the automation documentation
RE: Problem with VBA programmation in CATIA V5
I've not tried your method yet but what I do is just not declare the type of data for this CATIA Products Document as :
"Dim iProducts"
I think it've returned like to declare objProducts As Object.
But anyone can tell my the reason why this error happended when I've tried to declare correctly the object As Products. It's a bug in VB6 or something like that??
I'm really sorry for my very bad English.
Have a good day to all.
Hieu TRAN
RE: Problem with VBA programmation in CATIA V5
I used something similar to create a "light" DMU without DMU license and it worked for me but with a little more work.
Language="VBSCRIPT"
Sub CATMain()
Dim productDocument1 As Document
Set productDocument1 = CATIA.ActiveDocument
Dim product1 As Product
Set product1 = productDocument1.Product
Dim products1 As Products
Set products1 = product1.Products
Dim arrayOfVariantOfBSTR1(0)
arrayOfVariantOfBSTR1(0) = "C:\Temp\Test.cgr"
products1.AddComponentsFromFiles arrayOfVariantOfBSTR1, "All"
End Sub
Regards
Fernando
RE: Problem with VBA programmation in CATIA V5
Regards
Fernando
RE: Problem with VBA programmation in CATIA V5
My posts here detail why you get this warning