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: 

Inventor AddIn using WPF

22 REPLIES 22
Reply
Message 1 of 23
Anonymous
3482 Views, 22 Replies

Inventor AddIn using WPF

Just wondering if anyone has tried creating an Inventor addin that uses WPF (instead of WinForms). We are trying it with Inventor 2010 and are running into problems. If anyone has tried it, what kind of success have you had? Thanks!

-Tom
22 REPLIES 22
Message 2 of 23
Mike.Wohletz
in reply to: Anonymous

tried it, I don't know that it wont work because I just plain got frustrated with it.

All I can ever get out of it is errors about running managed code and I gave up.
Message 3 of 23
DavinciCad
in reply to: Anonymous

it works if encapsulate within a winform...  using ElementHost

 

look better than winform, but adds an extra layer to manage in your interface.

 

cheers

 

Pat@blackbox-orange.com

Message 4 of 23
Boorda
in reply to: Anonymous

I know this is an old post but yes you can create add-ins using 100% WPF.


I have several WPF Class Library .Net 4.5 add-ins that work with Inventor 2012+.

You do not have to encapsulate within a winform.


Automation is key!
Message 5 of 23
DavinciCad
in reply to: Boorda

Hello



Thank you for your reply.



Are you using the WPF container in winforms?





Patrik Chartrand

Founder & CTO

BlackBox-Orange

www.blackbox-orange.com



Member of the mensa society

www.mensa.org



CONFIDENTIAL COMMUNICATION This email and any attachments thereto may
contain private and confidential material for the sole use of the intended
recipient. Any review, copying, or distribution of this email (or any
attachments thereto) by others is strictly prohibited. If you are not the
intended recipient, please contact the sender immediately and permanently
delete the original and any copies of this email and any attachments
thereto.



COMMUNICATION CONFIDENTIELLE Ce courriel, ainsi que tous les fichiers qui y
sont attach?s, peuvent contenir des informations priv?es et confidentielles
strictement r?serv?es ? l'usage du destinataire l?gitime. Toute lecture,
visionnement, copie ou distribution de ce courriel (ainsi que des fichiers
qui y sont attach?s) par des tiers est strictement interdite. Si vous n'?tes
pas le destinataire l?gitime, svp en aviser l'envoyeur imm?diatement et
effacer de fa?on permanente l'original et toute copie de ce courriel ainsi
que des fichiers qui y sont attach?s.
Message 6 of 23
Boorda
in reply to: DavinciCad

No, 100% WPF using the registry free add-in method. 

See images below to see how I have my VS project setup.

 


Automation is key!
Tags (3)
Message 7 of 23
RANJANSUPERMAN
in reply to: Boorda

Hi Boorda,

 

Could you please share the source code with us ?

 

Thanks

RJN

Message 8 of 23
Boorda
in reply to: RANJANSUPERMAN

What are you looking for specifically in a code example? How to set up registry free add-in or how to create a WPF Class library?

-Addam


Automation is key!
Message 9 of 23
Rab_i
in reply to: Boorda

How to create a WPF Class library? Boorda - The image you posted shows it but Visual Studio 2013 doesn't have that option. Can you please elaborate on that process how to setup a WPF Class Library?

Message 10 of 23
AlexFielder
in reply to: Boorda

Hi @Boorda, I know it's been a long time since you posted this reply but I would love to see what you have created in regards to the WPF implementation.

 

I have been attempting to get this working recently and the best I can manage is a new dockable window that contains a black box.

 

Thanks,

 

Alex.

Message 11 of 23
riccardo
in reply to: AlexFielder

message deleted. The answer was not for this thread.


Sorry

Message 12 of 23
AlexFielder
in reply to: riccardo

that's no problem @riccardo; your reply in the other thread might be able to help me with the "no tab key" issue I am having with another addin...

 

Do you have your solution hosted anywhere like Github that I could take a look at?

Message 13 of 23
Boorda
in reply to: Rab_i

@Rab_i I'm really sorry, I didn't see you post 9 months ago. You may have already figured it out by now, but in case you didn't here's how to create a WPF Class library....

 

  1. Create a new project as a WPF Application
  2.  Go to your project properties and change the Application Type to WPF Class Library
  3. You'll need to delete the Application.xaml or you will get build errors.

 

Your project should now be a buildable WPF Class Library.

 

Creating A WPF Class Library.PNG


Automation is key!
Message 14 of 23
Boorda
in reply to: AlexFielder

@AlexFielder, what are you having issues with exactly? Are you trying to get a button to show up in the ribbon somewhere?

 

If so, I have a few base classes that I have written that can setup  TABs, PANELs, and  Control Definitions (Buttons) just by supplying a few parameters.

I try to practice DRY programming, in other words Don't Repeat Yourself. So i create base classes out of code that becomes repetitive.

 

Since there are still questions about WPF Add-ins, in a few days I will post an Inventor WFP Add-in Project template with some setup instructions.

 

 

