Clear Thumbnails with white BG Ilogic

Clear Thumbnails with white BG Ilogic

davis.j
Advocate Advocate
1,387 Views
4 Replies
Message 1 of 5

Clear Thumbnails with white BG Ilogic

davis.j
Advocate
Advocate

I have modified the following code using assets from other threads. (Credit to those before me 🙂)

 

What the rule does is temporarily turn off some vault functionality to ignore prompts and errors. It then proceeds to snap and new thumbnail photo for each unique component in throughout the assembly tree. I've got it to a point that works but it is not perfect and large assemblies behave oddly sometimes. My end goal to have a stable rule that can be executed with no errors (Hopefully.)

 

Can someone test this with me. I am trying to identify why sometimes the parts don't close and continue and rather stay open. It is annoying to have to close them all after if the rule doesn't close them automatically.

 

Also how can I specify the code to look for derived parts in a given part and then open those as well and re-snap the thumbnail photo.

Idea Thread:
Save all thumbnails with white background. 

Sub Main()

	oColorScheme = ThisApplication.ActiveColorScheme.Name
	oBackGroundType = ThisApplication.ColorSchemes.BackgroundType

	ThisApplication.ColorSchemes.Item("Presentation").Activate
	ThisApplication.ColorSchemes.BackgroundType = _
	BackgroundTypeEnum.kOneColorBackgroundType 
	
	Dim a = iLogicVb.Automation
	a.RulesOnEventsEnabled = False
	
	If ThisDoc.Document.DocumentType <> kAssemblyDocumentObject Then
		MessageBox.Show("This rule must be run from an Assembly.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1)
	Exit Sub
	End If
	
    Dim oAsmDoc As Document
    oAsmDoc = ThisApplication.ActiveDocument

    Call MakeNewThumbnail(oAsmDoc)

    Dim oSubDoc As Document
    For Each oSubDoc In oAsmDoc.AllReferencedDocuments
        If oSubDoc.IsModifiable Then
            oSubDoc = ThisApplication.Documents.Open(oSubDoc.FullFileName, True)
            Call MakeNewThumbnail(oSubDoc)
            oSubDoc.Close	
        End If
	Next
		
	Call MakeNewThumbnail(oAsmDoc)

	a.RulesOnEventsEnabled = True
	
	ThisApplication.ColorSchemes.Item(oColorScheme).Activate 
	ThisApplication.ColorSchemes.BackgroundType = oBackGroundType

End Sub

Sub MakeNewThumbnail(oDoc As Document)
    On Error Resume Next
    
    With oDoc.ObjectVisibility
        .AllWorkFeatures = False
        .Sketches = False
        .Sketches3D = False
    End With
    
    oDoc.SetThumbnailSaveOption (kActiveComponentIsoViewOnSave)
    oDoc.Save
    
    On Error GoTo 0
    
End Sub

 

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

JelteDeJong
Mentor
Mentor

I don't have VBa installed therefore I can't test the code. but some things that you could try:

oSubDoc.Close

this function has an optional parameter: "SkipSave". (Optional input Boolean that specifies whether to skip the save. If SkipSave is set to True, it indicates that the changes to the document should not be saved and that the document should be closed silently. If SkipSave is set to False, it indicates that the normal save process should be followed.)

You have already saved the file before you close it. Therefore you can close without the extra save action while closing that possibly could go wrong. That would look like this.

oSubDoc.Close(True)

 

for the "save" action you use:

oDoc.Save

You could try to use the function "Save2(Optional SaveDependents As Boolean = True)" Saving dependent files could go wrong and I guess that you don't care if dependent files are saved (it's not necessary for creating thumbnails in the original part). Therefore you could skip that save action like this:

oDoc.Save2(False)

 I'm a bit surprised that you don't get the derived parts with:

For Each oSubDoc In oAsmDoc.AllReferencedDocuments
   ...
Next

 

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

Message 3 of 5

davis.j
Advocate
Advocate

Thanks @JelteDeJong 

 

I have implemented some of your ideas.

 

I have added some code from here:

https://forums.autodesk.com/t5/inventor-customization/ilogic-to-change-read-only-state-of-file-s/td-... 
This is so I can save the read only parts.

 

At this point I have to run the rule twice.

 

Is there any way to consolidate this rule to only have to run it once. I'm thinking large assemblies take some time and having to do the rule twice would be annoying 🙂. The first time I run the rule it changes all locked parts but not the parts that are in a checkout-able state that are read only. (3D model design vs released)

 

Current Rule:

