Code request: Set all tweaks to "no trail"

Code request: Set all tweaks to "no trail"

-niels-
Mentor Mentor
2,048 Views
21 Replies
Message 1 of 22

Code request: Set all tweaks to "no trail"

-niels-
Mentor
Mentor

Hello code guru's, i hope someone can help me with this.

 

I am doing a lot of revisions to old(er) presentation files, from before the "no trail" option was even available, and i want to make all trails visible and then set them to "no trail" so i can add my own custom trails where needed.

Doing this manually is taking a lot of time, so i was wondering if this could be automated?

It would probably have to be done with a macro, since iLogic isn't available in presentations, but i'm not even sure the "no trail" option is available in the API.

 

Is anyone willing to put some of their precious time into this?

 


Niels van der Veer
Inventor professional user & 3DS Max enthusiast
Vault professional user/manager
The Netherlands

0 Likes
Accepted solutions (1)
2,049 Views
21 Replies
Replies (21)
Message 2 of 22

pball
Mentor
Mentor

Well I don't have a solution but I might be close. I had to add a snapshot view to the IPN to get anywhere with the API. This loops through each trail and it's segments and prints if that segment is visible or not. If I try to set oSeg.Visible = False I get an error that the object doesn't support that. Not sure if the IPN API is just lacking there or if this headache is making me stupid right now.

 

Public Sub test()
    Dim oPresDoc As PresentationDocument
    Set oPresDoc = ThisApplication.ActiveEditDocument
        
    Dim oTrail As PresentationTrail
    Dim oSeg As PresentationTrailSegment
    

    For Each oTrail In oPresDoc.Scenes.Item(1).SnapshotViews.Item(1).Trails
        For Each oSeg In oTrail.Segments
            Debug.Print oSeg.Visible
        Next
    Next
End Sub

 

Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
0 Likes
Message 3 of 22

JelteDeJong
Mentor
Mentor

I did have a look in to it. From an external application (that mimics iLogic) i could find a property "TrailSegment.Visible" but its read only.  this is the code that i used:

Dim doc As PresentationDocument = ThisDoc.Document

For Each presentationExplodedView As PresentationExplodedView In doc.PresentationExplodedViews
    MsgBox(presentationExplodedView.Name)
    For Each trail As Trail In presentationExplodedView.Trails
        ' trail.SetVisibility(False) <- function exits but fails
        For Each trailSegment As TrailSegment In trail
            ' trailSegment.Visible <- property is readonly
        Next
    Next
Next

 Then i did a fast search and found this post. There its stated that its not possible to set the visibility.

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 4 of 22

-niels-
Mentor
Mentor

@pball @JelteDeJong Thanks for looking into this, much appreciated!

So, if i understand correctly from both your posts, changing the visibility of the trails isn't possible through code.

That's ok, selecting all tweaks and setting "show trails" is fast enough.

 

My issue starts after that, i have to go into each individual tweak and change the state from "all components" to "no trail". (see screenshot)

afbeelding.png

I'm leaning towards the assumption that the API doesn't let you change this either, seeing that changing their visibility isn't even possible.

 

I'll continue doing this manually for now, hope someone can give answer to this part as well.

 

---edit---

Upon reading more of the topic you linked, i read this statement by @YuhanZhang :

"we have not exposed the API for storyboard yet"

 

So i guess it really isn't possible (yet)...


Niels van der Veer
Inventor professional user & 3DS Max enthusiast
Vault professional user/manager
The Netherlands

0 Likes
Message 5 of 22

JhoelForshav
Mentor
Mentor

Hi @-niels- 

 

I think I've found the path to set these tweak states by inspecting the objects in VS. The only problem is that there's no documentation to be found about this, so I don't know what to put as an argument in PresentationDocument.ActivePublication(Context As Object).

 

The path to the property however should look something like this:

Dim oDoc As PresentationDocument = invapp.ActiveDocument
Dim oPublication As Publication = oDoc.ActivePublication("Something") 'Context As Object?
Dim oMarkedView As PublicationMarkedView = oPublication.MarkedViews.Item(1)
Dim oTweak As PublicationTweak = oMarkedView.Tweaks.Item(1)
oTweak.Definition.DisplayTrails = PublicationTweakTrailsDisplayEnum.kNoneTrailsDisplay

 We have these PublicationTweakTrailsDisplayEnumerators:

