Insert Custom Content center part skipping save as window

Insert Custom Content center part skipping save as window

william.pick
Enthusiast Enthusiast
327 Views
3 Replies
Message 1 of 4

Insert Custom Content center part skipping save as window

william.pick
Enthusiast
Enthusiast

Hello everyone,

I'm trying to inser custom members from content center part, and each time autodesk CC request me to specify a destination folder. Does anyone knows how to set a folder so users would be more confortable using custom members?

 

"As standard vs As custom" in the bottom of the screen.

williampick_0-1724327115123.png

 

"Windows I want to avoid users from chosing"

williampick_1-1724327231620.png

 

Note: A Standard CC memeber would not work, because parts will never repeat.

They will have a Tag for each customer, and after placing this part users may modify according to their needs.

I'm Using Content Center only as a standard folder for users to chose a template to automatically copy and paste.

williampick_2-1724327393072.png

 

Feel free to request more info if it was not clear, or suggest different ways to aproach.

Thanks.

328 Views
3 Replies
Replies (3)
Message 2 of 4

Michael.Navara
Advisor
Advisor

You can modify default behavior of Inventor SaveFileDialog, but it can have some side effects. You can hook to FileUIEvents.OnFileSaveAsDialog event. In this event you have two possibilities. 

  1. Set arguments of the event FileName to full file name and HandlingCode to Handled. In this case the dialog is not displayed and your file name is used and the document is saved. But you are responsible for full file name generation and user has no chance to change them.
  2. Obtain the SaveFileDialog object from Context argument and pass full file name to it. In this case the dialog is displayed, user can change file name and location, but when you pass correct full file name, the user can just click OK. See the sample code
  3. Another approaches like FileUIEvents.OnPopulateFileMetadata, PostPrivateEventApplicationEvents.OnSaveDocument etc. can be used, but it is not useful in my opinion.

Side effects of all approaches mentioned above are

  • It is hard to determine when you want to handle the SaveFileDialog. Because the event doesn't provide information about saved document.
  • It can be in conflict with another tool which can modify the file name like Vault Pro, DataStandards, etc.

For this task is very useful to use EventWatcher from SDK, which can help you to understand events order and to specify the behavior of your tool.

 

iLogic code sample for manipulation with FileDialog during OnFileSaveAsDialog event. It uses SharedVariable to store and restart event handler. It is just for testing purposes. In real implementation use your own add-in instead of iLogic. 

Sub Main()
    Dim handlerName As String = "OnFileSaveAsDialogHandler"
    If SharedVariable.Exists(handlerName) Then
        Dim oldHandler = SharedVariable.Value(handlerName)
        oldHandler.Deactivate()
    End If

    Dim newHandler = New OnFileSaveAsDialogHandler(ThisApplication)
    SharedVariable.Value(handlerName) = newHandler
    newHandler.Activate()


End Sub

Class OnFileSaveAsDialogHandler
    Public Property ThisApplication As Inventor.Application

    Dim _fileUiEvents As FileUIEvents

    Public Sub New(thisApplication As Inventor.Application)
        Me.ThisApplication = thisApplication
    End Sub

    Public Sub Activate()
        _fileUiEvents = ThisApplication.FileUIEvents
        AddHandler _fileUiEvents.OnFileSaveAsDialog, AddressOf FileUIEvents_OnFileSaveAsDialog
    End Sub

    Public Sub Deactivate()
        RemoveHandler _fileUiEvents.OnFileSaveAsDialog, AddressOf FileUIEvents_OnFileSaveAsDialog
        _fileUiEvents = Nothing
    End Sub

    Private Sub FileUIEvents_OnFileSaveAsDialog(ByRef fileTypes As String(),
                                                saveCopyAs As Boolean,
                                                parentHwnd As Integer,
                                                ByRef fileName As String,
                                                context As NameValueMap,
                                                ByRef handlingCode As HandlingCodeEnum)

        handlingCode = HandlingCodeEnum.kEventNotHandled
        Dim fileDialog as Inventor.FileDialog = context.Value("FileDialog")
        fileDialog.FileName = "C:\Temp\" & fileDialog.FileName
    End Sub
End Class

 

Message 3 of 4

william.pick
Enthusiast
Enthusiast

In this case I would have to capture the event of insering from Content Center, set event of the FileDialog to specific file destination I want, then turn it off (Default option). Then it would hide save dialog only when I need, and activate again file dialog to not interfere in additional daily use. Is this order possible?

0 Likes
Message 4 of 4

Michael.Navara
Advisor
Advisor

In general it is possible. but it requires a lot of research, because there are several events which can be fired. Very important is to find appropriate events sequence. 

  • Command CCV2PlaceButton terminates before the dialog is displayed
  • OnInitializeDocument event can be used, but it requires path check of FullDocumentName. And can be fired for another reason (for example placing real standard component). 

EventWatche log sample for placing custom part from CC until the dialog is displayed.

 

UserInputEvents.OnActivateCommand
     CommandName: "CCV2PlaceButton"
     Context: No context information
     
UserInputEvents.OnActivateCommand
     CommandName: "InteractionEvents"
     Context: No context information
     
UserInputEvents.OnTerminateCommand
     CommandName: "CCV2PlaceButton"
     Context: No context information
     
ApplicationEvents.OnInitializeDocument
     DocumentObject: Nothing
     FullDocumentName: "C:\Users\Michael\AppData\Local\Autodesk\Inventor 2024\Content Center\PC\Families\4df02335-e8a2-4e42-abe6-e51d8cfdae0b\en10092-2.ipt"
     Context: No context information
     BeforeOrAfter: kBefore
     HandlingCode: kEventNotHandled
     
ApplicationEvents.OnInitializeDocument
     DocumentObject: en10092-2.ipt (_DocumentClass)
     FullDocumentName: "C:\Users\Michael\AppData\Local\Autodesk\Inventor 2024\Content Center\PC\Families\4df02335-e8a2-4e42-abe6-e51d8cfdae0b\en10092-2.ipt"
     Context: No context information
     BeforeOrAfter: kAfter
     HandlingCode: kEventNotHandled
     
FileUIEvents.OnFileSaveAsDialog
     FileTypes: 
                    Inventor part file (*.ipt)|*.ipt
     SaveCopyAs: False
     ParentHWND: 855844
     FileName: Nothing
     Context:
          FileDialog = FileDialog
          InitialDirectory = "D:\Initial\Directory"
     HandlingCode: kEventNotHandled

 

 

0 Likes