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: 

Reg : Custom Ribbon tab

6 REPLIES 6
Reply
Message 1 of 7
deva_bhansali
965 Views, 6 Replies

Reg : Custom Ribbon tab

 

 

Hi everyone,

So far, I worked with macros and did well. I have started with template.

Would like to work on Inventor Add-ins/ Pluggins.

 

I have gone through the help provided in this and reg. templates. But, it would be helpful if anyone tell me what mistake I'm doing in code.


I need to create a custom ribbon tab. Please find the code.
However this is same code published in _http://adndevblog.typepad.com/manufacturing/2013/07/creating-a-ribbon-item-for-inventor.html

 

Anyone's help is appreciated in starting-up..

 

 

 

PublicSub Activate( _

      ByVal addInSiteObject As Inventor.ApplicationAddInSite, _

      ByVal firstTime AsBoolean) _

    Implements Inventor.ApplicationAddInServer.Activate

  ' Inventor application

  m_inventorApplication = addInSiteObject.Application

 

  ' get the command manager control definition

  Dim conDefs As Inventor.ControlDefinitions = _

      m_inventorApplication. _

      CommandManager.ControlDefinitions

 

  ' our custom command ID

  Dim idCommand1 AsString = "ID_COMAND_1"

 

  Try

    ' try get the existing command definition

    _defComando1 = conDefs.Item(idCommand1)

  Catch ex AsException

    ' or create it

    _defComando1 = conDefs.AddButtonDefinition( _

        "Command 1", idCommand1, _

        CommandTypesEnum.kEditMaskCmdType, _

        Guid.NewGuid().ToString(), _

        "Command 1 description", _

        "Command 1 Tooltip", _

        GetICOResource("ProjetName.StdIcon.ico"), _

        GetICOResource("ProjetName.Large.ico"))

  EndTry

 

  If (firstTime) Then

    If (m_inventorApplication.UserInterfaceManager.

        InterfaceStyle =

        InterfaceStyleEnum.kRibbonInterface) Then

 

      ' 1. access the Zero Doc ribbon

      Dim ribbonPart As Inventor.Ribbon =

        m_inventorApplication.

          UserInterfaceManager.

          Ribbons.Item("ZeroDoc")

 

      ' 2. create our custom tab

      Dim tabSampleBlog As Inventor.RibbonTab =

        ribbonPart.RibbonTabs.Add( _

          "Sample Blog", _

          "TAB_SAMPLE_BLOG", _

          Guid.NewGuid().ToString())

 

      ' 3. criar um painel

      Dim pnlMyCommands As Inventor.RibbonPanel =

        tabSampleBlog. _

        RibbonPanels.Add("My Command", _

                         "PNL_MY_COMMANDS", _

                         Guid.NewGuid().ToString())

 

      ' 4. colocar o botão no painel

      pnlMyCommands.CommandControls.AddButton(_defComando1, True)

    EndIf

  EndIf

 

  ' register the method that will be executed

  AddHandler _defComando1.OnExecute, AddressOf Command1Method

 

EndSub

' must be declared at the class level

Private _defComando1 As Inventor.ButtonDefinition

PrivateSub Command1Method()

  ' ToDo: do your code here

EndSub

 

PrivateFunction GetICOResource( _

                  ByVal icoResourceName AsString) AsObject

  Dim assemblyNet As System.Reflection.Assembly = _

    System.Reflection.Assembly.GetExecutingAssembly()

  Dim stream As System.IO.Stream = _

    assemblyNet.GetManifestResourceStream(icoResourceName)

  Dim ico As System.Drawing.Icon = _

    New System.Drawing.Icon(stream)

  ReturnPictureDispConverter.ToIPictureDisp(ico)

EndFunction

The PictureDispConverter converter is based on this AU class by Philippe Leefsma. Below is the piece required here converted to VB.NET

