A generic error occurred in GDI+

A generic error occurred in GDI+

Maxim-CADman77
Advisor Advisor
375 Views
2 Replies
Message 1 of 3

A generic error occurred in GDI+

Maxim-CADman77
Advisor
Advisor

(this one is consequent to this)

 

Dear @MjDeck 

Could you please study the reason for occasional "A generic error occurred in GDI+" for the model attached with the code like:

 

 

Option Explicit On

	AddReference "Stdole"
	AddReference "System.Drawing"

	Imports stdole
	Imports System.Drawing

Class ThisRule
	Sub Main

		Dim doc As PartDocument = ThisDoc.Document
		Dim cmpDef As ComponentDefinition = doc.ComponentDefinition

		Dim thumb As stdole.IPictureDisp = doc.Thumbnail

		Dim axHC As New AxHostConverter
	Logger.Info("axHC: " & If(axHC Is Nothing, "-", "+"))
		Dim image As System.Drawing.Image = axHC.GetImageFromIPictureDisp(thumb) ' A generic error occurred in GDI+

	End Sub
End Class


Class AxHostConverter
	Inherits System.Windows.Forms.AxHost

	Public Sub New()
		MyBase.New("{63109182-966B-4e3c-A8B2-8BC4A88D221C}")
		' MyBase.New((New Guid).ToString)
	End Sub

	Public Function GetImageFromIPictureDisp(ByVal IPDisp As stdole.IPictureDisp) As System.Drawing.Image
		Return MyBase.GetPictureFromIPicture(IPDisp) ' A generic error occurred in GDI+
	End Function
End Class

 

 

The code of Class AxHostConverter origins from this post this post of @WCrihfield 

 

The issue can be occasionally (not on each code run) reproduced on Inventor 2024.3 and earlier.

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Accepted solutions (2)
376 Views
2 Replies
Replies (2)
Message 2 of 3

Michael.Navara
Advisor
Advisor
Accepted solution
0 Likes
Message 3 of 3

Michael.Navara
Advisor
Advisor
Accepted solution

Fixed code should look like this

 

Option Explicit On
AddReference "Stdole"
AddReference "System.Drawing"
Imports stdole
Imports System.Drawing



Class ThisRule
	Sub Main
		'For i = 0 To 100 ' FOR TEST PURPOSES ONLY
			Dim doc As PartDocument = ThisDoc.Document
			Dim cmpDef As ComponentDefinition = doc.ComponentDefinition

			Dim thumb As stdole.IPictureDisp
			Do
				thumb = doc.Thumbnail
			Loop While thumb.Handle < 0

			Dim axHC As New AxHostConverter
			Logger.Info("axHC: " & If (axHC Is Nothing, "-", "+"))
			Dim image As System.Drawing.Image = axHC.GetImageFromIPictureDisp(thumb) ' NO MORE A generic error occurred in GDI+
		'Next
	End Sub
End Class


Class AxHostConverter
	Inherits System.Windows.Forms.AxHost

	Public Sub New()
		MyBase.New("{63109182-966B-4e3c-A8B2-8BC4A88D221C}")
		' MyBase.New((New Guid).ToString)
	End Sub

	Public Function GetImageFromIPictureDisp(ByVal IPDisp As stdole.IPictureDisp) As System.Drawing.Image
		Return MyBase.GetPictureFromIPicture(IPDisp) ' A generic error occurred in GDI+
	End Function
End Class

 

0 Likes