PublicationTweakTrailsDisplayEnum.kAllComponentsTrailsDisplay
PublicationTweakTrailsDisplayEnum.kAllPartsTrailsDisplay
PublicationTweakTrailsDisplayEnum.kNoneTrailsDisplay
PublicationTweakTrailsDisplayEnum.kSingleTrailDisplay

So this must be it.

 

Maybe if someone from Autodesk can give an answer to what's expected as the Context-argument we'll be able to solve this 🙂

Message 6 of 22

JhoelForshav
Mentor
Mentor

I got it working by traversing the tweak nodes in the BrowserPanes!

Here's the VBA Macro 🙂

 

Sub NoTrails()
Dim oDoc As PresentationDocument
Set oDoc = ThisApplication.ActiveDocument

        Dim oBNs As BrowserNodesEnumerator
        Set oBNs = oDoc.BrowserPanes.ActivePane.TopNode.BrowserNodes(1).BrowserNodes(2).BrowserNodes
        Dim oBN As BrowserNode
        For Each oBN In oBNs
            If TypeOf oBN.NativeObject Is PublicationTweak Then
                Dim oPT As PublicationTweak
                Set oPT = oBN.NativeObject
                Dim oDef As PublicationTweakDefinition
                Set oDef = oPT.Definition.Copy
                oDef.DisplayTrails = PublicationTweakTrailsDisplayEnum.kNoneTrailsDisplay
                oPT.Definition = oDef
            End If
        Next
End Sub
0 Likes
Message 7 of 22

-niels-
Mentor
Mentor

@JhoelForshav Nice detective work! 🔎

I had a quick glance in the (IV2018) programming help and i could find some of the objects and enumerators you list, but not everything links up or is available. (as you stated)

 

I have to finish these drawings, so i can't spend too much time on coding.

Also hoping someone from Autodesk can help out.


Niels van der Veer
Inventor professional user & 3DS Max enthusiast
Vault professional user/manager
The Netherlands

0 Likes
Message 8 of 22

JhoelForshav
Mentor
Mentor

@-niels- 

I think we posted pretty much at the same time so I don't know if you saw my last post.

I've only tried it in a very simple presentation, but it works for me!

 

Try it and let me know 🙂

Message 9 of 22

-niels-
Mentor
Mentor
I noticed it after i posted, am going to try it now.
Will let you know in a bit, anything special i need to do?

Niels van der Veer
Inventor professional user & 3DS Max enthusiast
Vault professional user/manager
The Netherlands

Message 10 of 22

JhoelForshav
Mentor
Mentor

I never work with Presentations myself so I'm not 100% sure about the position of the "Tweaks folder" in the browserpane. But if it's always like this it should work 🙂

tweaks.PNG

0 Likes
Message 11 of 22

YuhanZhang
Autodesk
Autodesk

Hi Niels,

 

Till now we don't have full API support for Presentation so for your request I think currently we can just turn of all the trail segments, but to do this you need to create a Presentation snapshot view for the storyboard. Below is a sample VBA code to do this, you can try if it works for you:

 

Sub TurnOffTrailsInSnapshotView()

Dim oPresDoc As PresentationDocument
Set oPresDoc = ThisApplication.ActiveDocument

Dim oScene As PresentationScene
 Set oScene = oPresDoc.Scenes(1)

Dim oSnapShot As PresentationSnapshotView
 Set oSnapShot = oScene.SnapshotViews(1)

' we need to break the associativity between the snapshot view and storyboard before editing it
oSnapShot.StoryboardAssociative = False

' enter the edit mode for snapshot view(eitherwise the edit will fail)
oSnapShot.Edit

Dim oTrail As PresentationTrail
For Each oTrail In oSnapShot.Trails
    Dim oSeg As PresentationTrailSegment
    For Each oSeg In oTrail.Segments
        Debug.Print oSeg.Visible
        oSeg.Visible = False
        Debug.Print oSeg.Visible
    Next
Next

End Sub

 

@pball @JelteDeJong Please try above VBA code. 



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 12 of 22

-niels-
Mentor
Mentor

Seems about right:

afbeelding.png

It's not doing anything though...

I changed a couple of tweaks back to "all components" and the macro isn't changing them.

When using the "step into" function i can see it skip over the

 

If TypeOf oBN.NativeObject Is PublicationTweak Then

 

So it's seeing the tweaks, but they don't seem to be "PublicationTweak"

 

@YuhanZhang Thanks for joining in.

I'm going to asume your code works, but i won't use it like that.

