Probably a Simple Problem: Using CreateFileDialog

Probably a Simple Problem: Using CreateFileDialog

Anonymous
Not applicable
490 Views
3 Replies
Message 1 of 4

Probably a Simple Problem: Using CreateFileDialog

Anonymous
Not applicable

I am new to iLogic (as I'm sure I am about to make clear), and I am running into an issue creating a macro.  I am trying to adapt the following example to batch process some files (Source) but I am getting errors just copying and pasting the code.

 

Right now I am trying to get past the first few lines.  When I paste it into the macro editor I get:

Dim oFileDlg As inventor.FileDialog = Nothing

InventorVb.Application.CreateFileDialog (oFileDlg)

'Search Criteria
oFileDlg.Filter = "Inventor Assemblies (*.iam)|*.iam"

I get an syntax error which I can reslove by removing the  " = Nothing" piece.  However, then I get an error message saying "Object variable or With block variable not set".

 

The more I try to adjust the code the more errors I run into.  Since this is an example I have seen elsewhere I assume the code is correct and I am just doing something wrong.  Do I need to check some references or something?  Has anyone else run into this before?

 

Sorry if this is a dumb question, I am trying to find the answer on my own but the code above seems to work for everyone else in all the examples I can find.

 

 

I am running Inventor 2015

 

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

Anonymous
Not applicable

Strange, I have a very similar code, with the exact same first 2 lines in a rule of mine and it runs fine.

Do you have an entire code or is this all you have so far? If you're sure these lines are the issue, then try replacing your last line with:

 

SyntaxEditor Code Snippet

If oDoc.DocumentType = kAssemblyDocumentObject Then
oFileDlg.Filter = "Autodesk Inventor Assembly Files (*.iam)|*.iam"
End If

I am also pretty new to iLogic and inventor so I am just shooting in the dark here.

 

Also forgot to mention that you have to define oDoc before you try the above. Just paste this line at the top.

 

SyntaxEditor Code Snippet

oDoc = ThisApplication.ActiveDocument

 

0 Likes
Message 3 of 4

Anonymous
Not applicable

If I try to run it without yet having opened a file I get "Object variable or With block variable not set".  If I open a .iam file and run it I get a "Object Required" error on the beginning of the if statement.

0 Likes
Message 4 of 4

MechMachineMan
Advisor
Advisor
Private Function FBrowseMulti
	Dim oMultiList As New List(Of String)
    Dim oFileDlg As FileDialog

    Call ThisApplication.CreateFileDialog(oFileDlg)

    With oFileDlg
        .FilterIndex = 1
        .MultiSelectEnabled = True
        .CancelError = True
           On Error Resume Next

            .Filter = "Inventor Files (*.idw;)|*.idw|All Files (*.*)|*.*"
            .DialogTitle = "Select .idw Files To Include In Drawing List"
            .ShowOpen
    End With
    If Err.Number <> 0 Then
        MsgBox("Error Exists")

   ElseIf Not oFileDlg.FileName = "" Then
        Dim fNames As Object
        fNames = Split(oFileDlg.FileName, "|")
        Dim curName As Object

        For Each curName In fNames
            oMultiList.Add(curName)
        Next curName
    End If
Return oMultiList
End Function

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes