Welcome to the COE Discussion Forum! 

 

To participate in the discussion forum, you must be logged in to the website.  If you forget your login information, please contact COE Headquarters at coe@coe.org or (800) 263-2255.

If you are new to the COE Discussion Forum and would like to participate, please register.

 

The COE 2008 Fall Industry Workshops

Experience two days of industry-focused education and hands-on training on the Dassault PLM solutions suite of products.  All education featured at the workshop is developed by and for users of CATIA®, ENOVIA®, DELMIA® and SIMULIA®.
 

Automotive
Oct. 15-16
Troy, Michigan

Aerospace & Defense
Oct. 27-28
Wichita, Kansas


Forum Highlight: CATIA V6

 

Get Answers to Your V6 Questions
Dassault Systèmes answers user questions about CATIA V6.  Discuss these answers and propose new questions with end users from around the world in the CATIA V6 Forum.

COE DISCUSSION FORUM
Subject: Replace Components in a Product using VB

You are not authorized to post a reply.   
Author Messages
DAVE2784


19 Jul 2005 10:25 AM
I was wondering if anyone knows how to replace components in a product using VB?

I have a product that has different options for a certain part (part A, part B, part C). I want to be able to swap out part A with part B or C and have its constraints automatically be recognised (using published references & a naming convention) via a VB GUI.

If this is possible using Knowledge Advisor or something else then that would work too...

Also if anyone out there knows if this is impossible then please let me know so I can stop trying to make it work.

Thanks!!!
CARBAHOLIC

19 Jul 2005 02:52 PM
I can't see any reason why it wouldn't work but I've never done it before. If you want help working the problem out, just tell use where you get stuck, and give us an idea of how you're going about it and we'll give you a hand.

Eric
BPRASAD


20 Jul 2005 10:22 AM
The way I have done in Knowledgeware is to create a Part Template with 3 PartBodies.

A PartBody defines a specific Part features. Thus, PartBody_A defines PartA. PartBody_B defines PartB and PartBody_C defines PartC. All 3 bodies reside within a single CATPart (referred herein as Part Template).

Now I define a Controlling Parameter (String) with 3 multiple entries -- say Active_Part = {PartA, PartB, PartC}
I have written a KWA Rule that activates one PartBody and deactivates the rest based on the chosen value for the "Active_Part." Thus at one time only one PartBody will be active giving you the desired results.
Quite straightforward, I think.

Once you are done creating this, you can insert this "Part Tempate" to any CATProduct you want and rest should work "as designed."

Brian Prasad
COE-DPC/KBE Chairperson
COE-FORUM-USER

21 Jul 2005 03:07 AM
I can't remember the exact code, but try looking for ReplaceComponent and ReplaceProduct in the docs. I know that I've used them in the past.

I think that you need to use both, but I can't remember.
hdub

27 Jul 2005 09:03 PM
D,

Create a multi value parameter (loop in my example...) of type string in your skeleton which should exist under your top level product that contains the part or product you want to swap.

Create a rule(called LoopSwap in my example...) within the top level product that calls a script with an arg. that represents the file name of the part you want to replace with.

if `SKEL\Loop` == "Loop 1"
`Relations\VB Scripts.1\LoopSwap` .Run("\Loop 1.CATProduct")

if `SKEL\Loop` == "Loop 2"
`Relations\VB Scripts.1\LoopSwap` .Run("\Loop 2.CATProduct")

if `SKEL\Loop` == "Loop 2 - STEP"
`Relations\VB Scripts.1\LoopSwap` .Run("\Loop 2 STEP.CATProduct")

if `SKEL\Loop` == "Loop 3"
`Relations\VB Scripts.1\LoopSwap` .Run("\Loop 3.CATProduct")

Create a VB Script under the KWA Workbench that looks like this....

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 product2 As Product
Set product2 = products1.Item("GenericLoop.1")

Set product2 = products1.ReplaceComponent(product2,"C:\Directory\The\File\Exists\In" & file, True)
product1.Update

End Sub

This should work. You will notice That I replaced an entire product. The methodology works the same for parts but the coding is a bit different.

Go ahead and constrain your generic part using pubs. Make sure the pubs in the other files have the same names as the generic, that way when you replace, the links are tight.

Good Luck. Go Tigers.
DAVE2784


18 Aug 2005 09:29 AM
Thanks hdub! You da man!

Basically, I was looking for the:
"Set product2 = products1.ReplaceComponent(product2,"C:\Directory\The\File\Exists\In" & file, True)"
line and it worked out well for me.

Now if I could only make that work in VPM (V4)...

And of course, Go Tigers!
You are not authorized to post a reply.
Forums > COE Forums > KBE > Replace Components in a Product using VB



ActiveForums 3.6

    

401 North Michigan Avenue, Chicago, IL 60611-4267 | (312) 321-5153 | (800) COE-CALL (U.S.)