Sub Main()
	
	strPath = System.IO.Directory.GetParent(ThisDoc.Document.FullFileName).FullName

	Dim dir As New System.IO.DirectoryInfo(strPath)
	For Each File As System.IO.FileInfo In dir.GetFiles("*", System.IO.SearchOption.AllDirectories)
	    
	    File.IsReadOnly = False
	Next
	
	Dim oSubDoc As Document
    Dim oAsmDoc As Document
    oAsmDoc = ThisApplication.ActiveDocument

	oColorScheme = ThisApplication.ActiveColorScheme.Name
	oBackGroundType = ThisApplication.ColorSchemes.BackgroundType

	ThisApplication.ColorSchemes.Item("Presentation").Activate

	ThisApplication.ColorSchemes.BackgroundType = _
	BackgroundTypeEnum.kOneColorBackgroundType 

	Dim a = iLogicVb.Automation
	a.RulesOnEventsEnabled = False
	
	If ThisDoc.Document.DocumentType <> kAssemblyDocumentObject Then
		MessageBox.Show("This rule must be run from an Assembly.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1)
	Exit Sub
	End If

    Call MakeNewThumbnail(oAsmDoc)

    For Each oSubDoc In oAsmDoc.AllReferencedDocuments
        If oSubDoc.IsModifiable Then
            oSubDoc = ThisApplication.Documents.Open(oSubDoc.FullFileName, True)
            Call MakeNewThumbnail(oSubDoc)
            oSubDoc.Close(True)
        End If
	Next

	a.RulesOnEventsEnabled = True
	
	ThisApplication.ColorSchemes.Item(oColorScheme).Activate 
	ThisApplication.ColorSchemes.BackgroundType = oBackGroundType

End Sub

Sub MakeNewThumbnail(oDoc As Document)
	
    On Error Resume Next
	
    With oDoc.ObjectVisibility
        .AllWorkFeatures = False
        .Sketches = False
        .Sketches3D = False
    End With
    
    oDoc.SetThumbnailSaveOption (kActiveComponentIsoViewOnSave)
    oDoc.Save
    
    On Error GoTo 0
    
End Sub

 

Might anyone else be able to test this with me?

 

Thanks,

0 Likes
Message 4 of 5

davis.j
Advocate
Advocate
Accepted solution

Looks like all I had to do was add:

oAsmDoc.Save

 

And I also added this:

Ignore Vault popup when opening/closing files with API? 

 

So far this rule is working and I will be testing it out for a while to see if they are any more quirks to work out:

Sub Main()
	
Dim VaultAddin As ApplicationAddIn = ThisApplication.ApplicationAddIns.ItemById("{48B682BC-42E6-4953-84C5-3D253B52E77B}")
	VaultAddin.Deactivate()
	
	strPath = System.IO.Directory.GetParent(ThisDoc.Document.FullFileName).FullName

	Dim dir As New System.IO.DirectoryInfo(strPath)
	For Each File As System.IO.FileInfo In dir.GetFiles("*", System.IO.SearchOption.AllDirectories)
	    
	    File.IsReadOnly = False
	Next
	
	Dim oSubDoc As Document
    Dim oAsmDoc As Document
    oAsmDoc = ThisApplication.ActiveDocument

	oColorScheme = ThisApplication.ActiveColorScheme.Name
	oBackGroundType = ThisApplication.ColorSchemes.BackgroundType

	ThisApplication.ColorSchemes.Item("Presentation").Activate

	ThisApplication.ColorSchemes.BackgroundType = _
	BackgroundTypeEnum.kOneColorBackgroundType 

	Dim a = iLogicVb.Automation
	a.RulesOnEventsEnabled = False
	
	If ThisDoc.Document.DocumentType <> kAssemblyDocumentObject Then
		MessageBox.Show("This rule must be run from an Assembly.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1)
	Exit Sub
	End If

    Call MakeNewThumbnail(oAsmDoc)

    For Each oSubDoc In oAsmDoc.AllReferencedDocuments
        If oSubDoc.IsModifiable Then
            oSubDoc = ThisApplication.Documents.Open(oSubDoc.FullFileName, True)
            Call MakeNewThumbnail(oSubDoc)
			oAsmDoc.Save
            oSubDoc.Close(True)
        End If
	Next

	a.RulesOnEventsEnabled = True
	
	ThisApplication.ColorSchemes.Item(oColorScheme).Activate 
	ThisApplication.ColorSchemes.BackgroundType = oBackGroundType
	
	VaultAddin.activate()

End Sub

Sub MakeNewThumbnail(oDoc As Document)
	
    On Error Resume Next
	
    With oDoc.ObjectVisibility
        .AllWorkFeatures = False
        .Sketches = False
        .Sketches3D = False
    End With
    
    oDoc.SetThumbnailSaveOption (kActiveComponentIsoViewOnSave)
    oDoc.Save
    
    On Error GoTo 0
    
End Sub

 

Setting to solved for now. 😃

Message 5 of 5

davis.j
Advocate
Advocate

I have been using these two rules lately with success. One is for Current Level only, the other is for a part only list that will go through all parts. I use then use BOMTools App export Excel sheets after the Thumbnails are set to a white BG.

 

Clear Thumbnails.png

Clear Thumbnails (First Level)

Sub Main()
	
Dim VaultAddin As ApplicationAddIn = ThisApplication.ApplicationAddIns.ItemById("{48B682BC-42E6-4953-84C5-3D253B52E77B}")
	VaultAddin.Deactivate()
	
	strPath = System.IO.Directory.GetParent(ThisDoc.Document.FullFileName).FullName

	Dim dir As New System.IO.DirectoryInfo(strPath)
	For Each File As System.IO.FileInfo In dir.GetFiles("*", System.IO.SearchOption.AllDirectories)
	    
	    File.IsReadOnly = False
	Next
	
	Dim oSubDoc As Document
    Dim oAsmDoc As Document
    oAsmDoc = ThisApplication.ActiveDocument

	oColorScheme = ThisApplication.ActiveColorScheme.Name
	oBackGroundType = ThisApplication.ColorSchemes.BackgroundType

	ThisApplication.ColorSchemes.Item("Presentation").Activate

	ThisApplication.ColorSchemes.BackgroundType = _
	BackgroundTypeEnum.kOneColorBackgroundType 

	Dim a = iLogicVb.Automation
	a.RulesOnEventsEnabled = False
	
	If ThisDoc.Document.DocumentType <> kAssemblyDocumentObject Then
		MessageBox.Show("This rule must be run from an Assembly.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1)
	Exit Sub
	End If

    Call MakeNewThumbnail(oAsmDoc)

    For Each oSubDoc In oAsmDoc.ReferencedDocuments
        If oSubDoc.IsModifiable Then
            oSubDoc = ThisApplication.Documents.Open(oSubDoc.FullFileName, True)
            Call MakeNewThumbnail(oSubDoc)
			oAsmDoc.Save
            oSubDoc.Close(True)
        End If
	Next
	
    If oAsmDoc.IsModifiable Then
        Call MakeNewThumbnail(oAsmDoc)
		oAsmDoc.Save
    End If

	a.RulesOnEventsEnabled = True
	
	ThisApplication.ColorSchemes.Item(oColorScheme).Activate 
	ThisApplication.ColorSchemes.BackgroundType = oBackGroundType
	
	VaultAddin.activate()

End Sub

Sub MakeNewThumbnail(oDoc As Document)
	
    On Error Resume Next
	
    With oDoc.ObjectVisibility
        .AllWorkFeatures = False
        .Sketches = False
        .Sketches3D = False
    End With
    
    oDoc.SetThumbnailSaveOption (kActiveComponentIsoViewOnSave)
    oDoc.Save
    
    On Error GoTo 0
    
End Sub

 

Clear Thumbnails (All Parts)

Sub Main()
	
Dim VaultAddin As ApplicationAddIn = ThisApplication.ApplicationAddIns.ItemById("{48B682BC-42E6-4953-84C5-3D253B52E77B}")
	VaultAddin.Deactivate()
	
	strPath = System.IO.Directory.GetParent(ThisDoc.Document.FullFileName).FullName

	Dim dir As New System.IO.DirectoryInfo(strPath)
	For Each File As System.IO.FileInfo In dir.GetFiles("*", System.IO.SearchOption.AllDirectories)
	    
	    File.IsReadOnly = False
	Next
	
	Dim oSubDoc As Document
    Dim oAsmDoc As Document
    oAsmDoc = ThisApplication.ActiveDocument

	oColorScheme = ThisApplication.ActiveColorScheme.Name
	oBackGroundType = ThisApplication.ColorSchemes.BackgroundType

	ThisApplication.ColorSchemes.Item("Presentation").Activate

	ThisApplication.ColorSchemes.BackgroundType = _
	BackgroundTypeEnum.kOneColorBackgroundType 

	Dim a = iLogicVb.Automation
	a.RulesOnEventsEnabled = False
	
	If ThisDoc.Document.DocumentType <> kAssemblyDocumentObject Then
		MessageBox.Show("This rule must be run from an Assembly.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1)
	Exit Sub
	End If

    Call MakeNewThumbnail(oAsmDoc)

    For Each oSubDoc In oAsmDoc.AllReferencedDocuments
        If oSubDoc.IsModifiable Then
            oSubDoc = ThisApplication.Documents.Open(oSubDoc.FullFileName, True)
            Call MakeNewThumbnail(oSubDoc)
			oAsmDoc.Save
            oSubDoc.Close(True)
        End If
	Next

	a.RulesOnEventsEnabled = True
	
	ThisApplication.ColorSchemes.Item(oColorScheme).Activate 
	ThisApplication.ColorSchemes.BackgroundType = oBackGroundType
	
	VaultAddin.activate()

End Sub

Sub MakeNewThumbnail(oDoc As Document)
	
    On Error Resume Next
	
    With oDoc.ObjectVisibility
        .AllWorkFeatures = False
        .Sketches = False
        .Sketches3D = False
    End With
    
    oDoc.SetThumbnailSaveOption (kActiveComponentIsoViewOnSave)
    oDoc.Save
    
    On Error GoTo 0
    
End Sub

 

0 Likes