Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Bad File Name in Dir

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
AJ1227
3583 Views, 5 Replies

Bad File Name in Dir

Hello all,

 

I created a macro to publish all drawings related to a model as PDF and came across a recent problem that I do not know how to fix.  When someone uses a part from our China engineering library I get a hiccup because the China folders have Chinese characters in the folder name.  Here is the error message I'm getting:

 

Microsoft Visual Basic

Run-time error '52':

Bad file name or number

 

When I try to debug it takes me to this line:

 

 'check for existing file
                If Dir(DrawDocName) <> "" Then

 

I finally figured out what the problem was but I'm not sure how to fix it.  Any ideas?

 

Also, I see that Acrobat has VBA add-ins; does anyone know how to program, at the end of my macro to publish all drawings as PDF's, open Acrobat and combine all files into a single PDF in the order that they were modified?  All I could do at the end of my macro is open Acrobat but not combine.

 

Thanks,

 

5 REPLIES 5
Message 2 of 6
adam.nagy
in reply to: AJ1227

Hi,

 

If you search for "Dir Unicode VBA" on the net then you can find articles on this issue saying that Dir does not seem to support Unicode. Instead, you should be able to use FileSystemObject:

http://www.mrexcel.com/forum/excel-questions/635230-visual-basic-applications-dir-funtion.html and http://msdn.microsoft.com/en-us/library/aa242706(v=vs.60).aspx

 

If Acrobat has VBA, then I would think it also has an ActiveX component (like all the Office applications) that could be used from outside. You could  start here to look for information on that: http://www.adobe.com/devnet/acrobat/interapplication_communication.html

 

Hope this helps.

 

Cheers,



Adam Nagy
Autodesk Platform Services
Message 3 of 6
AJ1227
in reply to: adam.nagy

I've changed the macro to use FSO and it no longer hangs up but it is not finding drawings that exist.  I referenced Microsoft Scripting Runtime and have changed the code as follows, but my Chinese characters are still being changed to question marks (?) and I think that's why it can't find related drawings.

 

   For Each DocFile In OpenDoc.AllReferencedDocuments

   'Get the current part / assembly's path and file name without extension

                Dim FSO As New Scripting.FileSystemObject

                Dim CurrDocName As String

                CurrDocName = FSO.GetAbsolutePathName(DocFile)

   'Create the drawing documents full path and file name with extension

                Dim DrawDocName As String

                DrawDocName = CurrDocName & ".dwg"

   'check for existing file

                If FSO.FileExists(DrawDocName) = True Then

    'drawing exists so perform tasks

 

Do I have something wrong here?

 

Thanks.

Message 4 of 6
AJ1227
in reply to: AJ1227

Ahh, it's not picking up drawings because it's locking in the first parts path as the FSO; how do you get that to reset for each part?

Message 5 of 6
AJ1227
in reply to: AJ1227

Got it working!  All I needed to do from the beginning was add Dim FSO As New Scripting.FileSystemObject and replace Dir with FSO.FileExists.  Here is the revised code.  Thanks for the help!

 

'Get the current part / assembly's path and file name without extension

                Dim FSO As New Scripting.FileSystemObject

                Dim CurrDocName As String

                CurrDocName = Left(DocFile.FullFileName, Len(DocFile.FullFileName) - 4) 'without extension                                

'Create the drawing documents full path and file name with extension

                Dim DrawDocName As String

                DrawDocName = CurrDocName & ".dwg"

'check for existing file

                If FSO.FileExists(DrawDocName) Then

'drawing exists so perform tasks

Message 6 of 6
adam.nagy
in reply to: AJ1227

Thanks for the update.

I'm glad you managed to sort this out. 🙂



Adam Nagy
Autodesk Platform Services

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report