"AssemblyBonusTools_AddPartCmd" Numbering

"AssemblyBonusTools_AddPartCmd" Numbering

antoniobaron
Contributor Contributor
1,046 Views
12 Replies
Message 1 of 13

"AssemblyBonusTools_AddPartCmd" Numbering

antoniobaron
Contributor
Contributor

Hi Folks

 

I just managed to learn from zero in one month some vb.net and inventor add-in development with the objective to create a numbering tool for inventor, so I'm able to define my own file system.

 

So far it worked perfect for every single inventor command, included make components, make parts, new file, assembly or part demoting demoting, frame generator and so on. But, with this "assemblybonustools" I couldn't manage that access its properties, it just fires the file value or filetype somewhere and I don't have a clue of that.

 

I'm completely new in vba, vb.net and ilogic, so please if you have any information about it I would appreciate your help.

I tried accessing through userinput events but I couldn't manage to define it on my addin. 

 

Thank you.

0 Likes
Accepted solutions (4)
1,047 Views
12 Replies
Replies (12)
Message 2 of 13

marcin_otręba
Advisor
Advisor
Accepted solution

hi,

 

try:

Sub PrintCommandNames()
Dim oControlDefs As ControlDefinitions
Set oControlDefs = ThisApplication.CommandManager.ControlDefinitions
Call ThisApplication.CommandManager.PostPrivateEvent(kFileNameEvent, "C:\vault\Projekty\aaa.ipt")
ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyBonusTools_AddPartCmd").Execute

End Sub

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

Message 3 of 13

antoniobaron
Contributor
Contributor

Hi Thank you for your response I appreciate it, seems that i will give me an approach to control the event.

 

Is there any event handler to place in the addin server members? or How should I fire that instruction when I press the command button? 

 

 

0 Likes
Message 4 of 13

marcin_otręba
Advisor
Advisor
Accepted solution

use:

 

Private Sub ui_OnActivateCommand(CommandName As String, Context As NameValueMap) Handles oUserInputEvents.OnActivateCommand

if command name = desired command then run code

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

Message 5 of 13

antoniobaron
Contributor
Contributor

Awesome I'm approaching the solution.

 

Look I have something like this on my add-in

 

"ApplicationAddInServer Members"

 


Public Sub Activate(ByVal addInSiteObject As Inventor.ApplicationAddInSite, ByVal firstTime As Boolean) Implements Inventor.ApplicationAddInServer.Activate

 


' Initialize AddIn members.

m_FileUIEvents = g_inventorApplication.FileUIEvents

m_AppEvents = g_inventorApplication.ApplicationEvents


'Handles Save as Dialog
AddHandler g_inventorApplication.FileUIEvents.OnFileSaveAsDialog, AddressOf m_fileUiEvents_OnFileSaveAsDialog

' Handles onPopulateFileMetadata
AddHandler g_inventorApplication.FileUIEvents.OnPopulateFileMetadata, AddressOf m_fileUIEvents_OnPopulateFileMetadata

 

handler for userInputEvents???????

 

Public Sub m_fileUIEvents_OnPopulateFileMetadata(ByVal FileMetadataObjects As Inventor.ObjectsEnumerator, ByVal Formulae As String, ByVal Context As Inventor.NameValueMap, ByRef HandlingCode As Inventor.HandlingCodeEnum) Handles m_FileUIEvents.OnPopulateFileMetadata

 

 

Now in the following section I will be adding the subrutine for the userEvents on Activate that you just passed to me.

I tried before to add a handler on the activate subrutine, but inventorapplication doesn't give me any option for the userInputEvents on Activate section. do I need to add the handler on the activate?

 

Because I'm completely new programming I don't have a thorough understanding how tings are related. Thanks a lot for your help. I know i'm getting very closer to my goal thanks to you.

 

0 Likes
Message 6 of 13

marcin_otręba
Advisor
Advisor

oUserInputEvents = g_inventorApplication.CommandManager.UserInputEvents

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

Message 7 of 13

antoniobaron
Contributor
Contributor

Mate, thanks for your help, it's really getting closer, certainly all the information you passed to me, let me to find some control over the command, however, the postprivate event doesn't want to work at all.... It blocks the application and shuts it down 😄 well at least I'm crashing it that's a good sign.

I'm also trying to get it through the onfilesaveasdialog event, which shows me the dialog with the desired filenumber but fires twice and then ends up by firing the create part dialog. a bloody mess. due to event handlers on that location and the event handlers of the command.

Any other alternative?


Dim cm As CommandManager = g_inventorApplication.CommandManager

Call cm.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, "D:\Temp\Thepart.ipt")

