- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
update styles library
Hello,
I'm Maarten and I'm trying to create a macro that allows me to update my entiry library from 2016 to 2018 automatically.
The library contains Parts, Iparts and iLogic components (assemblies).
So,
Let me first explain the steps that I need to follow when I must do this manually.
1. Open the iPart - masterfile on toplevel and modify the iproperties by adding a new Authority nr. (I need to modify this for our ERP system)
2. Update all styles ( Tab Manage)
3. Save
Then I insert this ipart into an assembly, update the style library and create all the variants according to the excell table.
I create all the parts by using following code:
And then all the parts are made.
But, I don't want to do this for all the iParts of my library.
What I want is to update styles, add authority nr, create all the variants in 1 action.
1. Insert ALL the iParts + parts in an assembly -
2. Press 1 button and the computer does the rest.
I created the following script, but I can't manage to update the COLOR styles of the part.
See below
Sub UpdateToNewRelease()
'Add a New Stock Number (switch to new structure in 2018)
' step 1 Declare stuff
Dim oAssyDoc As AssemblyDocument
Dim oComponent As ComponentOccurrence
Dim oRefDoc As PartDocument
Dim invCustomPropertySet As PropertySet
Dim PropAuthority As Property
Dim oPartDoc As PartDocument
Dim oFactoryDoc
Set oAssyDoc = ThisApplication.ActiveDocument
' step 2 - ask user for value of iproperty
Dim AuthorityNr As String
AuthorityNr = InputBox("What is the new Authority Number (Old Stock Number)", "Set Number", "")
' step 2 get a reference to each part
For Each oComponent In oAssyDoc.ComponentDefinition.Occurrences
If oComponent.IsiPartMember = False Then
'change the part Authority number directly
'set the Autority iProperty's
Set oRefDoc = oComponent.ReferencedDocumentDescriptor.ReferencedDocument
Set invCustomPropertySet = oRefDoc.PropertySets.Item("Design Tracking Properties")
Set PropAuthority = invCustomPropertySet.Item("Authority")
PropAuthority.Value = AuthorityNr
Else
'it is an ipart
'open the ipart and change the numnber
Set oPartDoc = oComponent.ReferencedDocumentDescriptor.ReferencedDocument
Set oFactoryDoc = oPartDoc.ReferencedDocumentDescriptors.Item(1).ReferencedDocument
'change the Autority Number of the factory document
Set invCustomPropertySet = oFactoryDoc.PropertySets.Item("Design Tracking Properties")
Set PropAuthority = invCustomPropertySet.Item("Authority")
PropAuthority.Value = AuthorityNr
'update styles
Dim mat As Material
For Each mat In oFactoryDoc.Materials
If mat.UpToDate = False Then
Call mat.UpdateFromGlobal
Debug.Print mat.Name
End If
Next
End If
Next
End Sub
When i open the ipart to verify - then I see that the authority nr is filled in, but the color is not updated automatically.
see below
Is there someone that can help me out how I can update the style libraries (type color) automatically??
That would be great!
Thanks a lot.