Can VB.NET display part thumbnails in a Form?

Can VB.NET display part thumbnails in a Form?

JBerns
Advisor Advisor
2,573 Views
13 Replies
Message 1 of 14

Can VB.NET display part thumbnails in a Form?

JBerns
Advisor
Advisor

Community,

 

I have mocked up a sample form that I would like to develop for our designers.

Form Mockup 01.png

 

Background:

We have tubes and occasional plates that get "tabs" added to the ends. See image. This adds to the original B_L or G_L value of the custom iProperty from Content Center. This requires a new custom iProperty to be saved for the part.

 

I made a form and code that a designer can use when the individual parts are open. This works well, but is slow to process many parts one at a time.

Structural Steel Form 01.png

 

Goal:

I would like to expand on this with a form to display all the parts in the active assembly. Not concerned with subassemblies at this time, but that would be beneficial.


This new form, as shown above, would allow the designer to select a part, see a preview, and then select the Process and Length custom iProperties.

 

Questions:

Is it possible to display the part's thumbnail in the form when the part is selected from a DataGrid in a VB.NET form?

 

Is it possible to emulate Excel behavior with VB.NET where you could drag a cell's lower-right corner to fill-copy?

Cell Copy 01.png

 

This would make it easier to set the Process value for similar parts rather than having to select each part individually in the grid.

 

Research so far:

I found code to save a thumbnail to disk, but not how to display a thumbnail. Perhaps once the part is selected in the form, the thumbnail is saved to a temp file, and then that is retrieved for display in the form.

 

I have not found any code to emulate the Excel cell copy behavior for VB.NET, DataGrids, etc.

 

 

Thank you for your time and attention. I look forward to the responses.

 

 

Regards,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Accepted solutions (1)
2,574 Views
13 Replies
Replies (13)
Message 2 of 14

JhoelForshav
Mentor
Mentor
0 Likes
Message 3 of 14

JBerns
Advisor
Advisor

Thanks, @JhoelForshav .

 

I saw that solution dated back to 2010, but was hoping there may be a more current solution.

 

I installed the 2019 SDK from here:

https://forums.autodesk.com/t5/inventor-customization/inventor-2019-sdk-developertools-install-error... 

 

The third solution in Brian's blog looks promising, however, the article mentions using the Register.BAT file to register the component.

 

When I run either the BAT file in the 32-bit or 64-bit folder, this error appears:

2020-03-24_17-09-04.png

 

Any assistance would be appreciated. Especially, if I need to recompile from the source code.

 

 

Regards,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 4 of 14

JhoelForshav
Mentor
Mentor

Hi @JBerns 

 

I was thinking something like this as an example to view the thumbnail in a form.

For some reason i cannot get the apprentice to work so I cant test it, but maybe it'll work for you.

The form has one picturebox and one button.

You should have an assembly open in inventor. When you klick the button in the form you can select a part occurrence in the assembly and hopefully the picturebox should show its thumbnail.

 

You'll need to add stdole as a reference in your project.

Imports Inventor

Public Class Form1
    Dim oApprentice As ApprenticeServerComponent = New ApprenticeServerComponent
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim invApp As Inventor.Application
        Dim oAsm As AssemblyDocument
        Try
            invApp = GetObject(, "Inventor.Application")
            oAsm = invApp.ActiveDocument
        Catch ex As Exception
            Exit Sub
        End Try
        Dim oOcc As ComponentOccurrence = invApp.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select part occurrence")
        Dim oDoc As PartDocument = oOcc.Definition.Document
        Dim oApprenticeDoc As ApprenticeServerDocument = oApprentice.Open(oDoc.FullDocumentName)


        Dim oThumbnail As stdole.IPictureDisp = oApprenticeDoc.Thumbnail
        Dim img As Image = IPictureDispConverter.PictureDispToImage(oThumbnail)
        PictureBox1.Image = img
    End Sub
