Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Change background , save and change background to original using VB. NET

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
Joos_T
596 Views, 5 Replies

Change background , save and change background to original using VB. NET

Dear all,

 

I want to save my thumbnails with a different background then my original setting of my inventor file. 

Theirfore I first want to change the background then save the file and then set the setting back to the original inventor setting.

 

I've already have tried to write a little in Visual Studio, see attachment, but I keep getting an error.

 

It would be great if anyone could help me.

 

 

	Public Sub BackgroundSwapper(ByVal InventorApplication As Inventor.Application)
		Dim oDoc As Inventor.Document = InventorApplication.ActiveEditDocument
		Dim StandardFile As String = ("C:\TEMP\InventorBackGroundSettings.txt")
		Dim CurrentColorScheme As String

		On Error Resume Next
		CurrentColorScheme = InventorApplication.ActiveColorScheme.Name

		Dim DefaultSetting As String

		If System.IO.File.Exists(StandardFile) Then
			DefaultSetting = com_BackgroundAssm.Text
		Else
			DefaultSetting = com_BackgroundAssm.Text
		End If

		If CurrentColorScheme = "Presentation" Then
			InventorApplication.ColorSchemes(DefaultSetting).Activate()
			InventorApplication.ColorSchemes.BackgroundType = 52737 '= color gradient. 
		Else
			InventorApplication.ColorSchemes("Presentation").Activate()
			InventorApplication.ColorSchemes.BackgroundType = 52737 '= one color. 
		End If

		oDoc.Save()


	End Sub
Labels (5)
5 REPLIES 5
Message 2 of 6
Dev_rim
in reply to: Joos_T

Hi there,

As far as I know ActiveEditDocument, is using for reaching the assembly documents on the edit mode. So first thing you should use ActiveDocument instead of ActiveEditDocument.

 

I can not understand why you are using 2 If statements with the same result on true and false.

In the end the final code you need I think :

Public Sub BackgroundSwapper(ByVal InventorApplication As Inventor.Application)
		Dim oDoc As Inventor.Document = InventorApplication.ActiveDocument
		Dim StandardFile As String = ("C:\TEMP\InventorBackGroundSettings.txt")
		Dim CurrentColorScheme As String
		On Error Resume Next
		CurrentColorScheme = InventorApplication.ActiveColorScheme.Name
		Dim DefaultSetting As String = com_BackgroundAssm.Text
		InventorApplication.ColorSchemes("Presentation").Activate()
		InventorApplication.ColorSchemes.BackgroundType = 52737 '= one color. 
		oDoc.Save()

        InventorApplication.ColorSchemes(CurrentColorScheme).Activate()


	End Sub

 

If my answer is solved your problem, please mark it as Solution

Freundliche Grüße / Kind Regards
Message 3 of 6
Joos_T
in reply to: Dev_rim

Hi,

 

Thanks for your reply. It still has the same error as before. 

I think your right about the double statement. So  I will implement that.

 

Message 4 of 6
Dev_rim
in reply to: Joos_T

Oh I just check the image you send.

You have to call the function with Application object.

You are calling it right now like this

devrimyoyen_0-1669625616576.png

But you have to put some Application object inside of the parenthesis.

like:

BackgroundSwapper(Invapp)

or the variable that contains the Inventor.Application object.

 

Thats your issue

 

If my answer is solved your problem, please mark it as Solution

Freundliche Grüße / Kind Regards
Message 5 of 6
lah29-bertrand
in reply to: Joos_T

for myself, I use this little code 

In application option: one color set to white

and I use background file 

 

If ThisApplication.ColorSchemes.BackgroundType = kOneColorBackgroundType Then
ThisApplication.ColorSchemes.BackgroundType = kImageBackgroundType
Else If ThisApplication.ColorSchemes.BackgroundType = kImageBackgroundType Then
	ThisApplication.ColorSchemes.BackgroundType = kOneColorBackgroundType
End If

 

Message 6 of 6
Joos_T
in reply to: Dev_rim

Hi,
The code does work. I only had to change "Presentation" to a variable (com_backgroundassm)
Now it will change to the variable you choose in the combobox.

thanks a lot!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report