×
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

VB scripting - how to address a Product?

VB scripting - how to address a Product?

VB scripting - how to address a Product?

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

RE: VB scripting - how to address a Product?

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.

RE: VB scripting - how to address a Product?

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

RE: VB scripting - how to address a Product?

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.

RE: VB scripting - how to address a Product?

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

RE: VB scripting - how to address a Product?

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
    

RE: VB scripting - how to address a Product?

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

RE: VB scripting - how to address a Product?

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.  

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