EKL Apply Materials onto a Part From 3DX

Print Friendly, PDF & Email

EKL Apply Materials onto a Part From 3DX

The EKL Script below requires two parameters to be pre-created in the specification tree; Material_Name ( String), and Apply_Material_On_Body ( Boolean). This script connects to the 3DX instance and retrieves multiple objects based on the Criterion. In this case its core materials which can then either be applied to the PartBody or Part based on the Path being supplied or not, using the SetMaterialCore method.

Let oMaterialApplied ( Boolean )

Let ioRepRef ( VPMRepReference )
ioRepRef = GetPLMOwner( Material_Name ) 		// Parameter From Tree

Let ioRef ( VPMReference )
ioRef = ioRepRef.AggregatingReference : VPMReference	// Get Parent Product of the Parameter
Notify("#" , ioRef.PLM_ExternalID  )

CreateProgressBar( "Applying Material: " + Material_Name )
ProgressBarSetValue( 50 )
ProgressBarSetText( "Querying..." )
Let ioPLMQuery ( PLMQuery )

Let ioPLMResultsList ( List )	// PLM Query
ioPLMQuery = CreatePLMQuery( "CATMATReference" )
ioPLMQuery.AddCriterion( "V_Name" , Material_Name )
ioPLMQuery.AddCriterion( "current" , "RELEASED" )
//ioPLMQuery.AddCriterion( "project" , "Standard" )
ioPLMResultsList = ioPLMQuery.RunQuery()

Notify("Number of Results Found : #" , ioPLMResultsList->Size())	

If( ioPLMResultsList->Size() > 0 )
{
	Let ioPLMQueryResult( PLMQueryResult )
	ioPLMQueryResult = ioPLMResultsList [ 1 ]
	
	Let ioMaterialReference ( CATMatReference )
	Let ioMaterialConnection ( CATMatConnection )
	
	Set ioMaterialReference = ioPLMQueryResult.LoadResult( True )
	
	Let ioPath ( String )
	ioPath = "" // Create Material on Part Level
	If( Apply_Material_On_Body == True )
	{
		Let ioFeatureList ( List )
		Let Support( Feature )
		ioFeatureList = GetRootUI()->Query("BodyFeature","x.Name==\"PartBody\"") // Find the Part Body for the Path
		Support = ioFeatureList[ 1 ]
		ioPath = ioRef->CreatePathString( NULL , Support )
		Notify( "Path to Partbody is : #" , ioPath )
	}
	
	Set oMaterialApplied = SetMaterialCore(ioRef , ioPath ,  ioMaterialReference , ioMaterialConnection )
	ProgressBarSetValue( 50 )
}
Else
{
	Message( "Material Not Found in the Database : #" , Material_Name )
}