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!

Problem with VBA programmation in CATIA V5 1

Status
Not open for further replies.

phuonghieu83

Automotive
Mar 27, 2007
18
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 :


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.
 
Replies continue below

Recommended for you

Dim objProducts As Object
Do a search of any CATIA forum to get the full answer or read the automation documentation
 
Thank you PeterGuy.

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
 
Did you try first to record a macro?

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
 
Sorry, I just notice its vba....

Regards
Fernando
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor