Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

VB scripting - how to address a Product?

Status
Not open for further replies.

bsurfN99

Automotive
Jan 27, 2004
30
0
0
US
I am trying to get a script to run within the context of an assembly, I can't seem to get the "Product related" lines correct. Any Ideas?

My Script does work when only running in a Catpart...


*********** I'm adding this part (doesn't work)
'find product information
Dim product1 As product
Set product1 = CATIA.Activeproduct
Set product1 = partdocument

*********** For here down works (in a .CatPart)

'set current catia document as current
Dim partDocument1 As partDocument
Set partDocument1 = CATIA.ActiveDocument

Dim ActivePart As Part
Set ActivePart = partDocument.Part

Dim parameters1 As parameters
Set parameters1 = ActivePart.parameters

......etc.....


Any Ideas?


Thanks,
- BsurfN99
 
Replies continue below

Recommended for you

You could try something like the following:

' Initialise Part Settings
Dim CurrentDoc As Document
Set CurrentDoc = CATIA.ActiveDocument
Dim CurrentProd As Product
Set CurrentProd = CurrentDoc.Product

It works ok on the macro I'm working on, which follows a similar strategy to the one you describe

If Beethoven had been killed in a plane crash at the age of 22, it would have changed the history of music...
and of aviation.
 
Thanks, I haven't been able to really see if it works in the context of my assembly though, because I can't seem to get my parameters to connect. I get an "Run-time error '438': Object doesn't support this property or method" This error occurs at the *** line.

'find product and part information
Dim CurrentDoc As document
Set CurrentDoc = CATIA.ActiveDocument

Dim CurrentProd As product
Set CurrentProd = CurrentDoc.product

Dim parameters1 As parameters
Set parameters1 = CurrentDoc.parameters ***


I'm sure I'm missing something basic here, any ideas?


BsurfN99
 
I think it should work if you try CurrentProd.parameters instead of CurrentDoc.parameters

If Beethoven had been killed in a plane crash at the age of 22, it would have changed the history of music...
and of aviation.
 
Modifing it to CurrentDoc.parameters, does make it work, except it add the parameters to the product, and not my active part, I would like to be able to add my parameters to my active "catpart" even when in designing within a product.

Thanks for your help...


-BsurfN99
 
If You want to collect the parameters of the active CATPart in designing product. What you should do is

Dim productDocument1 As ProductDocument
Set productDocument1 = CATIA.ActiveDocument

Dim Rootprod As Product
Set Rootprod = productDocument1.Product

Dim MyProd As product
Set MyProd = Rootprod.products.Item("iproduct.name")

Dim Parameters1 As Parameters
Set Parameters1 = MyProd.Parameters

i = 0
do
i = i + 1
Msgbox Parameters1.item(i).Name
loop until i = Prameters1.Count

Hope this would work for you
 
Thanks for the Ideas, unfortunately that's not what I was tring to do. It did give me an idea though, I just tried it, it didn't work....

Here is what I am tring do accomplish.

Within any CatPart, wheather I have open just a CatPart or if I am active in a Catpart, within a product; I have set parameters that I may want to apply to my CatPart.

At the moment, I have this working only for working only in a Catpart, It errors out if I try to run it when working in a Catpart that is also in a CatProduct. I would like to fix this. I am fairly new to VBA, any help is much appreciated.

Thanks for everyones help...

-BsurfN99
"The secret to success is the consistency to pursue."
- Harry F. Banks
 
The challenge here is that VB calls both CATParts and CATProduct Products. You need to determine wether or not the part you are working with is actually a CATPart or not. One way of finding this out is to look at the ActPart.Products.Count. If it is greater than 0, then you are definitely looking at a CATProduct, but if it is 0, you either have a CATPart, or you have a CATProduct with no children. From there, you can look at the associated Document, to see if it's a CATPart or not. You could also check to see if the Active Part has a HybridBodies collection, or a Bodies collection.
 
Status
Not open for further replies.
Back
Top