Reply
Solved! Go to solution

Apply Material Error

Hello All,

 

I am changing the Material of a Sheet Metal but the other Physical Properties are not changed with the change in Material.

 

I found that using ApplyMaterial() method will do the "Apply to Model" functionality.

 

I am trying to use that method but I am getting Argument Exception "The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))"

 

I used the below Code:

 objApplication = CreateObject("SolidEdge.Application")

objSheetMetalDoc=objApplication.ActiveDocument

 objMatTable = objApplication.GetMaterialTable

objMatTable.ApplyMaterial(objSheetMetalDoc, newMaterial)

 

 where newMaterial is a String.

 

I also tried using Dim ObjDoc as Object and use objDoc instead of objSheetMetalDoc.

 

I am not sure why I am getting this error.

Please help.

 

Thank you

6 REPLIES
Solution
Solution
Accepted by topic author Developer
‎08-26-2015 04:32 AM

You are probably using an invalid material. Make sour it...

[ Edited ]

You are probably using an invalid material. Make sure it exists in the list of names before applying it (see my example).

I my version of SE, I get an exception although it is applying the face style and setting the physical properties correctly, so I simply ignore the exception.

Dim objDoc As SheetMetalDocument = objApp.ActiveDocument
Dim objMatTable As MatTable = objApp.GetMaterialTable()
Dim nMaterials As Integer = 0
Dim materials() As Object = Nothing
objMatTable.GetMaterialList(nMaterials, materials)
If Array.IndexOf(materials, "Copper") >= 0 AndAlso Array.IndexOf(materials, "Gold") >= 0 Then
  Dim strMaterial As String = ""
  objMatTable.GetCurrentMaterialName(objDoc, strMaterial)
  Try
    If strMaterial = "Gold" Then
      objMatTable.ApplyMaterial(objDoc, "Copper")
    Else
      objMatTable.ApplyMaterial(objDoc, "Gold")
    End If
  Catch ex As Exception
    ' Ignore the exception
  End Try
End If

 

Re: You are probably using an invalid material. Make sour it...

Hello Martin,

Thank you very much for the quick solution.
It worked.

Similarly how to Apply the changes in Gage Value to the Model?

Thanks

To apply the changes of the gage values, use the followin...

To apply the changes of the gage values, use the following code, which sets all values to 1 mm. Keep in mind that SE uses "meter" as its internal measurement unit:

Dim objDoc As SheetMetalDocument = objApp.ActiveDocument
Dim objUOM As UnitsOfMeasure = objDoc.UnitsOfMeasure
Dim vVars As SolidEdgeFramework.Variables = objDoc.Variables
objApp.DelayCompute = True
vVars.Edit("MaterialThickness", objUOM.FormatUnit(UnitTypeConstants.igUnitDistance, 0.001))
vVars.Edit("BendRadius", objUOM.FormatUnit(UnitTypeConstants.igUnitDistance, 0.001))
vVars.Edit("ReliefLength", objUOM.FormatUnit(UnitTypeConstants.igUnitDistance, 0.001))
vVars.Edit("ReliefWidth", objUOM.FormatUnit(UnitTypeConstants.igUnitDistance, 0.001))
objApp.DelayCompute = False

 

Re: To apply the changes of the gage values, use the followin...

Hi Martin,

I am able to update each of these values using SetGlobalParameter.
But I am updating the Gage using Sheet Metal "MechanicalModelling" property.

I want the Material Thickness, Bend Radius, Relief Depth and Width to be updated as present on Material.mtl file for the Gage.

Like if i change Gage to 14 Gage from 16 Gage I want the Material Thickness, Bend Radius, Relief Depth and Width to be updated to that of 14 Gage.

Re: To apply the changes of the gage values, use the followin...

I actually don't have code for that, but you will have to GetPSMGaugeListFromExcel, choose one of the available gages and then apply it to the document using SetDocumentToGageTableAssociation.
Both methods belong to the MatTable object.

Re: To apply the changes of the gage values, use the followin...

Here is some code:
[CODE]
Dim objDoc As SheetMetalDocument = objApp.ActiveDocument
Dim objMatTable As MatTable = objApp.GetMaterialTable()
Dim strMaterial As String = ""
objMatTable.GetCurrentMaterialName(objDoc, strMaterial)
If String.IsNullOrEmpty(strMaterial) Then strMaterial = "Stainless Steel"
Dim nGages As Integer = 0
Dim gages() As Object = Nothing
objMatTable.GetPSMGaugeListFromExcel(strMaterial, nGages, gages)
objMatTable.SetDocumentToGageTableAssociation(objDoc, gages(0), strMaterial, True, True)
[/CODE]