Another Inventor API bug

Another Inventor API bug

BugFinder
Advocate Advocate
699 Views
3 Replies
Message 1 of 4

Another Inventor API bug

BugFinder
Advocate
Advocate

I am trying to use the OnFileresolution event to resolve files and so far this is what I have:

Option Explicit

Private WithEvents inv As Inventor.FileAccessEvents
Private invApp As Inventor.Application

Private Sub Class_Initialize()
    
    On Error Resume Next
    
    Set invApp = GetObject(, "Inventor.Application")
    
    If Err Then
        Err.Clear
        Set invApp = CreateObject("Inventor.Application")
        invApp.Visible = False
    End If
    
    On Error GoTo 0
        
    Set inv = invApp.FileAccessEvents
    
End Sub

Private Sub inv_OnFileResolution(ByVal RelativeFileName As String, ByVal LibraryName As String, CustomLogicalName() As Byte, ByVal BeforeOrAfter As Inventor.EventTimingEnum, ByVal Context As Inventor.NameValueMap, FullFileName As String, HandlingCode As Inventor.HandlingCodeEnum)
    
    Dim str As String
    
    HandlingCode = kEventHandled
    
    If (BeforeOrAfter = kBefore) Then
        str = "C:\New folder\"
        FullFileName = str & RelativeFileName
    End If
    
End Sub

 The problem is the Handlingcode does nothing.  Event though it is set to handled, I still get a dialog box asking for the file which I have specified in the FullFileName.

 

Anyone else got this? Smiley Frustrated

0 Likes
700 Views
3 Replies
Replies (3)
Message 2 of 4

Dennis.Ossadnik
Autodesk Support
Autodesk Support

Hi BugFinder,

 

I tried to reproduce your issue and was faced with the same problem in VB.net 2010.

It seems that this is related to an MS issue. More information you can find here:

http://social.msdn.microsoft.com/Forums/eu/clr/thread/a312244e-371c-4435-a21c-89e604a670d0

 

After I changed the value for Embed Interop Types in VB.net to False the issue was gone.

Then the file resolution will accept your FullFileName and you can redirect to another file.

 

Could you please test and give us a feedback.

Thanks.

Dennis



Dennis Ossadnik
Senior Technical Support Specialist
0 Likes
Message 3 of 4

BugFinder
Advocate
Advocate

Hi Dennis,

 

Sorry I forgot to say, I was using VBA in Access.  Do you know of an appropriate fix for that?

 

Thanks

0 Likes
Message 4 of 4

Dennis.Ossadnik
Autodesk Support
Autodesk Support

Hi BugFinder,

I checked this on my machine and it works. I can handle the event properly using VBA in Access.

(Inventor 2012 - Access 2010)

 

But maybe the following could cause the confusion:

The RelativeFileName could contain also the relative path to the file. If the FullFileName you assembled in your code does not exist, Inventor will show the standard file resolution dialog.

I stepped in this trap while testing the code.

 

For instance:

The RelativeFileName is "Test\file1.ipt" and you want to redirect to the folder "C:\New folder\" then this would end in "C:\New folder\Test\file1.ipt".

But if your file is in "C:\New folder\" Inventor will show the standard dialog and it "seems" that nothing happend.

 

I changed the code to check if there is a relative path and check afterwards if the file exist.

 

Maybe you could give it a try:

Private Sub inv_OnFileResolution(ByVal RelativeFileName As String, ByVal LibraryName As String, CustomLogicalName() As Byte, ByVal BeforeOrAfter As Inventor.EventTimingEnum, ByVal Context As Inventor.NameValueMap, FullFileName As String, HandlingCode As Inventor.HandlingCodeEnum)
    
    If (BeforeOrAfter = kBefore) Then
                    
        Dim FileName As String
        Dim NewFullFileName As String
        
        Dim str As String
        str = "C:\New folder\"
        
        NewFullFileName = str & RelativeFileName
        
        'relative path?
        If InStr(1, RelativeFileName, "\") > 0 Then
            If MsgBox("Your RelativeFileName [" & RelativeFileName & "] contais a relative path. Do you want to use only the FileName instead?", vbYesNo) = vbYes Then
                FileName = Right(RelativeFileName, Len(RelativeFileName) - InStrRev(RelativeFileName, "\"))
                NewFullFileName = str & FileName
            End If
        End If
                
        'Check if the file exists
        Dim objFSO As Object
        Set objFSO = CreateObject("scripting.filesystemobject")
        If objFSO.FileExists(NewFullFileName) = False Then
            MsgBox ("File [" & NewFullFileName & "] not found! Event OnFileResolution will not be handled in this step.")
        Else
        'Only if the check is okay, then set the handling code
            HandlingCode = kEventHandled
            FullFileName = NewFullFileName
        End If
        objFSO = Nothing
    End If
    
End Sub

 

Thanks

Dennis

 



Dennis Ossadnik
Senior Technical Support Specialist
0 Likes