Guys,
The codes work when the value matches the listed items from the material component.
Since I am reading the value from another place, the end users might have entered "steels" instead of "steel".
Any codes that I can check to see it matches, if it doesn't match then I want a message box to display. Below is what I am trying to achieve but the code doesn't work - getting an error about object required.
Thanks,
Tony
--------This one works-----------------
Dim oPdoc As PartDocument
Set oPdoc = oDoc1
Dim oComp As ComponentDefinition
Set oComp = oPdoc.ComponentDefinition
'Debug.Print oPdoc.ComponentDefinition.Material.name
Dim sTemp As String
sTemp = "Steel"
Dim oMat As Material
Set oMat = oPdoc.Materials(sTemp)
oPdoc.ComponentDefinition.Material = oMat
Debug.Print oPdoc.ComponentDefinition.Material.name
End Sub
----------- Trying to achieve, but codes doesn't work ---
Public Sub ChangeMat()
Dim oPdoc As PartDocument
Set oPdoc = oDoc1
Dim oComp As ComponentDefinition
Set oComp = oPdoc.ComponentDefinition
'Debug.Print oPdoc.ComponentDefinition.Material.name
Dim sTemp As String
sTemp = "Steel"
Dim oMat As Material
Set oMat = oPdoc.Materials(sTemp)
If oPdoc.ComponentDefinition.Material <> oMat Then
MsgBox "Must select manually from the list", vbInformation, ""
Else
Debug.Print oPdoc.ComponentDefinition.Material.name
End If
End Sub
The codes work when the value matches the listed items from the material component.
Since I am reading the value from another place, the end users might have entered "steels" instead of "steel".
Any codes that I can check to see it matches, if it doesn't match then I want a message box to display. Below is what I am trying to achieve but the code doesn't work - getting an error about object required.
Thanks,
Tony
--------This one works-----------------
Dim oPdoc As PartDocument
Set oPdoc = oDoc1
Dim oComp As ComponentDefinition
Set oComp = oPdoc.ComponentDefinition
'Debug.Print oPdoc.ComponentDefinition.Material.name
Dim sTemp As String
sTemp = "Steel"
Dim oMat As Material
Set oMat = oPdoc.Materials(sTemp)
oPdoc.ComponentDefinition.Material = oMat
Debug.Print oPdoc.ComponentDefinition.Material.name
End Sub
----------- Trying to achieve, but codes doesn't work ---
Public Sub ChangeMat()
Dim oPdoc As PartDocument
Set oPdoc = oDoc1
Dim oComp As ComponentDefinition
Set oComp = oPdoc.ComponentDefinition
'Debug.Print oPdoc.ComponentDefinition.Material.name
Dim sTemp As String
sTemp = "Steel"
Dim oMat As Material
Set oMat = oPdoc.Materials(sTemp)
If oPdoc.ComponentDefinition.Material <> oMat Then
MsgBox "Must select manually from the list", vbInformation, ""
Else
Debug.Print oPdoc.ComponentDefinition.Material.name
End If
End Sub