Update all styles in ipt/iam with VBA

Update all styles in ipt/iam with VBA

bindlmi
Advocate Advocate
5,878 Views
23 Replies
Message 1 of 24

Update all styles in ipt/iam with VBA

bindlmi
Advocate
Advocate

Hi,

I want to update all styles in a 3D-document with VBA. I'm using Inventor 2018.3.3 (German).

I already wrote a code, that updates LightingStyles, TextStyles, RenderStyles, Materials and SheetMetalStyles, but I cannot find APIs for the last two styles (see picture). Are there any APIs to update these "DimensionStyles" and "StandardStyles" from 3D Annotations?

 

If anyone needs it, here is my code:

Public Sub Refresh3D_Styles()

Dim oDoc As Document
Set oDoc = ThisApplication.ActiveDocument

'Beleuchtungsstile
    Dim oLightingStyle As LightingStyle
    
    For Each oLightingStyle In oDoc.LightingStyles
        If oLightingStyle.UpToDate = False Then
            oLightingStyle.UpdateFromGlobal
        End If
    Next

'Textstile
    Dim oTextStyle As TextStyle
    
    For Each oTextStyle In oDoc.TextStyles
        If oTextStyle.UpToDate = False Then
            oTextStyle.UpdateFromGlobal
        End If
    Next

'Darstellungen (Farben)
    Dim oRenderStyle As RenderStyle
    
    For Each oRenderStyle In oDoc.RenderStyles
        If oRenderStyle.UpToDate = False Then
            oRenderStyle.UpdateFromGlobal
        End If
    Next

'Materialien
    Dim oMaterial As Material
    
    For Each oMaterial In oDoc.Materials
        If oMaterial.UpToDate = False Then
            oMaterial.UpdateFromGlobal
        End If
    Next

'Blechstile
    If oDoc.ComponentDefinition.Type = kSheetMetalComponentDefinitionObject Then
        
        Dim oSheetMetalStyle As SheetMetalStyle
        
        For Each oSheetMetalStyle In oDoc.ComponentDefinition.SheetMetalStyles
            If oSheetMetalStyle.UpToDate = False Then
                oSheetMetalStyle.UpdateFromGlobal
            End If
        Next
        
    End If

End Sub

 

Kind regards

Michael

Accepted solutions (2)
5,879 Views
23 Replies
Replies (23)
Message 21 of 24

engilic
Advocate
Advocate

Thank you @WCrihfield ,

 

this looks very interesting, will try it asa I go to my work.

 

Now you open more possibilities and now I have more questions.

 

Is it possible to get the value of selected button or item? If it is OK button to get a type of it or at least to get a value “OK”, also if somehow possible to go through all children with sending TAB key, then question is can I get value of selected child and then decide whether to include it or not.

 

I saw some people do the loop while sending keys, or maybe they are sending keys in the loop, maybe calling the same command in the loop and then each time sending different keys according to selection, since I believe if you once send a command, sending it again want do anything but then you can focus on Inventor and then send a key to the same, previously, sent command window.

Also I think I saw some people say it is possible to get window name, so maybe possible to get more info from the open window.

Sounds very interesting, just can we get any return info from the open window and how?

 

The thing is that I do not want to include all children in Style Update since some of them are locked and not checked out so I do not want to change them, and if I know the file name, it is easy to decide. With your earlier post and little bit of searching I think it is possible, but not exactly sure how.

 

Is there an explanation what can we do in iLogic or VBA in Inventor with sending keys, similar and related commands?

 

thank you @WCrihfield 

0 Likes
Message 22 of 24

WCrihfield
Mentor
Mentor

Hi, @engilic .  The SendKeys process I was using in those rules is a pretty basic 'Sub'. It just blindly does what its told, without knowing where it is going, and doesn't return anything. The line of code just before it using AppActivate (vb.net / vba) is what prepares/sets-up the (where to send it) for the SendKeys method following it. If not set-up correctly, using SendKeys can sometimes be dangerous, because it may send those keystrokes to the wrong target, which could cause unforeseen results on your system or other software. I just know that this order of events worked for me, to ensure it sent those keystrokes to that dialog, without having to name or find that specific dialog.


I don't currently know how to retrieve info about whatever button or setting your focus may currently be at within a sub-application level pop-up dialog after using the SendKeys sub.  I know there are ways to attempt to find/get info about window objects on screen, and sometimes even the contents of those windows, in certain situations, but that's likely going to an area of coding that I'm just not familiar enough with right now to give advise about.

 

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 23 of 24

engilic
Advocate
Advocate

Thank you @WCrihfield ,

 

You are very helpful and you spend a lot of time explaining, I appreciate that very much.

 

I went away from sending keys since as you said it's 'blind' and can be dangerous, so for this case, I just updated all styles by doing this, might be helpful for someone:

 

'Update Styles

Dim oDoc As Document = ThisApplication.ActiveEditDocument
Dim oStyle As Style

oStyles = oDoc.StylesManager.Styles

For Each oStyle In oStyles
	If Not oStyle.UpToDate Then
		oStyle.UpdateFromGlobal
	End If
Next

 

It would be still helpful and nice to precisely say to which window I want to send keys and get some info from windows, but for now, I'm ok.

 

Thank you once again very much for all your help and your time.

 

Have a lovely day

Message 24 of 24

nbonnett-murphy
Advocate
Advocate
Thanks very much for this. We have hundreds of parts that got strange expanded plate textures applied during a migration, so I have to purge and update styles all the time. I'll put this on a "file open" trigger and not worry about it ever again.

I was also able to make it purge styles first by replacing "UpdateStylesCmd" with "PurgeStylesCmd".
0 Likes