Breaking associativitiy of the snapshot is not something i want to do, i need to be able to update the snapshot(s) in respect to the storyboard.

If @JhoelForshav's code is able to work in IV2018 then i'd have what i need, could you see if that's possible?


Niels van der Veer
Inventor professional user & 3DS Max enthusiast
Vault professional user/manager
The Netherlands

0 Likes
Message 13 of 22

JhoelForshav
Mentor
Mentor

@-niels- 

That's strange... See screencast - Am I doing the tweaks the wrong way or something?

 

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Message 14 of 22

-niels-
Mentor
Mentor

@JhoelForshav Nope, that seems alright to me.

It might be because i'm on 2018.

 

I've added a msgbox to find out what type it's seeing, maybe we can compare?

afbeelding.png

Sub NoTrails()
Dim oDoc As PresentationDocument
Set oDoc = ThisApplication.ActiveDocument

        Dim oBNs As BrowserNodesEnumerator
        Set oBNs = oDoc.BrowserPanes.ActivePane.TopNode.BrowserNodes(1).BrowserNodes(2).BrowserNodes
        Dim oBN As BrowserNode
        For Each oBN In oBNs
        Call MsgBox("Type is: " & oBN.NativeObject.Type, vbOKOnly, "info")
        If TypeOf oBN.NativeObject Is PublicationTweak Then
                Dim oPT As PublicationTweak
                Set oPT = oBN.NativeObject
                Dim oDef As PublicationTweakDefinition
                Set oDef = oPT.Definition.Copy
                oDef.DisplayTrails = PublicationTweakTrailsDisplayEnum.kNoneTrailsDisplay
                oPT.Definition = oDef
            End If
        Next
End Sub

Niels van der Veer
Inventor professional user & 3DS Max enthusiast
Vault professional user/manager
The Netherlands

Message 15 of 22

JhoelForshav
Mentor
Mentor

@-niels- 

Your object type is PublicationComponent, So maybe we're not getting in to the tweaks folder after all...

0 Likes
Message 16 of 22

-niels-
Mentor
Mentor

@JhoelForshav Just to make sure i tried it on a new presentation, where it did work.

afbeelding.png

So your code works, but there is something different in these old ipn's.

(like i mentioned in my opening post, these are from before the "no trails" option.)

Not sure where to go from here...


Niels van der Veer
Inventor professional user & 3DS Max enthusiast
Vault professional user/manager
The Netherlands

Message 17 of 22

JhoelForshav
Mentor
Mentor
Accepted solution

I see... I still find the object type strange though. Maybe it's just something with the order of the browsernodes.

Try this code to make sure we're actually in the tweaks folder:

 

Sub NoTrails()
Dim oDoc As PresentationDocument
Set oDoc = ThisApplication.ActiveDocument

Dim oBNs As BrowserNodesEnumerator
Set oBNs = oDoc.BrowserPanes.ActivePane.TopNode.BrowserNodes(1).BrowserNodes
Dim oBN As BrowserNode
For Each oBN In oBNs
    If oBN.BrowserNodeDefinition.Label = "Tweaks" Then
    MsgBox "Tweaks found!"
    Exit For
    End If
Next
Dim tNode As BrowserNode
For Each tNode In oBN.BrowserNodes
    Dim oPT As PublicationTweak
    Set oPT = tNode.NativeObject
    Dim oDef As PublicationTweakDefinition
    Set oDef = oPT.Definition.Copy
    oDef.DisplayTrails = PublicationTweakTrailsDisplayEnum.kNoneTrailsDisplay
    oPT.Definition = oDef
Next
End Sub

 

If it doesn't give you the message box "tweaks found!" then the problem is finding the nodes....

Message 18 of 22

-niels-
Mentor
Mentor

Without really checking what you've changed yet, this code works!

I get the "tweaks found" message and then it iterates through the tweaks and changes them correctly.

Awesome!

 

Thank you, this will save me a good bit of time doing this manually to hundreds of tweaks. 😃


Niels van der Veer
Inventor professional user & 3DS Max enthusiast
Vault professional user/manager
The Netherlands

Message 19 of 22

JhoelForshav
Mentor
Mentor

Awesome! For some reason I guess the browsernode order was not the same "under the hood" as it's represented in the UI for these old files.

 

I'm glad I could help 🙂

Message 20 of 22

mjkoushik
Explorer
Explorer

Is it possible to change the tweak distances using Publication Tweaks?. No supporting documents for Publication tweak can be found in inv 2021. Pls help

0 Likes