3DX - Apply Existing Material Using VBA

Dillon Thomison

3DX - Apply Existing Material Using VBA

Does anybody know how to apply an existing material to a Part using VBA in 3DX?

I have reviewed the VBA documentation and it only discusses methods for creating and applying a new material. It seems to be missing a method for getting the reference to the Core Material stored in the PLM system and applying that to the Part.

Marc D. Young

RE: 3DX - Apply Existing Material Using VBA
(in response to Dillon Thomison)

Hello Dillon,

We did something using EKL to read the material of an existing Part (VPMRefernce) in CATIA.   See video Three Ways to Automate CATIA Tasks with EKL Scripts - XLM Solutions   I assume you want to do the opposite though, automatically assign a material to a CATIA Part.    We would be happy to look into this for you.  If interested, feel free to reach out at [login to unmask email]

Best Regards,

Marc Young

www.xlmsolutions.com

Dillon Thomison

RE: 3DX - Apply Existing Material Using VBA
(in response to Marc D. Young)

Hi Marc. I actually just discovered your videos last week. Yes, I would like to create a way to quickly take a material from our library in 3DX and apply it to a part. It really seems like Dassault left out a method to do that considering the Material PLM Service only has a PLMCreate method.

Marc A Jeeves

RE: 3DX - Apply Existing Material Using VBA
(in response to Dillon Thomison)

Here is how to build a list of materials and apply it to a multi-value parameter in an action

 

// Update_Material_List

 

parameter = ( parameter == True ) ? False ; True

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( "Querying Material: " + Material_Name )
ProgressBarSetValue( 5 )
ProgressBarSetText( "Querying..." )
Let ioPLMQuery ( PLMQuery )

Let ioPLMResultsList ( List )
ioPLMQuery = CreatePLMQuery( "CATMATReference" )
ioPLMQuery.AddCriterion( "project" , "Standard" )
ioPLMQuery.AddCriterion( "current" , "RELEASED" )
ioPLMResultsList = ioPLMQuery.RunQuery()

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

Let ioPLMQueryResult( PLMQueryResult )
Let ioResultStringList ( List )
Let ioIndex ( Integer )
ioIndex = 1
For ioPLMQueryResult inside ioPLMResultsList
{
Let ioMaterialRef ( CATMatReference )
ioMaterialRef = ioPLMQueryResult.LoadResult( ) : CATMatReference
Notify("#" , ioMaterialRef.V_Name)

ioResultStringList->Append( ioMaterialRef.V_Name )

ProgressBarSetValue( ( 100 / ioPLMResultsList->Size() ) * ioIndex)
ProgressBarSetText( "Material Found : " + ioMaterialRef.V_Name )
ioIndex = ioIndex + 1
}

ioResultStringList->RemoveDuplicates()
ProgressBarSetValue( 100 )
Material_Name.AuthorizedValues = ioResultStringList

 

 

 

Here is how to apply the material from the list with EKL this was written as an action

 

// Material_Name : String

//Apply_Material_On_Body : Boolean

 

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 )
ioPLMQuery = CreatePLMQuery( "CATMATReference" )
ioPLMQuery.AddCriterion( "project" , "Standard" )
ioPLMQuery.AddCriterion( "V_Name" , Material_Name )
ioPLMQuery.AddCriterion( "current" , "RELEASED" )
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 )
}

Edited By:
Marc A Jeeves[Gulfstream Aerospace Corporation] @ Sep 27, 2022 - 09:45 AM (America/Central)

Marc D. Young

RE: 3DX - Apply Existing Material Using VBA
(in response to Dillon Thomison)

Hi Dillon,

Looks like Marc J beat me to it.  if you have any questions with what he provided or need any other help, feel free to reach out.

Marc Young

www.xlmsolutions.com

Marc A Jeeves

RE: 3DX - Apply Existing Material Using VBA
(in response to Marc D. Young)

haha

Dillon Thomison

RE: 3DX - Apply Existing Material Using VBA
(in response to Marc A Jeeves)

Marc J,

I really appreciate the code snippet! Unfortunately our 3DX instance isn't set up to allow individuals to use EKL. That is why I have been sticking with the clunk VBA scripts. I'm curious if there is a way to use EKL functions within a VBA script.

I see in your script you are able to use LoadResult to get the material into the MatRef. I think VBA is missing that method. It seems like the only way to actually load PLMEntities is to fully open them in an editor.