End Class
Public NotInheritable Class IPictureDispConverter : Inherits AxHost

    Private Sub New()

        MyBase.New("")

    End Sub

    Public Shared Function PictureDispToImage(pictureDisp As IPictureDisp) As Image

        Try

            Return GetPictureFromIPicture(pictureDisp)

        Catch

            Return Nothing

        End Try

    End Function

End Class

 

0 Likes
Message 5 of 14

JhoelForshav
Mentor
Mentor

Hi @JBerns 

I got it to work... For some reason apprentice started working when i changed the applications target framework from ".NET Framework 4.7.2" to ".NET Framework 3.5" and then back again.

ThumbnailPreview.PNG

 

0 Likes
Message 6 of 14

JBerns
Advisor
Advisor

@JhoelForshav,

 

Thanks for the code. I am not very familiar with developing programs outside of Inventor.

My experience is mostly VBA/iLogic.

 

I will look over the code and try to get this to work with Visual Studio. I have 2017 and 2019. Any recommendations?

what Visual Studio project type should I create? Will I need to add other references besides the stdole.dll?

 

 

Regards,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 7 of 14

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @JBerns

I use visual studio 2019 mostly. Works fine for inventor 2020 and the addins i create etc.

 

You'll also have to reference the Autodesk.Inventor.Interop.dll

 

See attached projcet. It's a windows forms app 🙂

0 Likes
Message 8 of 14

JBerns
Advisor
Advisor

@JhoelForshav,

 

Thank you for the VS sample project and reference file required. Success.

2020-03-26_8-19-03.png

I'll need to learn more how to use external apps to interrogate and write to assemblies, references, and components.

Thanks again for the example.

 

Regards,

Jerry

 

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 9 of 14

JBerns
Advisor
Advisor

@JhoelForshav,

 

Do you think you could access these thumbnails from an iLogic internal or external rule? Or will an external app be required?

 

Regards,

Jerry 

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 10 of 14

JhoelForshav
Mentor
Mentor

Hi @JBerns ,

Happy to help! 🙂

 

You can absolutely access the thumbnail from ilogic. In fact, it's easier since you dont have to use apprentice to do this from within Inventor. The problem will be displaying the picture. Ilogic forms are very limited in their functionality.

 

I think you're better off building this in visual studio as an addin or an external application.

0 Likes
Message 11 of 14

JBerns
Advisor
Advisor

@JhoelForshav 

 

To date, I have built custom forms with iLogic rules. These rules can access SQL databases and use DataGrids and DataGridViews. I did not use Visual Studio, although it may have been easier to develop using that tool. 😉

 

I was hoping thumbnails would be easy. I will try to adapt your code to run as an internal rule. I will report my success. Thanks again.

 

 

Regards,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 12 of 14

JhoelForshav
Mentor
Mentor

@JBerns 

Of course it can be done like you say!

I apologize for underestimating you! 🙂

I thought you wanted to use ilogic forms. If you reference system.windows.forms you can  do it in ilogic as well.

Using visual studio you can build the form with the form builder and copy the class to ilogic. Or make dll from it and reference that from ilogic.

If I were you I'd make this an addin though.

 

Have a good weekend and good luck with your project!

0 Likes
Message 13 of 14

JBerns
Advisor
Advisor

No worries, @JhoelForshav. I'm certainly not an expert at VB, but did not want to be limited by the default iLogic forms.

 

Now that I can programmatically create my own forms with iLogic, I have been using the iLogic editor environment mostly. It is FAR more difficult to design, but I thought the greater challenge would be to connect an external app to the Inventor model.

 

Maybe this is a good project to get to that skill level.

 

 

Regards,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 14 of 14

niranjan934
Contributor
Contributor

Dear All,

 

   I Choose a String of Inventor Document from data grid view in vb.net. With the help of the string path I opened a document visible as false then Iam extracting the image from document and Saving another Location but it won't work. Please Suggest a code how to extract a image without opening a document or opening with false using vb.net

  

0 Likes