×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Problem with VBA programmation in CATIA V5

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 :

http://files.engineering.com/getfile.aspx?folder=961ead90-fa48-4a50-98f0-233ad445b0da&file=References_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.
 

RE: Problem with VBA programmation in CATIA V5

Dim objProducts As Object
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

(OP)
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

RE: Problem with VBA programmation in CATIA V5

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

RE: Problem with VBA programmation in CATIA V5

Sorry, I just notice its vba....

Regards
Fernando

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources