iLogic Change Background Colour

iLogic Change Background Colour

TA.Fehr
Advocate Advocate
3,865 Views
11 Replies
Message 1 of 12

iLogic Change Background Colour

TA.Fehr
Advocate
Advocate

I've written two iLogic codes that change the bacground colour to white before save (so the thumbnail shows the part/assembly cleanly), and then after save to revert to the original colours. The code exists in each part and is triggered to run the same way for each part.

 

The code works perfectly on single parts, and on assemblies where all the sub-components are open within Inventor.

 

However, when I make changes and save at the assembly level (while the sub-components are not open in Inventor) the code stops running after the first rule. Manually running the second rule reverts the changes, but the sub-components do not update their respective thumbnails as per the first example.

 

Because the rules are triggered by the save command I had to split the code into pre and post save because the function can't call a save without going into an infinite loop. The code saves the bacground color to the part location to retrieve after thet save, and then deletes the txt file. I considered making this an external rule, but this would cause issues when we send any parts/assemblies to our clients.

 

The first rule triggered to run before the save is:

 

SyntaxEditor Code Snippet

fs = CreateObject("Scripting.FileSystemObject")

OldColorFile = fs.CreateTextFile(ThisDoc.Path & "\" & ThisDoc.FileName(False) & "OldColorName.txt", True)
Dim OldColorSchemeName As String
OldColorSchemeName = ThisApplication.ActiveColorScheme.Name
OldColorFile.WriteLine (OldColorSchemeName)
OldColorFile.Close

OldBackgroundFile = fs.CreateTextFile(ThisDoc.Path & "\" & ThisDoc.FileName(False) & "OldBackground.txt", True)
Dim OldBackground As BackgroundTypeEnum
OldBackground = ThisApplication.ColorSchemes.BackgroundType
OldBackgroundFile.WriteLine (OldBackground)
OldBackgroundFile.Close

ThisApplication.ColorSchemes.Item("Presentation").Activate
ThisApplication.ColorSchemes.BackgroundType = 52737

 The second rule, which is triggered to run after the save is:

 

SyntaxEditor Code Snippet

Imports System.IO
Dim oRead As New StreamReader(ThisDoc.Path & "\" & ThisDoc.FileName(False) & "OldBackground.txt")
Dim aLine As String
aLine = oRead.readline()
oRead.Close
Kill (ThisDoc.Path & "\" & ThisDoc.FileName(False) & "OldBackground.txt")

Dim Read As New Streamreader(ThisDoc.Path & "\" & ThisDoc.FileName(False) & "OldColorName.txt")
Dim bLine As String
bLine = Read.readline()
Read.Close
Kill (ThisDoc.Path & "\" & ThisDoc.FileName(False) & "OldColorName.txt")

ThisApplication.ColorSchemes.Item(bline).Activate
ThisApplication.ColorSchemes.BackgroundType = aline
ThisApplication.GeneralOptions.Show3DIndicator = True

 

3,866 Views
11 Replies
Replies (11)
Message 2 of 12

hossaiy
Autodesk
Autodesk

Hi,

 

am not sure if you've already solved your problem, but i thought i'd share the following with you anyway.

 

I think this sort of thing is more suited for a plug-in. Here is a video of one that i put together (it basically shows an assembly file already opened, and when i click the button "Save-all" in my plug-in, it opens all the refrenced part files and re-saves them such that the thumbnails now have a white back-ground):

 

 

 
 
Here is a link for information on creating plug-ins, but feel free to ask too.
 
Thanks


Yacoub Hossain
Message 3 of 12

Anonymous
Not applicable

Hi, Sorry for the old post bump but have spent hours searching for a simple way to do exactly what's in your video above. Resave all the files with the click of a button with a white background. So when they're exported to a word parts list with thumbnails (using another plugin) and printed in Black and White they show up looking professional.

Then reset the current view preference to the user preference colour scheme background.

 

There was an All Thumbs plugin with similar functionality but all the links are dead and I am unable to download.

http://forums.autodesk.com/t5/inventor-forum/white-background-in-thumbnails-regardless-of-user-backg...

 

Are you wiling to share your plugin/code that makes this happen?

 

Thanks, Mitchell

0 Likes
Message 4 of 12

hossaiy
Autodesk
Autodesk

Hi Mitchell,

 

amazingly i did still have it lying around on my machine, and i briefly tried it out and it still seemed to be working too. I am uploading it for you, but i really knocked this up on a rainy sunday afternoon, so should only be used as a rough guide.

Anyway, hope it is useful to you.

 

Thanks

Yacoub



Yacoub Hossain
Message 5 of 12

Anonymous
Not applicable

Awesome, Thankyou so much. was planning on teaching myself plugins soon anyway.

 

I should just be able to follow the "My First Plugin" documentation and then compile your code?

0 Likes
Message 6 of 12

hossaiy
Autodesk
Autodesk

No problem Mitch. Yes I would go through the "My First Plugin" documentation and then compile my code and step into the logic to see how it is working. I did briefly check before uploading it and everything was still compiling and working for me.

Thanks

Yacoub



Yacoub Hossain
Message 7 of 12

daniel.streinz
Community Visitor
Community Visitor

Hi,

 

it tried this in Inventor 2018, but i get this failure:

 

Fehler in Regel: Test4 in Dokument: Bauteil1.ipt
Unbekannter Fehler (Ausnahme von HRESULT: 0x80004005 (E_FAIL))

 

System.Runtime.InteropServices.COMException (0x80004005): Unbekannter Fehler (Ausnahme von HRESULT: 0x80004005 (E_FAIL))
   bei System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
   bei Inventor.ColorSchemes.set_BackgroundType(BackgroundTypeEnum )
   bei Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
   bei iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

I think there is a problem with following line:

SyntaxEditor Code Snippet

ThisApplication.ColorSchemes.BackgroundType = 52737

 

Has someone else the same problem. I can´t get it run.

 

Thanks

Daniel

 

0 Likes
Message 8 of 12

Anonymous
Not applicable

Maybe can be of use for someone so I'll just leave this iLogic snippet here. 

Dim oView As View = ThisApplication.ActiveView
 Dim oCamera As Inventor.Camera
    oCamera = oView.Camera

Dim iCurrentBakground = ThisApplication.ColorSchemes.BackgroundType.GetHashCode()


Dim oCurrentColorSceme = ThisApplication.ActiveColorScheme
''MsgBox(oCurrentColorSceme.)

Dim sCurrentScheme = ThisApplication.ActiveColorScheme '''Get the current scheme
'MsgBox(sCurrentScheme.Name) '''Show the current scheme name
If sCurrentScheme.Name <> "Presentation" Then
	ThisApplication.ColorSchemes.Item("Presentation").Activate 
Else 
	'ThisApplication.ColorSchemes.Item("PreferedScheme").Activate '''' Your prefered scheme here 
End If

If ThisApplication.ColorSchemes.BackgroundType <> 52737 And sCurrentScheme.Name = "Presentation" Then
'	MsgBox(iCurrentBakground)
	ThisApplication.ColorSchemes.BackgroundType = 52737
	oCamera.Perspective = True
	oCamera.ApplyWithoutTransition
	oView.DisplayMode = DisplayModeEnum.kShadedRendering
	oView.Update
Else
'	MsgBox("wait")
	ThisApplication.ColorSchemes.BackgroundType = 52739
	oCamera.Perspective = False
    oCamera.ApplyWithoutTransition
	oView.DisplayMode = DisplayModeEnum.kShadedWithEdgesRendering
	oView.Update
End If


ThisApplication.ActiveView.Update()
0 Likes
Message 9 of 12

b.mccarthy
Collaborator
Collaborator

Nice code. I have been looking for a list of the Backgroundtype" codes, but have been unsuccessful. Can anyone point me in the right direction?

 

Thank you.

0 Likes
Message 10 of 12

WCrihfield
Mentor
Mentor

Here is a link to Inventor's online help page for the Enum behind that setting.

BackgroundTypeEnum Enumerator 

It may even be easier to follow later if you specify it using  = BackgroundTypeEnum.kOneColorBackgroundType instead of = 52737.  That's what I usually do when working with Enum's, just so others (and myself) can more easily read through it a year from now and fully understand it better.

 

If this helped you, please click (LIKE or KUDOS) 👍.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 11 of 12

b.mccarthy
Collaborator
Collaborator

Thank you!

0 Likes
Message 12 of 12

Maxim-CADman77
Advisor
Advisor

@WCrihfield 

Apart from this I'd rather recommend replace line

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

with

ThisApplication.ColorSchemes(7).Activate

That would make iLogic-workaround usable for any Inventor localization (not only English).

Please vote for Inventor-Idea Text Search within Option Names