Inventor Customization

Reply
Valued Contributor
nttoan8187
Posts: 92
Registered: ‎06-29-2010
Message 1 of 10 (2,751 Views)

How to : Add Ribbon Tab, Panels and Button ??

2751 Views, 9 Replies
07-29-2010 01:59 AM

I have already write a Macro in VBA which functions as a button. I want to add a new tab with panels and buttons in these panels. So what I suppose to do is:

1/ Create tab and panels

2/ Add button in panels

 

This is the code I write to do the first step:

[code]

 

  ' Make sure a part document is active

        Dim oAsmDoc As AssemblyDocument

        oAsmDoc = mApp.ActiveDocument
        ' Get the part ribbon

        Dim oAsmRibbon As Ribbon

        oAsmRibbon = mApp.UserInterfaceManager.Ribbons.Item("Assembly")
        ' Create a new tab before the Assemble Tab

        Dim oProTab As RibbonTab

        oProTab = oAsmRibbon.RibbonTabs.Add("Pro", "Id_TabPro", "ClientId12345", "id_TabAssemble", True, False)

         oProTab.Visible = True
        'Create a new panel on the Promecon tab

        Dim oPanel(4) As RibbonPanel

        oPanel(1) = oProTab.RibbonPanels.Add("Model", "id_PanelA_PromeconModel", "ClientId12345")

        oPanel(2) = oProTab.RibbonPanels.Add("Drawing", "id_PanelA_PromeconDrawing", "ClientId12345")

        oPanel(3) = oProTab.RibbonPanels.Add("BonusTools", "id_PanelA_PromeconBonusTools", "ClientId12345")

        oPanel(4) = oProTab.RibbonPanels.Add("Report", "id_PanelA_PromeconReport", "ClientId12345")

[end code]

 

        The fault exists in the bold line.  I think the problem is the ClientId. In the API Online Class Material, they say that "ClientId   -  Input String that uniquely identifies the client. This is the CLSID of the AddIn in a string form, e.g. "{C9A6C580-3817-11D0-BE4E-080036E87B02}". It is not   recommended to pass a “dummy” string or a null string.". But I cann't find out what ClientId is suitable and reasonable.

 

2/ How to convert an VBA modules to a button and add it to panel

 

Thank you so much!


 

Please mark this answer as Problem Solved if it solves your question.
-----------------------------------------------------------------------------------------
Toan
Inventor API
Employee
Posts: 403
Registered: ‎01-06-2009
Message 2 of 10 (2,745 Views)

Re: How to : Add Ribbon Tab, Panels and Button ??

07-29-2010 04:02 AM in reply to: nttoan8187

There is no fault for the bold line, it succeeds when you run the code for first time. But it would fail if you run it twice if you forgot to clean up the ribbon tab you created last time. So to avoid the failure you can check if a ribbon tab with the ClientIDd already exists.

 

To convert a VBA modules to a button I suggest you to read Mr. Brian's paper:

 

http://modthemachine.typepad.com/files/Upgrading to Ribbon.pdf

 

you can find it on the post Upgrading your add ins to support the ribbon user interface.

 

Please let me know if I can help more.

 


 



Rocky Zhang
Inventor API
Manufacturing Solutions
Autodesk, Inc.

Valued Contributor
nttoan8187
Posts: 92
Registered: ‎06-29-2010
Message 3 of 10 (2,742 Views)

Re: How to : Add Ribbon Tab, Panels and Button ??

07-29-2010 04:12 AM in reply to: yuhanzhang

I am reading that paper but I still can't find the solution.

To check that tab, do I use Try method as some code in API Online Class?

I already try it, but it still doesn't work.

Sorry for me, I just begin in API with a very little knowledge in VB.NET

Please mark this answer as Problem Solved if it solves your question.
-----------------------------------------------------------------------------------------
Toan
Inventor API
ADN Support Specialist
Posts: 288
Registered: ‎07-21-2006
Message 4 of 10 (2,730 Views)

Re: How to : Add Ribbon Tab, Panels and Button ??

07-29-2010 11:15 AM in reply to: nttoan8187

I think the main issue is that adding new ribbon elements wasn't ever intended to be used from VBA but from an add-in.  It can be used, but has issues.  One of the main ones is that any changes you make to the ribbon are forgotten the next time you run Inventor.  You're program would need to be re-run for each session.  An add-in also has the same issue but because Inventor automatically runs add-ins each time Inventor is started they have a chance to re-created their user-interface. 

 

If you're far enough along with programming Inventor that you want to customize the user-interface, I would strongly recommend looking at writing add-ins instead of using VBA.

 

This post contains a document that describes how to write an add-in.

 

http://modthemachine.typepad.com/my_weblog/2010/01/how-to-write-an-inventor-add-in.html



Brian Ekins
Developer Technical Services
Autodesk Developer Network
Autodesk, Inc.
Valued Contributor
nttoan8187
Posts: 92
Registered: ‎06-29-2010
Message 5 of 10 (2,719 Views)

Re: How to : Add Ribbon Tab, Panels and Button ??

07-29-2010 08:26 PM in reply to: ekinsb

I will research Upgrading Your AutoDesk Inventor Add-Ins to Use the New Ribbon User Interface  &  Taking the Step from VBA Macros to Autodesk Inventor Add-Ins. I hope that I can figure out how to solve this problem. 

 

Could you please to answer another question in the first problem. As Mr. Rocky Zhang said, I find out that the bold line is right when I press the button first time. If I press the second time, error will exist b/c the later Client-Id coincides with the first Client-Id.

