Redirect filepath to avoid idw resolve link dialog box in VBA.

Redirect filepath to avoid idw resolve link dialog box in VBA.

shastu
Advisor Advisor
1,652 Views
14 Replies
Message 1 of 15

Redirect filepath to avoid idw resolve link dialog box in VBA.

shastu
Advisor
Advisor

When I run my VBA code, I have captured and stored the exact file location of the ipt file that I am wanting the idw to resolve to.  Is there anyway I can resolve that file to the idw in VBA so I don't have to see the resolve dialog box when opening the idw? 

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

adam.nagy
Autodesk Support
Autodesk Support

Hi,

 

There are multiple ways you can change what file another file will resolve to:

http://adndevblog.typepad.com/manufacturing/2016/03/replacereference-vs-filesaveas-vs-onfileresoluti...

 

If you want to do it dynamically, i.e. which file it should resolve to might depend on multiple things, then go with #3

 

Cheers,



Adam Nagy
Autodesk Platform Services
0 Likes
Message 3 of 15

shastu
Advisor
Advisor

Thanks for the response Adam.  Unfortunately, I am still missing something.  Let me simplify this as to not waste any of your time.  Lets say I have a file 93100-03.IDW and the model that was used to make that was 93100-03.IPT.  Well, instead of it resolving to 93100-03.ipt I know want it to resolve to 93100-03S.IPT.  So my VBA code would look like this:

 

Sub test()
Dim asmDoc As Document
asmDoc.Launch = ThisApplication.Documents.Open("C:\Infor_PLM\PLM_Client\Inventor\work\PLM\93100-03.IDW")

End Sub

 

The only thing this tries to do is open the document 93100-03.IDW.  What can I do in VBA so that I don't see the Resolve Dialog box and instead it resolves it to 93100-03S.IPT using the VBA code?  I already have code that will capture the full path and filename of the idw file and the full path and filename of the IPT. 

 

Thanks so much,

 

Actually, I just realized that the above code even if the original ipt file exist errors out after it opens the file.  Do you know why that would be?  I get a "Run-time error '91': Object variable or With block variable not set" even though the file opened correctly.

 

0 Likes
Message 4 of 15

shastu
Advisor
Advisor

I changed it to this and it works to open the file without errors.  Now I just need a line above the open command that will point the idw to the new ipt file.

 

Sub test()
Dim asmDoc As Document
ThisApplication.Documents.Open "C:\Infor_PLM\PLM_Client\Inventor\work\PLM\93100-03.IDW"

End Sub

0 Likes
Message 5 of 15

shastu
Advisor
Advisor

Adam,

 

Can you please tell me what I am doing wrong or missing.  How do you know what values to put into some of the parameters.  See below?

 

Sub test()
Dim Orig As String
Dim LibraryName As String
Dim CustomLogicalName As Byte
Dim BeforeOrAfter As EventTimingEnum
Dim Context As NameValueMap
Dim FullFileName As String
Dim HandlingCode As HandlingCodeEnum

Orig = "93100-03.IPT"
FullFileName = "C:\Infor_PLM\PLM_Client\Inventor\work\PLM\93100-03S.IPT"
LibraryName = ""

FileAccessEvents.OnFileResolution(Orig,LibraryName,CustomLogicalName,Before,,FullFileName,kEventHandled)
ThisApplication.Documents.Open "C:\Infor_PLM\PLM_Client\Inventor\work\PLM\93100-03.IDW"

End Sub

0 Likes
Message 6 of 15

Curtis_Waguespack
Consultant
Consultant

Hi shastu,

 

 I know we're always told that files must share ancestry (have the same InternalName) in order to use ReplaceRefernce, but I've not found that to be the case (???)

 

Anyway, this works for me.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

Sub test()

    Dim sPath As String
    sPath = "C:\Infor_PLM\PLM_Client\Inventor\work\PLM\"
    
    ThisApplication.SilentOperation = True

    ThisApplication.Documents.Open (sPath & "93100-03.idw")
       
    ThisApplication.SilentOperation = False
       
    Dim oRefFileDesc As FileDescriptor
    
    For Each oRefFileDesc In ThisApplication.ActiveEditDocument.file.ReferencedFileDescriptors
        oRefFileDesc.ReplaceReference (sPath & "93100-03S.ipt")
    Next
    
     ThisApplication.ActiveEditDocument.Save
    
End Sub

 

0 Likes
Message 7 of 15

shastu
Advisor
Advisor