Dim cd As ControlDefinition = cm.ControlDefinitions("AssemblyBonusTools_AddPartCmd")

Call cd.Execute()

0 Likes
Message 8 of 13

marcin_otręba
Advisor
Advisor

try

FileUIEvents.OnFileInsertNewDialog Event

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 9 of 13

antoniobaron
Contributor
Contributor

Oh, yes I tried to watch that event, the event watcher doesn't show that the event is being fired. It shows the onfilesaveasdialog and the user events we've been dealing with.

I managed to insert my part, and not showing the dialog. At the end i don't know why inventor adds that "Productivity Functionality" if will send into more dialogs and more complicated decisions. So far, it places my part with the new generated number (AWESOME)

But... always a but.. 

It's firing twice the subroutine. How could I control that behaviour?


This is the code.

 If CommandName = "AssemblyBonusTools_AddPartCmd" Then

                Dim DocPath As String = Left(g_inventorApplication.ActiveDocument.FullDocumentName, InStrRev(g_inventorApplication.ActiveDocument.FullDocumentName, "\"))
                ' Call the Class NumberGenerator
                Dim NumbGen As New NumberGenerator


                Dim oFileName As String
                NumbGen.NonDrawingNumberGen(oFileName)



                Dim cm As Inventor.CommandManager = g_inventorApplication.CommandManager
                cm.ClearPrivateEvents()

                Call cm.PostPrivateEvent(Inventor.PrivateEventTypeEnum.kFileNameEvent, DocPath & oFileName & ".ipt")

End if



0 Likes
Message 10 of 13

marcin_otręba
Advisor
Advisor

Hi,

 

and this second time it is also AssemblyBonusTools_AddPartCmd command ? or maybe some other command fired after ?

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 11 of 13

antoniobaron
Contributor
Contributor

The event watcher, shows me that it just fires the command once for active and once for cancel.

If I place a msgbox("This is a test") it will show the message twice during the
sub m_AppUIEvents_OnActivateCommand

I know that the app tries to open go to onfilesaveasdialog afterwards. And I just placed an handler event on that section. But it's the same problem.

How is that it shows twice the dialog? Am i doing something wrong during the declaration of the activate handlers or can i do something there?

0 Likes
Message 12 of 13

antoniobaron
Contributor
Contributor
Accepted solution

Ok I finally solved it thanks to the previous collaboration. Let's say the problem is solved HALF WAY. Still it doesn't show the save dialog with my filenumber. But I'm happy with the results, at the end, it will just save the file in the current assembly folder.

I believe that the solution should be through the save as dialog event, but it will required to develop the entire command.

Open for improvements.

Cheers

 

       Private Sub m_AppUIEvents_OnActivateCommand(CommandName As String, Context As NameValueMap) Handles m_AppUIEvents.OnActivateCommand


            If CommandName = "AssemblyBonusTools_AddPartCmd" Then

                Dim DocPath As String = Left(g_inventorApplication.ActiveDocument.FullDocumentName, InStrRev(g_inventorApplication.ActiveDocument.FullDocumentName, "\"))
                ' Call the Class NumberGenerator
                Dim NumbGen As New NumberGenerator


                Dim oFileName As String
                NumbGen.NonDrawingNumberGen(oFileName)



                Dim cm As Inventor.CommandManager = g_inventorApplication.CommandManager
                'cm.ClearPrivateEvents() ' this was the problem

                Call cm.PostPrivateEvent(Inventor.PrivateEventTypeEnum.kFileNameEvent, DocPath & oFileName & ".ipt")



                'Dim cd As ControlDefinition = cm.ControlDefinitions("MAYBE SOME CONTROL TO OPEN THE SAVEASDIALOG")

                'Call cd.Execute2(True) 


            End If

 

0 Likes
Message 13 of 13

antoniobaron
Contributor
Contributor
Accepted solution
Public Sub m_fileUIEvents_OnPopulateFileMetadata(ByVal FileMetadataObjects As Inventor.ObjectsEnumerator, ByVal Formulae As String, ByVal Context As Inventor.NameValueMap, ByRef HandlingCode As Inventor.HandlingCodeEnum) Handles m_FileUIEvents.OnPopulateFileMetadata

' This is only for one item. 

' For frame generator there are forums with that solution as well as for tube and pipe.


oMetadata = DirectCast(FileMetadataObjects.Item(1), FileMetadata)
Dim MyFile As String
oMetadata.FullFileName = oPath & myFile
oMetadata.DisplayName = MyFile
oMetadata.DisplayNameOverridden = True
oMetadata.FileNameOverridden = True
HandlingCode = HandlingCodeEnum.kEventHandled
0 Likes