-Addam


Automation is key!
Message 15 of 23
AlexFielder
in reply to: Anonymous

Hi Addam,

The issue I was having was in my attempts at getting a WPF form to display inside of a dockablewindow - the best I could manage was a black screen of nothing. :s

I have previously gotten a WPF window to display as a regular winform would but there's something about the dockablewindow.addchild() method that I just can't fathom for them.

I'm a huge fan of the Don't Repeat Yourself approach and will use the DRY acronym moving forwards, so thanks for sharing that 🙂

FWIW: I have a repository here that I started last week (with a customer of Graitec) which contains a DRY-centric class to get or set iProperty values:

https://github.com/AlexFielder/MyFirstInventorAddin

Thanks,

Alex
Message 16 of 23
Boorda
in reply to: AlexFielder

Hmmm, I haven't really messed with dockable windows yet in WPF. I will play around with them and let you know if I can manage to get something working. In the meantime, instead of using a WPF Window in the dockable window, maybe try to just display a WPF User Control. Not sure if that will work, but it's worth trying.

-Addam


Automation is key!
Message 17 of 23
AlexFielder
in reply to: Boorda

There's this article which details doing just that (WPF control inside a Winform):

 

http://adndevblog.typepad.com/manufacturing/2012/06/embedding-a-wpf-user-control-in-a-dockablewindow...

 

And here's an article by @adam.nagy where he uses WPF inside an Inventor Add-in (albeit not in a dockable window):

 

http://adndevblog.typepad.com/manufacturing/2015/11/wpf-window-inside-an-inventor-add-in.html

 

I haven't (yet) tried the first approach although I suppose there's no reason why a wpf Window couldn't be set to fill whatever winForm it was assigned to..?

 

 

Message 18 of 23
Boorda
in reply to: Boorda

I have been super busy the last week, just wanted to let everyone know I haven't forgotten about posting the WPF template.

I will post it as soon as I can get around to it.

 

-Addam


Automation is key!
Message 19 of 23
Boorda
in reply to: AlexFielder

@AlexFielder Ok, so on the subject of dockable windows here is what I did.

 

I wasn't able to get a WPF Window to work so I just created a blank System.Windows.Forms.Form then dropped an ElementHost on it and docked it in the parent container. As far as the design, that's all I had to do. It doesn't matter what size you set the form as it will automatically adjust to fit the dockablewindow. Also, you can do this in a WPF Class Library, I did not have to create an old Windows Forms Class Library. You just need to add a reference to the System.Windows.Forms namespace.

   Here is what the Form looks like in the code behind...

 

Imports Inventor

Public Class DWForm

    Public Sub New(InvApp as Inventor.Application, InternalName As String, WindowTitle As String, WPFControl As UIElement, Optional ShowTitle As Boolean = True)

        ' This call is required by the designer.
          InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        
'Pass the WPFControl to the ElementHost
Me.ElementHost1.Child = WPFControl
'Create the Dockable Window.
Dim DocWin = InvApp.UserInterfaceManager.DockableWindows.Add(CLID, InternalName, WindowTitle)
'Add the current form to the dockable window.
DocWin.AddChild(Me.Handle)

'Controls the Title Bar Visibility. DocWin.ShowTitleBar = ShowTitle

'Make sure the dockable window and the child form are visible. DocWin.Visible = True Me.Visible = True

'Ensure the child window chrome is turned off. Me.FormBorderStyle = Forms.FormBorderStyle.None End Sub End Class

 

 

   The above class allows you to create dockable windows over and over without having to write this code out every time.You just create a new instance of this class and pass in a unique InternalName and the WPF element to be hosted. It's worth noting that the CLID variable (in red) I have in my add-ins as a global variable with my add-in's CLID, you could change the method signature and add that as a parameter to pass in.

 

   Here is how you create multiple instances of dockable windows, this is in my Activate method....

        'Hook into the Inventor Application object...
         _InvApp = AddInSiteObject.Application

Dim DocFrm1 = New DWForm(_InvApp, "FUTE_DW_1", "Window 1", New QuickProps, False)
Dim DocFrm2 = New DWForm(_InvApp, "FUTE_DW_2", "Window 2", New iPropertyBlock, False)

   The QuickProps & iPropertyBlock (in blue) are just WPF User Controls that I have created in my project. I am literally creating them as I pass them into the form. You should build all of you logic and binding into your WPF controls and simply use the form to host it. It may get complicated if you start trying to throw controls on the Windows Form as well.

 

Anyway, I hope that helps! 

Let me know if you have any issues with the code.

 

-Addam

 

 

 


Automation is key!
Message 20 of 23
AlexFielder
in reply to: Boorda

Hi Addam, 

 

That's great work; thanks for sharing!

 

Cheers,

 

Alex.

 

PS. I'm not surprised you went the route of using the ElementHost, it seems almost impossible to use a vanilla-WPF solution.

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

Post to forums  

Autodesk Design & Make Report