What Part Document properties do I use to replicate Update Styles and Purge Styles?

What Part Document properties do I use to replicate Update Styles and Purge Styles?

W.Scott.Dempster
Enthusiast Enthusiast
302 Views
4 Replies
Message 1 of 5

What Part Document properties do I use to replicate Update Styles and Purge Styles?

W.Scott.Dempster
Enthusiast
Enthusiast

I am looking to write a program which will replicate the functions for Update Styles and Purge Styles, but I am struggling to find what classes within the Part Document to look into for each (ie RenderStyles, MaterialAssets, AppearanceAssets, etc.), and how to use them.

 

Could anyone tell me which class(es) I should look at?

 

And once I have them, what methods should I call that is similar to Update Styles and Purge Styles? I am hoping it is easy as .UpdateFromGlobal for Update Styles and .Delete for Purse Styles, but I would appreciate any information.

 

Note: I am aware there exists code that replicates both functions by using SendKeys, and they work great for one part, but if I try to use it for a list of parts it starts to fall apart as you may expect a SendKeys program to do.

0 Likes
Accepted solutions (1)
303 Views
4 Replies
Replies (4)
Message 2 of 5

JelteDeJong
Mentor
Mentor

something like this:

Sub Main()
    Dim doc As PartDocument = ThisDoc.Document
    PurgeDocument(doc)
End Sub

Private Sub PurgeDocument(doc As PartDocument)
    For Each style As LightingStyle In doc.LightingStyles
        If (Not style.InUse) Then
            style.Delete()
        End If
        If (Not style.UpToDate) Then
            style.UpdateFromGlobal()
        End If
    Next

    For Each style As MarkStyle In doc.MarkStyles
        If (Not style.InUse) Then
            style.Delete()
        End If
        If (Not style.UpToDate) Then
            style.UpdateFromGlobal()
        End If
    Next

    For Each style As RenderStyle In doc.RenderStyles
        If (Not style.InUse) Then
            style.Delete()
        End If
        If (Not style.UpToDate) Then
            style.UpdateFromGlobal()
        End If
    Next

    For Each style As TextStyle In doc.TextStyles
        If (Not style.InUse) Then
            style.Delete()
        End If
        If (Not style.UpToDate) Then
            style.UpdateFromGlobal()
        End If
    Next
End Sub

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 5

W.Scott.Dempster
Enthusiast
Enthusiast

Thanks for the response. I tried the code out and I am seeing two issues:

 

1) Inventor doesn't like the .Delete method for these styles. For instance, I am getting "Method Delete of object <style> failed" when I try this in VBA, and it fails at the same point in iLogic.

2) The .Update method doesn't seem to work either.

 

Do you think this could be a permissions issue?

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor
Accepted solution

Hi @W.Scott.Dempster.  Out of curiosity, which version of Inventor are you using.  If you are not using 2023 version, then you may not have the MarkStyles.  Also, try commenting out the block of code dealing with RenderStyles, and see if you still have errors.  The RenderStyles & RenderStyle objects were basically obsoleted back around 2016 or so, in favor of the new Asset objects for materials, appearances, & physical properties.  They have been attempting to keep most of the functionality working for the sake of keeping legacy solutions working, but I would recommend avoiding them in any current or future automation solutions.  The Asset object does have a Delete method, and an IsUsed (not InUse) property, but does not have an UpdateFromGlobal method.  To update one, you could have to use the CopyTo method, and specify True for ReplaceExisting argument, or simply delete it, then create a new copy from the library.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 5

W.Scott.Dempster
Enthusiast
Enthusiast

Hi @WCrihfield -- I am using 2021, so the MarkStyles definitely threw me for a loop haha. Thanks for the heads up about Styles.

 

But I am gaining traction with your recommendation of: 1) using the Assets object of the Part Document, 2) using the .Delete method per my discretion, and 3) copying from the Application.AssetLibrary to my Part Document. Seems to be working so far.

 

Thank you for your help!

0 Likes