Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

AddComponentsFromFiles using VB.NET 1

Status
Not open for further replies.

crillejohan

Mechanical
Jul 4, 2017
2
SE
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.
 
Replies continue below

Recommended for you

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

Code:
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
- Text along a curve for Catia V5
 
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!! :)
 
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:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top