Curtis,  THANKS SO MUCH!!!  I was wanting to resolve the file somehow before I even opened the idw file.  You on the other hand, open the file, and then resolve the Reference.  I think I can make this work for what I need and it is greatly appreciated.  Just curious though for my own learning purposes can you tell me why you didn't use the FileAccessEvents.OnFileResolution method?

0 Likes
Message 8 of 15

shastu
Advisor
Advisor

Curtis,

 

Your code worked great on my first attempt.  I changed the name of the files to variables instead so that it would work for any file, but then it didn't work.  So I went back to your original code and replaced it with the file names that I was using as a test and it still failed.  I have attached the files for you.  All you have to do with the code you gave me is change out the "93100-03.idw" to "13047-105.idw" and the "93100-03sks.ipt" to "13047-105sks.ipt".  If you could tell me why that is throwing an error maybe it would help me understand the code even more.  Thanks.

0 Likes
Message 9 of 15

shastu
Advisor
Advisor

It must have something to do with my ANSI Title Block.  The first file I tried it on that it worked has a different ANSI Title Block.  Unfortunately, most of the files we have in our system have the one that causes the failure.  If I delete the ANSI Titleblock from the file that causes the error, the error goes away.

0 Likes
Message 10 of 15

Curtis_Waguespack
Consultant
Consultant

shastu wrote:


... for my own learning purposes can you tell me why you didn't use the FileAccessEvents.OnFileResolution method?


Hi shastu,

 

I only took a minute to look at your example code, and simply didn't try very hard to use that method, before digging up an macro I has on hand that used the ReplaceReference method.

 

 


shastu wrote:

It must have something to do with my ANSI Title Block.  The first file I tried it on that it worked has a different ANSI Title Block.  Unfortunately, most of the files we have in our system have the one that causes the failure.  If I delete the ANSI Titleblock from the file that causes the error, the error goes away.


 Maybe it has to do with some prompted entries? I'll try to have a look later to confirm.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

0 Likes
Message 11 of 15

shastu
Advisor
Advisor

That would be great when you have time.  I am curious if you are seeing the same error with those files or not.  Originally, I started with the file that was working and tried bringing in the new Title Block and that caused the errors, but when I went to files that I attached in that zip file and removed that Title Block, I still saw the error so now I am stumped.

0 Likes
Message 12 of 15

shastu
Advisor
Advisor

Sorry for all of the replies but I want to keep you updated on what I have found out to help you help me.  I am doing everything I can to try to resolve this as well.  What I have figured out is that for the file 93100-03.IDW it only goes through the "For Each" loop one time and does not error out.  This means that there is only 1 oRefFileDesc for that file. On the file 13047-105.IDW there are two oRefFileDescs.  It doesn't seem like that should be a problem, but maybe that has something to do with it.  I was under the impression that however many views were in the drawing, that is how many oRefFileDescs there would be, but that is not right.  So I am now thinking that maybe this has something to do with the embedded bmp image in the title block.  If that is the problem, I am not sure how to get around that.

0 Likes
Message 13 of 15

shastu
Advisor
Advisor

Yep, that was it.  Thanks for your help.

0 Likes
Message 14 of 15

Curtis_Waguespack
Consultant
Consultant

Hi shastu,

 

Ahhh, okay.

 

If you've not already done so, maybe just look at the referenced file name and check the extension, something like this example.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

Sub test()

    Dim sPath As String
    sPath = "C:\Infor_PLM\PLM_Client\Inventor\work\PLM\"
       
    ThisApplication.SilentOperation = True

    ThisApplication.Documents.Open (sPath & "93100-03.idw")
       
    ThisApplication.SilentOperation = False
       
    Dim oRefFileDesc As FileDescriptor
    
    For Each oRefFileDesc In ThisApplication.ActiveEditDocument.file.ReferencedFileDescriptors
        'MsgBox (oRefFileDesc.FullFileName) 'show file name
        If Right(oRefFileDesc.FullFileName, 4) = ".ipt" Or _
            Right(oRefFileDesc.FullFileName, 4) = ".iam" Or _
            Right(oRefFileDesc.FullFileName, 4) = ".ipn" Then
            oRefFileDesc.ReplaceReference (sPath & "93100-03S.ipt")
        End If
    Next
    
     ThisApplication.ActiveEditDocument.Save
    
End Sub
0 Likes
Message 15 of 15

shastu
Advisor
Advisor

Thanks, that is probably better than how I got around it.  I just looked for the specific bmp file and then skipped it.

0 Likes