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: 

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

9 REPLIES 9
Reply
Message 1 of 10
nttoan8187
9881 Views, 9 Replies

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

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
9 REPLIES 9
Message 2 of 10
YuhanZhang
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.

 


 



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Message 3 of 10
nttoan8187
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
Message 4 of 10
ekinsb
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
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 5 of 10
nttoan8187
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
Message 6 of 10
nttoan8187
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
Message 7 of 10
ekinsb
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
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 8 of 10
nttoan8187
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
Message 9 of 10
ekinsb
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
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 10 of 10
nttoan8187
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

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

Post to forums  

Autodesk Design & Make Report