EKL - Attach PLM Material to Piping Parts

Introduction

Purpose : synchronize Material Name attribute and PLM material associated to the piping part : associate a PLM material equal to the Material Name Attribute of the piping part reference

With this rule you can have a unique generic part and component family that covers multiple materials, system will associate automatically the good PLM material according the value of the attribute "MaterialName" 

Prereq :

  1. the Material Title must be unique in database
  2. a material table must be attached to the Piping specification Resource Set in Datasetup App 

Code Example

/* Signature: Name : ipPartBody ; Type: BodyFeature */

// Declaration Variable
let pRepRef (VPMRepReference)
let pPrdRef (VPMReference)
let BodyName(String)
let returnCode(Boolean)
let Path(String)
let pOldMaterial(CATMatReference)
let AppliedMaterial(CATMatConnection)
let pMaterialTable(Ens_MaterialTable)
let pListCell(List)
let pCell(EnsTechnologicalTableCell)
let Nb (Integer)
let j(Integer)
let StrMaterialName(String)
let StrMaterialNameOld(String)
let StrMaterialNameTable(String)
let pPipingEntity(Piping_Entity)
let PipingMaterial(String)
let pNewMaterial(CATMatReference)
let bMaterialFound(Boolean)

// Initialization
set bMaterialFound = false

// Retrieve name of Body
set BodyName = ipPartBody.Name

if ("PartBody" == BodyName)
{
  Trace (1, "================ 3D Fluidic Material Rule =================== ")

  // Retrieve the VPMRepReference from Feature
  set pRepRef = GetPLMOwner(ipPartBody)

  // Retrieve VPMReference from VPMRepReference
  if (NULL <> pRepRef)
  {
    set pPrdRef = pRepRef.AggregatingReference
  }

  // Retrieve the Piping Entity
  if (NULL <> pPrdRef)
  {
    set pPipingEntity = pPrdRef
  }

  // if it is Piping entity, we can do the work.
  if (NULL <> pPipingEntity)
  {
    Trace(1, pPipingEntity.Name)

    // Read the Material Name on Piping entity
    StrMaterialName = pPipingEntity.V_MaterialName
    Trace(1, "Material Name Value : " + StrMaterialName)

    // Read Material core apply on Piping entity
    returnCode = GetMaterialCore(pPipingEntity, Path, pOldMaterial, AppliedMaterial)

    if (NULL <> pOldMaterial)
    {
      StrMaterialNameOld = pOldMaterial.V_Name
      Trace(1, "Material Name of CATMaterial : " + StrMaterialNameOld)
    }

    if (StrMaterialName == StrMaterialNameOld)
    {
      Trace(1, "Material Already Apply, nothing to do")
    }
    else
    {
      Trace(1, "We must apply the Material")

      // Remove the existing material as it is not the good one.
      if (NULL <> pOldMaterial)
      {
        returnCode = RemoveMaterial(AppliedMaterial)
      }

      // Retrieve the Material table from data setup.
      pMaterialTable = AccessResource("PipingSpecificationResource|Material","Ens_MaterialTable")

      if (NULL <> pMaterialTable)
      {
        pMaterialTable.GetColumn(1,pListCell)
        Nb = pListCell.Size()

        // Loop on table to retrieve the same matrial as define on Piping Entity
        j = 1
        for j while j <= Nb
        {
          pCell = pListCell.GetItem(j)
          if (NULL <>pCell)
          {
            StrMaterialNameTable = pCell.GetAttributeString("ValueAsString")
            if (StrMaterialName == StrMaterialNameTable)
            {
              // IF we retrieve the Material Name in ESE Table, we apply it on Piping Entity
              Trace(1, StrMaterialNameTable + " - " + ToString(j))
              pNewMaterial = pCell.GetAttributeObject("PLMEntityValueSource")
              if (NULL <> pNewMaterial)
              {
                  Trace(1, "Pointer on Material is OK")
                  returnCode = SetMaterialCore(pPrdRef, Path, pNewMaterial, AppliedMaterial)
                  bMaterialFound = true
              }
            }
          }
        }
        if (false == bMaterialFound)
        {
          Notify("Material not found in Table")
        }
      }
    }
  }
}

 

3DXML :

Pipe exemple including the Rule