PublicNotInheritableClassPictureDispConverter

  <DllImport("OleAut32.dll",

    EntryPoint:="OleCreatePictureIndirect",

    ExactSpelling:=True, PreserveSig:=False)> _

  PrivateSharedFunction OleCreatePictureIndirect( _

    <MarshalAs(UnmanagedType.AsAny)> picdesc AsObject, _

    ByRef iid AsGuid, _

    <MarshalAs(UnmanagedType.Bool)> fOwn AsBoolean _

    ) AsIPictureDisp

  EndFunction

 

  Shared iPictureDispGuid AsGuid = GetType( _

    IPictureDisp).GUID

 

  PrivateNotInheritableClassPICTDESC

    PrivateSubNew()

    EndSub

    'Picture Types

    PublicConst PICTYPE_UNINITIALIZED AsShort = -1

    PublicConst PICTYPE_NONE AsShort = 0

    PublicConst PICTYPE_BITMAP AsShort = 1

    PublicConst PICTYPE_METAFILE AsShort = 2

    PublicConst PICTYPE_ICON AsShort = 3

    PublicConst PICTYPE_ENHMETAFILE AsShort = 4

 

    <StructLayout(LayoutKind.Sequential)> _

    PublicClassIcon

      Friend cbSizeOfStruct AsInteger = Marshal.SizeOf( _

        GetType(PICTDESC.Icon))

      Friend picType AsInteger = PICTDESC.PICTYPE_ICON

      Friend hicon AsIntPtr = IntPtr.Zero

      Friend unused1 AsInteger

      Friend unused2 AsInteger

 

      FriendSubNew(icon__1 As System.Drawing.Icon)

        Me.hicon = icon__1.ToBitmap().GetHicon()

      EndSub

    EndClass

 

    <StructLayout(LayoutKind.Sequential)> _

    PublicClassBitmap

      Friend cbSizeOfStruct AsInteger = Marshal.SizeOf( _

        GetType(PICTDESC.Bitmap))

      Friend picType AsInteger = PICTDESC.PICTYPE_BITMAP

      Friend hbitmap AsIntPtr = IntPtr.Zero

      Friend hpal AsIntPtr = IntPtr.Zero

      Friend unused AsInteger

 

      FriendSubNew(bitmap__1 As System.Drawing.Bitmap)

        Me.hbitmap = bitmap__1.GetHbitmap()

      EndSub

    EndClass

  EndClass

 

  PublicSharedFunction ToIPictureDisp( _

                    icon As System.Drawing.Icon _

                    ) AsIPictureDisp

    Dim pictIcon AsNewPICTDESC.Icon(icon)

    Return OleCreatePictureIndirect(pictIcon, _

                                    iPictureDispGuid, True)

  EndFunction

 

  PublicSharedFunction ToIPictureDisp( _

                    bmp As System.Drawing.Bitmap _

                    ) AsIPictureDisp

    Dim pictBmp AsNewPICTDESC.Bitmap(bmp)

    Return OleCreatePictureIndirect(pictBmp, _

                                    iPictureDispGuid, True)

  EndFunction

EndClass

 

 

 

 

 

 

The area highlighted in color is giving errors as there's something is missing

 

 

 

6 REPLIES 6
Message 2 of 7
adam.nagy
in reply to: deva_bhansali

Hi,

 

I cannot see what is supposed to be highlighted in the code.

What exact error are you getting and on which exact line?

 

Cheers,



Adam Nagy
Autodesk Platform Services
Message 3 of 7
deva_bhansali
in reply to: adam.nagy

Hi Adam,

Thanks for the reply. I would like to create a New ribbon menu in Autodesk Inventor Environement.

Presently, I have create a button under  > Tools Ribbon. 

It would be helpful if you give me an idea of creation of New Ribbon menu like Model, Inspect, Tools etc.

 

~Deva

Message 4 of 7
adam.nagy
in reply to: deva_bhansali

As I mentioned I could not see anything highlighted in the code you pasted, so I do not know which line is failing for you.

 

One thing that you may be missing is which Ribbon you are adding the tab to. Augusto's sample added it to the ZeroDoc enviroment, e.g. the one when nothing is opened inside Inventor.

If you want to add a tab to e.g. the Ribbon used inside an assembly then you would get it through

m_inventorApplication.UserInterfaceManager.Ribbons.Item("Assembly")


Adam Nagy
Autodesk Platform Services
Message 5 of 7
naresh_kalyan
in reply to: adam.nagy

Hi all,

The same way I have started creation of DLL. I'm done with it. But, when I wanted to change the icon instead of standard icon i.e. addin.ico. It is prompting as shown error as attached.

Can anyone let me know, what I need to do to add my own Icon file?

 

AIP2014, VS2010 (VB.NET)

 

Regards

NKalyan

Message 6 of 7

Ok, I figured it out and I fixed the issue. But, Another quesiton.....

 

Another question: can anyone tell me, how to make a Button visible in couple of cases like if Drawing opened & No document opened.

 

Dim ribbon As Inventor.Ribbon = uiMan.Ribbons("Drawing" and "ZeroDoc"). 'May be an odd syntax, but I put to show the logic

 

Button1: I want to Press the Button to do update, save & Close on a Drawing document which is active.

Button2: I want to run a "for loop" without opening any document, which opens, Updates & Closes multiple drawing documents on specified location.

 

These things I'm able to do in VBA enviroment. Now, I'm creating a Add-in. Please, help me...

 

Regards

NKalyan

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

Post to forums  

Autodesk Design & Make Report