Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

CATIA V5 VBA Retrieve Material Path of Selected Product

Status
Not open for further replies.

hdwdlnd

Aerospace
Sep 1, 2009
16
0
0
US
I am trying to develop a routine to capture the materials of selected products within an active product at various node levels and then push these material assignments to the reference product nodes of every part at their parent level. I only have material assignments assigned at the part's leaf levels from the top level product so that when any sub-product is opened there are not material assignments. I want to push the top level assignments down so that the same linked materials show up when child products are opened. These materials can come from different family table/tabs within different material catalog files.

I can extract the material names of the products but is there also a way to extract the link of said materials? Is there a way to find where the linked material catalog is located? I could not find what I was looking for within the chm. Thanks.
 
Replies continue below

Recommended for you

Here is the testing section I'm using here where it assigns a linked material. I want to be able to find the material link back to source from a node selection. Thanks for the help!

Code:
Sub CATMain()

Dim MaterialDocPath As String

Dim MaterialName As String, MaterialFamilyName As String

Dim sel As Selection

Set sel = CATIA.ActiveDocument.Selection

Dim prod As Product

Set prod = sel.item(1).LeafProduct

Dim catprod As Product

Dim prod2 As Product

Set prod2 = prod.Parent

Dim prod3 As Product
Set prod3 = prod2.ReferenceProduct
Set objParameters = prod3.Parameters

Set oManager = prod.GetItem("CATMatManagerVBExt")

LinkMode = 1
Dim oAppliedMaterial As Material

oManager.GetMaterialOnProduct prod, oAppliedMaterial

testmat = oAppliedMaterial.Name

num = objParameters.count
For i = 1 To objParameters.count

    Set objParameter = objParameters.item(i)
    strParmName = objParameter.Name
    strParmValue = objParameter.ValueAsString
    
    If InStr(1, strParmName, "Material") Then
    
        MsgBox (strParmValue)
        
    End If
    
Next i

MaterialName = "Screws&Bolts" '*
MaterialFamilyName = "Standard Facility" '*

MaterialDocPath = "V:\V5Delmia\CATALOGS\MATERIALS\Facilities.CATMaterial" '*

Dim oMaterial_document As Document

Set oMaterial_document = CATIA.Documents.Read(MaterialDocPath)

Dim oMaterial As Material

Set oMaterial = oMaterial_document.Families.item(MaterialFamilyName).Materials.item(MaterialName)

Set oManager = prod.GetItem("CATMatManagerVBExt")

LinkMode = 1

oManager.ApplyMaterialOnProduct prod, oMaterial, LinkMode

End Sub
 
Status
Not open for further replies.
Back
Top