cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

How to set material in a part with excel vba

Highlighted
Gravel

How to set material in a part with excel vba

I've searched everywhere for an example of this, and am coming up zeros. The only thing I've found is this article: 


https://www.ptc.com/en/support/article?n=CS148500

... and it doesn't work at all. (The "session" object isn't even instantiated in the example).

Here is what I'm doing:

' Dim statements
' connection stuff
...
... Set oModelDescriptor = oModelDescriptorCreate.Create(ModelType, ModelName, Null) Set oModel = oSession.RetrieveModel(oModelDescriptor)
...
blah blah
...
' do some stuff


All of that ^ works fine, as I can read/set parameters, etc.

I can also read the current material with this:

' get material
If oModel.Type = EpfcModelType.EpfcMDL_PART Then
     Set part = oModel
     Set material = part.CurrentMaterial
     .Cells(iRow, colOriginalMaterial).Value = material.Name
End If


But I'm not having any luck at all setting a new material. I'm trying something like this, but nadda (oModel is set earlier in the procedure):

' Set material

Dim part As IpfcPart
Dim material As IpfcMaterial

Set part = oModel
Set material = part.RetrieveMaterial("steel.mtl")
part.CurrentMaterial = material

 

Any help?

Tags (1)
2 REPLIES 2
Highlighted

Re: How to set material in a part with excel vba

Helllooooo.......   is this thing on?

Does anyone ever actually answer questions here? I don't think I've ever had a single response.  🙂

Highlighted

Re: How to set material in a part with excel vba

Maybe Creo can't found mtl file.

Try manually add new material from mtl into part.

Then use GetMaterial (Name as string). This function return IpfcMaterial. And then set this material to the part properties

part.CurrentMaterial = material

 

PS: in PTC case material = part.RetrieveMaterial("Iron") loading material by mtl file name WITHOUT extension .mtl. In your code you using name with extension

Announcements