Materials

Applying or Retrieving a Material on a Product, a Part, or a Body


This macro shows you how to apply and retrieve an existing material onto a Product, a Part or a Body.

 

applyMaterial is launched in CATIA. Existing documents called "MyCatalog.CATMaterial", "Product1.CATProduct" and "Part1.CATPart" must be found in the CATDocView.

applyMaterials.CATScript is located in the CAAScdMatUseCases module. Execute macro (Windows only).

 

applyMaterials includes three steps:

  1. Open the CATMaterial document and retrieve materials
  2. Open a CATProduct document and apply/retrieve a material
  3. Open a CATPart document and apply/retrieve a material on the Part and the PartBody

Open the material library and retrieve 3 existing materials

    '
    ' ----------------------------------------------------------- 
    ' Open the material library (.CATMaterial file)
    ' ----------------------------------------------------------- 
    '
    Dim sFilePath
    sFilePath = CATIA.FileSystem.ConcatenatePaths(sDocPath, _
                 "\online\CAAScdMatUseCases\samples\MyCatalog.CATMaterial")

    Dim oMaterial_document As Document
    Set oMaterial_document = CATIA.Documents.Open(sFilePath)
    Set oMaterial_document = CATIA.ActiveDocument
    '
    ' ----------------------------------------------------------- 
    ' Read materials in this catalog (which contains 3 families and 5 materials in each family)
    ' First retrieve the families of the library
    ' ----------------------------------------------------------- 
    '
    Dim cFamilies_list As MaterialFamilies
    Set cFamilies_list = oMaterial_document.Families

    Dim iNb_families As Integer
    iNb_families = cFamilies_list.Count
    Dim sFamiliesName As String
    sFamiliesName = cFamilies_list.Name
    '
    ' ----------------------------------------------------------- 
    ' Retrieve the first family of the library
    ' ----------------------------------------------------------- 
    '
    Dim oFirst_family As MaterialFamily
    Dim ifamily_no As Integer
    ifamily_no = 1
    Set oFirst_family = cFamilies_list.Item(iFamily_no)
    Dim sFamilyName As String
    sFamilyName = oFirst_family.Name
    '
    ' -----------------------------------------------------------
    ' Retrieve the material number 1,2 and 3 of the family
    ' -----------------------------------------------------------
    '
    Dim cMaterials_list As Materials
    Set cMaterials_list = oFirst_family.Materials

    Dim iNb_materials As Integer
    iNb_materials = cMaterials_list.Count

    Dim imaterial_no As Integer
    imaterial_no = 1
    Dim oMaterial1 As Material
    Set oMaterial1 = cMaterials_list.Item(imaterial_no)
  
    imaterial_no = 2
    Dim oMaterial2 As Material
    Set oMaterial2 = cMaterials_list.Item(imaterial_no)
  
    imaterial_no = 3
    Dim oMaterial3 As Material
    Set oMaterial3 = cMaterials_list.Item(imaterial_no)	
	...

[Top]

Open a CATProduct document. Apply a material on the root product and retrieve it

	...
    '
    ' -----------------------------------------------------------
    ' Read product file
    ' -----------------------------------------------------------
    '
    Dim oProductDocument As Document
    sFilePath = CATIA.FileSystem.ConcatenatePaths(sDocPath, _
                 "\online\CAAScdMatUseCases\samples\Product1.CATProduct")
    Set oProductDocument = CATIA.Documents.Open(sFilePath)
    Set oProductDocument = CATIA.ActiveDocument
    '
    ' -----------------------------------------------------------
    ' Access on material manager on root product document
    ' -----------------------------------------------------------
    '
    Dim oRootProduct As Product
    Set oRootProduct = oProductDocument.Product
      
    Dim oManager As MaterialManager
    Set oManager = oRootProduct.GetItem("CATMatManagerVBExt")
    '
    ' -----------------------------------------------------------
    ' Apply the material on the Product (as a link)
    ' -----------------------------------------------------------
    '
    Dim linkMode As Integer
    linkMode = 1
    oManager.ApplyMaterialOnProduct oRootProduct,oMaterial1,linkMode 
    '
    ' -----------------------------------------------------------
    ' Retrieve the material applied on the Product 
    ' -----------------------------------------------------------
    '
    Dim oAppliedMaterial As Material
    oManager.GetMaterialOnProduct oRootProduct,oAppliedMaterial 
    oProductDocument.Close	
	... 

[Top]

Open a CATPart document. Apply a material on the part and its partbody and retrieve them

	...
            
    '
    ' -----------------------------------------------------------
    ' Open the Part document
    ' -----------------------------------------------------------
    '
    sFilePath = CATIA.FileSystem.ConcatenatePaths(sDocPath, _
                 "\online\CAAScdMatUseCases\samples\Part1.CATPart")
    
    Dim oPartDocument As Document
    Set oPartDocument = CATIA.Documents.Open(sFilePath)
    Set oPartDocument = CATIA.ActiveDocument
    '
    ' -----------------------------------------------------------
    ' Access on material manager on root part document
    ' -----------------------------------------------------------
    '
    Dim oRootPart As Part
    Set oRootPart = oPartDocument.Part
    
    ' Retrieve the extension object associated to Y under the key "MyCATIVBExtensionImpl"
    Set oManager = oRootPart.GetItem("CATMatManagerVBExt")
    '
    ' -----------------------------------------------------------
    ' Apply the material on the Part
    ' -----------------------------------------------------------
    '
    linkMode = 0
    oManager.ApplyMaterialOnPart oRootPart,oMaterial2,linkMode 
    '
    ' -----------------------------------------------------------
    ' Retrieve the material on the Part 
    ' -----------------------------------------------------------
    '
    oManager.GetMaterialOnPart oRootPart,oAppliedMaterial 
    '
    ' -----------------------------------------------------------
    '  Retrieve the Part Body
    ' -----------------------------------------------------------
    '
    Dim oMainBody As Body
    Set oMainBody = oRootPart.MainBody
    '
    ' -----------------------------------------------------------
    ' Apply the material on the Part Body (as a link)
    ' -----------------------------------------------------------
    '
    linkMode = 1
    oManager.ApplyMaterialOnBody oMainBody,oMaterial3,linkMode 
    '
    ' -----------------------------------------------------------
    ' Retrieve the material on the Part Body
    ' -----------------------------------------------------------
    '
    oManager.GetMaterialOnBody oMainBody,oAppliedMaterial 
	...

[Top]


In Short

This use case presents a macro which can be useful to:

  1. Apply materials from a material library onto products, parts or bodies.
  2. Retrieve materials already applied onto products, parts or bodies.

[Top]


Copyright © 1994-2003, Dassault Systèmes. All rights reserved.