Modify default values in dialog boxes

Modify default values in dialog boxes

TONELLAL
Collaborator Collaborator
1,410 Views
14 Replies
Message 1 of 15

Modify default values in dialog boxes

TONELLAL
Collaborator
Collaborator

When you create a new Frame Generator assembly, you have a dialog box with Frame name, Path to frame file, Skeleton name, path to skeleton file. Inventor propose default values. Is there a way to automatically modify these default values ? For example, instead Inventor propose "New Frame file name = Frame0001.iam", I want a custom calculated file name. Is it possible ?

0 Likes
1,411 Views
14 Replies
Replies (14)
Message 2 of 15

xiaodong_liang
Autodesk Support
Autodesk Support

Hi,

 

The event FileUIEvents.OnPopulateFileMetadata provides you to suggest the name when file names and properties are being generated by a command. Hope it helps.

 

Class1 code: 
Option Explicit 

Private WithEvents fileUIEvts As FileUIEvents 

Private Sub Class_Initialize() 
   Set fileUIEvts = ThisApplication.FileUIEvents 
End Sub 

Private Sub Class_Terminate() 
   Set fileUIEvts = Nothing 
End Sub 

Private Sub fileUIEvts_OnPopulateFileMetadata(ByVal FileMetadataObjects As ObjectsEnumerator, ByVal Formulae As String, ByVal Context As NameValueMap, HandlingCode As HandlingCodeEnum) 
   Dim oMetaData As FileMetadata 
   If FileMetadataObjects.Count 0 Then 
   For Each oMetaData In FileMetadataObjects 
          oMetaData.FileName = "asdk_" & oMetaData.FileName 
         oMetaData.FileNameOverridden = True 
   Next oMetaData 
   HandlingCode = kEventHandled 
  End If 
End Sub 

Module code: 
Private cls As Class1 

Sub startcmd() 
Set cls = New Class1 
End Sub 

Sub Endcmd() 
Set cls = Nothing 
End Sub 

 

0 Likes
Message 3 of 15

TONELLAL
Collaborator
Collaborator

This seems to be what I'm looking for !

But I'm not really a programmer, so it is difficult for me to use it . Do you have a more detailed example, where you effectively modify dialog box values ?

0 Likes
Message 4 of 15

TONELLAL
Collaborator
Collaborator

I finally found how to use it, but :

-how can I use Context ? I think it is used to know why the event fired, but Its value is always 0.

-what is the format and how function Formulae ?

-if I have a dialog box with several FileMetaData objects (for example when using Frame generator : in the same dialog box, you have the skeleton properties (name/path) and the frame properties (name/path)) . How can I make the difference ?

0 Likes
Message 5 of 15

xiaodong_liang
Autodesk Support
Autodesk Support

Hi,

 

1. Context:  you have the correct understanding. The attachments are my test. The context tells why the event fires. It is NOT empty

 

2. Formulae: from help reference, this is  an input String that specifies XML-based formulae for generating file name, display name and file properties. This can be a null string. Sorry I have not a sample at hand

 

3. This question is not clear to me. When FG is insterted, the event fires twice (see attached snapshots), in each, you have the chance to modify the name for FG assembly. FG skeleton and the FG element. 

    

0 Likes
Message 6 of 15

TONELLAL
Collaborator
Collaborator

Thanks for your informations !

 

1-Ok, I was not watching on the right place. I suppose Context.Item(1) is the "type", and Context.Item(2) is the "sub-type" ?

2-Formulae : I read the help, do you know if I can found more information about this ?

3-Effectively, using Context.item I can diffrentiate FG assembly, FG skeleton and the FG element, and modify name/path. So it is ok for FG. But what about Piping ? In this case, I have a similar dialog box with name/path for the piping and for the routing, but Context is empty. The event is yet fired twice (see screen shots).

0 Likes
Message 7 of 15

Anonymous
Not applicable

Hello Tonellal,

 

Is it possible to share the working code? because I can't get the sample given above working properly.

 

Is it actually possible to use the same principle to populate differnt fields in different commands?

 

Thx

 

Chris

 

 

0 Likes
Message 8 of 15

TONELLAL
Collaborator
Collaborator

Here is the code :

 

'in module

Private Sub startcmd()

Dim dd

Set cls = New Class2

End Sub

 

 

'in "Class2" class module

 

Private Sub fileUIEvts_OnPopulateFileMetadata(ByVal FileMetadataObjects As ObjectsEnumerator, ByVal Formulae As String, ByVal Context As NameValueMap, HandlingCode As HandlingCodeEnum)
   Dim oMetaData As FileMetadata
   Dim str As String
  
   str = ThisApplication.CommandManager.ActiveCommand 'Put here a breakpoint to watch Context
      
   If FileMetadataObjects.Count > 0 Then
   For Each oMetaData In FileMetadataObjects
          oMetaData.FileName = "FG filename" & oMetaData.FileName
          oMetaData.FullFileName = "FG fullfilename"
         oMetaData.FileNameOverridden = True
   Next oMetaData
   HandlingCode = kEventHandled
  End If
End Sub

 

 

1/ You use the command "Insert a profile" :

-in the FG dialog box, select the profile and place it

-when you "Apply" or "OK", you stop on the breakpoint, so you ca watch Context, wich contains Item 1 = "Frame Generator" and item 2 = "Frame".

-the event fire several times, you can know why by testing Item 2 : frame, skeleton or member, then for each set values for oMetadata.

 

2/ You use the command "Create a piping route" :

