I am using iLogic to create an HTML page with a table listing certain parts from an assembly BOM.
I would like to include a column for a thumbnail image of the part. Here is some of the code (please note, large chunks of code is missing, but just to give a better idea of what I'm building on)
oWrite = System.IO.File.CreateText(oHTMLDoc) ' Create the HTML file
' Lines to set up HTML table, fonts etc.....
For Each oRow As BOMRow In oBOMRows
oRowCompDef = oRow.ComponentDefinitions.Item(1) fullfilename = oRowCompDef.Document.FullFileName partnumber = oRowCompDef.Document.PropertySets("Design Tracking Properties").Item("Part Number").Value category = oRowCompDef.Document.PropertySets("Inventor Document Summary Information").Item("Category").Value comments = oRowCompDef.Document.PropertySets("Inventor Summary Information").Item("Comments").Value ' Add thumbnail image here oWrite.WriteLine("<td Class=""tg-yw4l"">" & "<a href=""" & fullfilename & """> " & partnumber & "</a>" & "</td>") oWrite.WriteLine("<td Class=""tg-yw4l"">" & category & "</td>") oWrite.WriteLine("<td Class=""tg-yw4l"">" & comments & "</td>") Next
What is the best way to access the thumbnail image for me to use it on my HTML document?
Solved! Go to Solution.
Solved by YuhanZhang. Go to Solution.
I am able to get the thumbnail iProperty as IPictureDisp but I need a way to convert & save this as an image for me to use on my page. Can anyone provide some guidance how to achieve this?
You could create a image on saving the document, and use that..
I mean export ie *.bmp
Regards,
Arthur Knoors
Autodesk Affiliations:
Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!
! For administrative reasons, please mark a "Solution as solved" when the issue is solved !
Public Sub SaveAsBmp() ' Get the active view. Dim oView As View Set oView = ThisApplication.ActiveView 'Create a new NameValueMap Object Dim oOptions As NameValueMap Set oOptions = ThisApplication.TransientObjects.CreateNameValueMap '.TransientObjects.CreateNameValueMap oOptions.Value("TransparentBackground") = True 'True oOptions.Value("OnlyShowActiveComponentsForIn-PlaceEditing") = True oOptions.Value("OnlyShowActiveComponentsForInPlaceEditing") = True oView.Fit Call oView.SaveAsBitmapWithOptions("C:\Temp\TestB2.bmp", 0, 0, oOptions) End Sub
Regards,
Arthur Knoors
Autodesk Affiliations:
Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!
! For administrative reasons, please mark a "Solution as solved" when the issue is solved !
As I am looping through the 'parts only' bom rows I won't be using ThisApplication.ActiveView.
Do you know how I could access an image from each BOMRow item?
If you just want to save the thumbnail(IPictureDisp) of a document via API you can refer to below posts:
http://modthemachine.typepad.com/my_weblog/2010/06/accessing-thumbnail-images.html
Hope they help.
@YuhanZhang Yes that is what I'm trying to achieve. I'm struggling to add the correct references for any of the codes in the links you sent me to work in iLogic environment.
It fails on either SavePicture or Compatibility.VB6.IPictureDispToImage because of missing reference to my project.
Could you advise on what I would need to add to get either of these methods to work?
AddReference "blah blah"
or
Imports blah blah
To add the reference to Compatibility.VB6 you need to add it as below in your .Net project(create a VB.net project to try it):
Or use Browser... to reference it from GAC using below path:
C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.VisualBasic.Compatibility\v4.0_10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualBasic.Compatibility.dll
And in iLogic Rule editor I think you can just add below line to the Header Statements area:
Imports Microsoft.VisualBasic.Compatibility.VB6
Please let me if any more problems.
@YuhanZhang thank you for your help. I'm still getting an error unfortunately.
My full code is:
AddReference "stdole.dll"
AddReference "Microsoft.VisualBasic.Compatibility.dll"
Imports Microsoft.VisualBasic.Compatibility.VB6
Sub Main SaveThumbnail()
' Get the active document.
Dim doc As Document
doc = ThisApplication.ActiveDocument
' Get the thumbnail from the document.
Dim thumb As Inventor.IPictureDisp
thumb = doc.Thumbnail
' Create the filename for the bmp file so it is the same
' as the document name but with a "bmp" extension.
Dim filename As String
filename = Left$(doc.FullFileName, Len(doc.FullFileName) - 3) & "bmp"
' Save the thumbnail.
'Call stdole.SavePicture(thumb, filename)
img = Compatibility.VB6.IPictureDispToImage(thumbnail)
End Sub
This is the error I get is with Compatibility.VB6.IPictureDispToImage:
Reference required to assembly 'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
Otherwise if I try using SavePicture method I get this errror:
'SavePicture' is not declared. It may be inaccessible due to its protection level.
Do you know how I can fix to get either of these to work?
Here is the updated iLogic code, please check if it works there:
AddReference "system.drawing.dll" AddReference "stdole.dll" AddReference "Microsoft.VisualBasic.Compatibility.dll" Imports Microsoft.VisualBasic.Compatibility.VB6 Sub Main() ' Get the active document. Dim doc As Document doc = ThisApplication.ActiveDocument ' Get the thumbnail from the document. Dim thumb As Inventor.IPictureDisp thumb = doc.Thumbnail ' Create the filename for the bmp file so it is the same ' as the document name but with a "bmp" extension. Dim filename As String filename = Left$(doc.FullFileName, Len(doc.FullFileName) - 3) & "bmp" Dim img As Drawing.Image img = Compatibility.VB6.IPictureDispToImage(thumb) Call img.Save ("C:\temp\custom.bmp") End Sub
Can't find what you're looking for? Ask the community or share your knowledge.