×
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

AddComponentsFromFiles using VB.NET

AddComponentsFromFiles using VB.NET

AddComponentsFromFiles using VB.NET

(OP)
Been looking into using VB.NET and Visual Studio (2017) to control an (semi-)automation application in CATIA v5 (running R24).

Up until recently, things were going well, “transferring” code from VBA in Catia to Visual Studio; but now I ran into some issues with adding CATparts to a CATProduct (i.e., assembly).

Upon trying to use AddComponentsFromFiles I get stuck. One thing I notice is that the Variant type that is used in VBA has been deleted from VB.NET, and so the tooltip says it’s an Array type now.

In VBA, the standard procedure (i.e., macro recording) is to use:

----

Sub CATMain()

Dim productDocument1 As ProductDocument
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-cylinder.CATPart"
Set products1Variant = products1
products1Variant.AddComponentsFromFiles arrayOfVariantOfBSTR1, "All"

End Sub
-----


However, when I transfer – in every which way I can think of including putting the file name into an Array type – I get different types of errors, but no real indication of a way forwards.
Anyone tried anything similar / can point me in some direction?

Thanks.

RE: AddComponentsFromFiles using VB.NET

I do not see any problem, I transfer your solution to VB.NET almost without changes and it is working properly.

CODE --> VB.NET

Dim CATIA = GetObject(, "CATIA.Application")
Dim productDocument1
productDocument1 = CATIA.ActiveDocument

Dim product1
product1 = productDocument1.Product

Dim products1
products1 = product1.Products

Dim arrayOfVariantOfBSTR1(0)		
arrayOfVariantOfBSTR1(0) = "D:\Test\BAROMETERCOVER.CATPart"

Dim products1Variant
products1Variant = products1
products1Variant.AddComponentsFromFiles(arrayOfVariantOfBSTR1, "All") 

Tesak
http://scripts4all.eu/txtoncurve/ - Text along a curve for Catia V5

RE: AddComponentsFromFiles using VB.NET

(OP)
Yes, copying your example works perfectly!
(I probably messed up either definition of product1/productDocument1/products1 by explicitly defining their type..)
Thanks for the clarification!! :)

RE: AddComponentsFromFiles using VB.NET

In vb.net there is many things that will need the "()". In case of error suspect that you will need some "()".

Just in case, I have used the vs2017, and a few days ago, i downgraded to VS comunity 2013. And almost everything converts from vba to vb.net.

Tiago Figueiredo
Tooling Engineer

Youtube channel:
https://www.youtube.com/channel/UC1qdlBeJJEgMgpPLV...

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