2015 assembly material change vba code is not functioning properly in 2016

2015 assembly material change vba code is not functioning properly in 2016

k14348
Advocate Advocate
417 Views
0 Replies
Message 1 of 1

2015 assembly material change vba code is not functioning properly in 2016

k14348
Advocate
Advocate

Public Sub AssyMaterialChange()
' Check that an assembly is active.
If ThisApplication.ActiveDocumentType <> kAssemblyDocumentObject Then
MsgBox "An assembly must be active."
Exit Sub
End If

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

' Get the custom property from the assembly and set it.
Call SetPropertyValue(asmDoc, "Design Tracking Properties", "Material", "(NS) S235")

' Iterate through all of the documents referenced by the assembly.
Dim Doc As Document
For Each Doc In asmDoc.AllReferencedDocuments
Call SetPropertyValue(Doc, "Design Tracking Properties", "Material", "(NS) S235")
Next
End Sub


Private Function SetPropertyValue(Doc As Document, PropertySetName As String, PropertyName As String, PropertyValue As Variant) As Boolean
' Attempt to get the specified property set.
Dim propSet As PropertySet
On Error Resume Next
Set propSet = Doc.PropertySets.Item(PropertySetName)
If Err.Number <> 0 Then
' Failed to get the specified property set. Return an error.
SetPropertyValue = False
Exit Function
End If

' Attempt to get the specified property.
Dim prop As Property
Set prop = propSet.Item(PropertyName)
If Err.Number <> 0 Then
Err.Clear

' The property is not there, so create it.
Call propSet.Add(PropertyValue, PropertyName)
If Err.Number <> 0 Then
' Failed to add the property.
SetPropertyValue = False
Exit Function
End If
Else
prop.Value = PropertyValue
If Err.Number <> 0 Then
' Failed to set the value.
SetPropertyValue = False
Exit Function
End If
End If

SetPropertyValue = True
End Function

 

 

If i run this code individual part material name not changing. When i call that part into idw its working. Plz help

0 Likes
418 Views
0 Replies
Replies (0)