Change material content center part through vba

Change material content center part through vba

frederic.vandenplas
Collaborator Collaborator
702 Views
4 Replies
Message 1 of 5

Change material content center part through vba

frederic.vandenplas
Collaborator
Collaborator

I wrote (by accident Smiley Very Happy ) a little piece of code that allows me to change the material of default content center parts (out of the box)

 

Strange, because i cannot change the material throught the interface of a standard cc part (default behaviour)

 

Even stranger is that i can add unknown materials, but through the iproperties the part shows allways the default (steel, mild ) material,

except in de BOM.

 

This is a very strange behaviour or even a bug/leak or is there another explanation for it? someone ever came across this?

 

modified.jpgmodified1.jpgmodified2.jpg

If you think this answer fullfilled your needs, improved your knowledge or leads to a solution,
please feel free to "kudos"
0 Likes
703 Views
4 Replies
Replies (4)
Message 2 of 5

wispoxy
Advisor
Advisor
Wow, what a disaster. I would just reset everything back to defaults.
0 Likes
Message 3 of 5

Wind_Talker
Contributor
Contributor
Hi Frederic,

This is strange indeed. I am more interested in the code. Will you be happy to provide the code for us all?

Your help is appreciated.

Regards
Message 4 of 5

wispoxy
Advisor
Advisor

Same as @Wind_Talker, I'm interested in the code. Please share.

0 Likes
Message 5 of 5

frederic.vandenplas
Collaborator
Collaborator
Public Sub ChangeMaterialAssembly()

' Get the active assembly.
Dim oAsmDoc As AssemblyDocument
Set oAsmDoc = ThisApplication.ActiveDocument

' Get all of the referenced documents.
Dim oRefDocs As DocumentsEnumerator
Set oRefDocs = oAsmDoc.AllReferencedDocuments

' Iterate through the list of documents.
Dim oRefDoc As Document
For Each oRefDoc In oRefDocs
    oRefDoc.PropertySets(3).Item("Material").Value = "S235JR" '
Next

End Sub

Sub ChangeMaterialPart()

Dim oPartDoc As PartDocument
Set oPartDoc = ThisApplication.ActiveDocument
oPartDoc.PropertySets(3).Item("Material").Value = "S235JR"

End Sub

This code is quite simple but does the "trick" 

If you think this answer fullfilled your needs, improved your knowledge or leads to a solution,
please feel free to "kudos"
0 Likes