However,when I press the first time,  the new tab exists just for a moment (less than 1 second) and disappears. What should I do if I want to show it when Inventor still running.

I know to show it permanently; I must use Add-In. But now I just want to show it until Inventor shut down.

 Does it relate to the Environment? Override or Parallel Environment?? Or anything else?

 

Thank you so much!

 

 

Please mark this answer as Problem Solved if it solves your question.
-----------------------------------------------------------------------------------------
Toan
Inventor API
Valued Contributor
nttoan8187
Posts: 92
Registered: ‎06-29-2010
Message 6 of 10 (2,709 Views)

Re: How to : Add Ribbon Tab, Panels and Button ??

07-29-2010 11:49 PM in reply to: nttoan8187

 

I got that after I close all assembly document and reopen them. Now I think that when i run the code, I must reopen that environment (assembly, part, etc.) to get the affect.

 

I have 1 more question. I want to get part documents in an assembly. I already write the code, but it doesn't work.

 

[code]

        Dim oFileType As FileTypeEnum

        If oFileType = FileTypeEnum.kAssemblyFileType Then

            ' Set a reference to the assembly component definintion.

            ' This assumes an assembly document is open.

            Dim oAsmCompDef As AssemblyComponentDefinition

            oAsmCompDef = mApp.ActiveDocument.ComponentDefinition


            ' Get the occurrence.

            Dim oOcc As ComponentOccurrence

            Dim i As Integer = 0

            For i = 1 To 500
                oOcc = oAsmCompDef.Occurrences.Item(i)

                oBlockPart = oOcc

                CreateDrawing()

            Next

        End If

 

[end code]

 

With CreateDrawing() is a small sub that create a drawing with an editing part. CreateDrawing() works very well with this oBlockPart:

Dim oBlockPart As PartDocument

oBlockPart = mApp.ActiveEditDocument

 

So, please show me what problem with the upper code, I just want get the parts in assembly. Does the bold line correct?

Please mark this answer as Problem Solved if it solves your question.
-----------------------------------------------------------------------------------------
Toan
Inventor API
ADN Support Specialist
Posts: 288
Registered: ‎07-21-2006
Message 7 of 10 (2,702 Views)

Re: How to : Add Ribbon Tab, Panels and Button ??

07-30-2010 07:25 AM in reply to: nttoan8187

The ComponentOccurrence object represents the occurrence instance in the assembly and is not a part document.  However, you can access the part or assembly document that the occurrence references.  In your code you would edit to the following:

 

   oOcc = oAsmCompDef.Occurrences.Item(i)

   oBlockPart = oOcc.Definition.Document

   CreateDrawing()



Brian Ekins
Developer Technical Services
Autodesk Developer Network
Autodesk, Inc.
Valued Contributor
nttoan8187
Posts: 92
Registered: ‎06-29-2010
Message 8 of 10 (2,691 Views)

Re: How to : Add Ribbon Tab, Panels and Button ??

08-01-2010 07:01 PM in reply to: ekinsb

Thank you so much, it works very well.

 

I just think more deeply and I have a more specific question about the file name. In my assembly, I have a few type of name for part, such as PL-x, PROF-x, LPL-x, LPROF-x, etc (with x is the number). I use the property FullFileName, but it doesn't work.

[code]

' Set a reference to the assembly component definintion.

        ' This assumes an assembly document is open.

        Dim oAsmCompDef As AssemblyComponentDefinition

        oAsmCompDef = mApp.ActiveDocument.ComponentDefinition

        ' Number the occurrence and add its value to oBlockPart

        Dim oOcc As ComponentOccurrence

        Dim i As Integer = 0

        For i = 1 To 500
            oOcc = oAsmCompDef.Occurrences.Item(i)

            oBlockPart = oOcc.Definition.Document

            If oBlockPart.File.FullFileName = "*PL*.ipt" Then

                CreateDrawing()

            End If
        Next

[code]

 

What property I should use?

Thank you so much. I really appreciate all thing you done!

Please mark this answer as Problem Solved if it solves your question.
-----------------------------------------------------------------------------------------
Toan
Inventor API
ADN Support Specialist
Posts: 288
Registered: ‎07-21-2006
Message 9 of 10 (2,673 Views)

Re: How to : Add Ribbon Tab, Panels and Button ??

08-03-2010 01:37 PM in reply to: nttoan8187

Is the line you're using exactly this?

 

    If oBlockPart.File.FullFileName = "*PL*.ipt" Then

 

If so, then you'll likely never enter the If statement because it's trying to match the name exactly, even with the asterisks.  A simple string comparison, like you're doing here does not take into account any wild card characters.  Instead, you'll probably want to use the Like operator.

 

    If oBlockPart.File.FullFileName Like "*PL*.ipt" Then

 

 



Brian Ekins
Developer Technical Services
Autodesk Developer Network
Autodesk, Inc.
Valued Contributor
nttoan8187
Posts: 92
Registered: ‎06-29-2010
Message 10 of 10 (2,667 Views)

Re: How to : Add Ribbon Tab, Panels and Button ??

08-03-2010 07:01 PM in reply to: ekinsb

Thank you so much! I got what I want.

I just find out Overview Articles in Programming Help. It is very very good for me to learn. It has description, explanation, and example code. Now I'm beginning to study all in Programming Help to have an enough knowledge to work in API.

Thank you again, see you later!

Please mark this answer as Problem Solved if it solves your question.
-----------------------------------------------------------------------------------------
Toan
Inventor API

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Inventor Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Autodesk Inventor helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Inventor

Twitter

Facebook

Blogs

Pinterest

Youtube