-the event fire, so you stop on the breakpoint. Problem : Context = 0 !! So, how can you know if you are on the Piping assembly, or on the piping route ?

 

0 Likes
Message 9 of 15

xiaodong_liang
Autodesk Support
Autodesk Support

Hi, 

 

hum...sorry, it is also true to me the context is empty for Pipe/Cable. But we have way to know if the current assembly is pipe. 

 

By using the respective GUID for the ADD-In, it’s possible to determine the type of document. Following are GUID for the Cable and Harness, Tube and Piping ,Frame Generator and Design Accelator Add-in’s. Using these GUID in the DocumentInterests.HasInterest property, we can determine the type of the document. 

'Cable & Harness routing - {C6107C9D-C53F-4323-8768-F65F857F9F5A} 
'Tube & Pipe routing - {4D39D5F1-0985-4783-AA5A-FC16C288418C} 
'Autodesk Frame Generator Add-in - {AC211AE0-A7A5-4589-916D-81C529DA6D17} 
'Design Accelerator Add-in - {BB8FE430-83BF-418D-8DF9-9B323D3DB9B9} 

Sub DocHasInteres() 
Dim odocints As DocumentInterests 
Set odocints = ThisApplication.ActiveDocument.DocumentInterests 
Dim hasinterest As Boolean 
'Check for Tube and Pipe routing 
hasinterest = odocints.hasinterest("{4D39D5F1-0985-4783-AA5A-FC16C288418C}") 

If hasinterest Then 
Dim odocint As DocumentInterest 
For Each odocint In odocints 
'Will be FrameDoc for the frame document 
Debug.Print odocint.Name 
Next 
End If 
End Sub

0 Likes
Message 10 of 15

TONELLAL
Collaborator
Collaborator

Ok, this indicate if the active document use a particular add-in. But I don't understand how I can use this to know, when there is a OnPopulateFileMetadata event, that this event come from this add-in ?

0 Likes
Message 11 of 15

xiaodong_liang
Autodesk Support
Autodesk Support

from help doc: DocumentInterest provides a means for an application to register an interest in a document. In another words, to flag the document as containing application-specific data, and to set the data version (for example, so Inventor can determine whether data migration is required and so fire the appropriate event).

 

While OnPopulateFileMetadata is just an event when file names and properties are being generated. So, you should be able to use it anytime. 

0 Likes
Message 12 of 15

Anonymous
Not applicable

Hi, 

 

Will you please help me out with frame generator default values.

I have create an ilogic rule that opens an assembly file asks you for a part number to save it. Then adds a part into the assembly as a phantom part and with the same part number as the assembly.

Then when we enter frame parts I want the create new frame dialog box to default to Frame & part number and also the skeleton & part number.

Then if possible when placing the member if the filename of the members can default to part number & 001,002 etc.

fg dialog box.JPGfg dialog box2.JPG

 

 

0 Likes
Message 13 of 15

TONELLAL
Collaborator
Collaborator

Hi Tony,

I use fileUIEvts_OnPopulateFileMetadata to detect if you are creating aFrame iam or inserting a Frame member. I see you are able to modify  frame and skeleton name, it is the same thing for frrame member name : with context(1) you detect if  you are in FG, if yes with context(2) you detect if you are creating frame/skeleton or inserting a member.

I think what your are searching is in bold :

 

Private Sub fileUIEvts_OnPopulateFileMetadata(ByVal FileMetadataObjects As ObjectsEnumerator, ByVal Formulae As String, ByVal Context As NameValueMap, HandlingCode As HandlingCodeEnum)
'Modifie les noms des fichiers Frame, Squelette et des membres FG, en fonction de ce qui est défini dans le formulaire Form_Renommage_FG_Actif_Inactif

Dim oMetaData As FileMetadata
Dim NomProjet As String
Dim NomStruct As String
Dim NomSousEnsemble As String
Dim Increment As String
Dim newFilename As String
Dim SplitFilename() As String
Dim NumFer As String
Dim i 'As Integer

If Context.Count <> 0 Then
    If Context.item(1) = "Frame Generator" Then 'If context is FG
        
        HandlingCode = kEventHandled

        Select Case Context.item(2)
            Case "Frame, Skeleton" 'Frame and Skeleton treatment
                'FG iam name
                Set oMetaData = FileMetadataObjects.item(1)
                oMetaData.DisplayName = .....
                oMetaData.FileName = .....

                'Skeleton name
                Set oMetaData = FileMetadataObjects.item(2)
                oMetaData.FileName = .....

            Case "Frame Member" 'Frame member treatment
                For Each oMetaData In FileMetadataObjects
                    newFilename = ""
                    SplitFilename = Split(oMetaData.FileName, " ")
                   
                    'Get only the last 3 digits from the default name
                    NumFer = Right(SplitFilename(UBound(SplitFilename)), 3)
    
                   'Get here the part number from your phantom part
                    PartNumber = .....

                   'Create the new filename
                    newFilename =PartNumber & NumFer
    
                    oMetaData.DisplayName = newFilename
                    oMetaData.FileName = newFilename
                Next oMetaData
        End Select

    End If
End If

End Sub
Message 14 of 15

Anonymous
Not applicable

Hi 

 

I am not that good in VBA can you help me a bit further.

If you edit the code so that it works I could probably then work out what I need to change.

 

Many Thanks.

0 Likes
Message 15 of 15

Anonymous
Not applicable

I have it working exactly as I wanted it.

 

many thanks.

0 Likes