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: 

open file & save file automatically

16 REPLIES 16
SOLVED
Reply
Message 1 of 17
akosi
1976 Views, 16 Replies

open file & save file automatically

hi,

 

most of time i issue hundreds of idw.

 

if i need to rename  or change anything in the iproperties of ipt, im doing it from the vault.

 

my problem is that, when i change something in iproperties of an ipt thru vault, i have to open the idw to update it.

as most of the iproperties in ipt shows in the idw.

 

its easy to change the properties in vault. but its deleting its purpose if i have to each idw to make sure i have the updated idw.

 

is there a code where i can open all idw and save the same file and checkin to the vault automatically?

 

thanks

inventor 2011

vault pro 2012

16 REPLIES 16
Message 2 of 17
jdkriek
in reply to: akosi

Checking in and out of Vault automatically in the manner you want requires a .NET Add-in that includes the Vault Add-in. It's not possible to include the Vault Add-in DLL via VBA. You can access most of the features programmatically through the command manager, but it requires user input on all the dialogs so it would require a lot more custom programming for something already available via .NET. So, yes it's possible, but it's a custom application add-in.

Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


Message 3 of 17
akosi
in reply to: akosi

Okay, nice to know.

But what if it doesnt involve vault. Just local drive , open and save the idw.
Is there someone out there who can help me.?

Thanks for your prompt reply ...

Inventor 2011
Vault pro 2012
Message 4 of 17
jdkriek
in reply to: akosi

I had a minute to put a script together. 

 

As noted in the script you need to include a refrence to the Microsoft Scripting Runtime

 

From the VBA Editor > Tools > Refrences > Check Microsoft Scripting Runtime > Ok

 

Public Sub OpenAndSave()
'JDK 4-30-13
'Include REF to Microsoft Scripting Runtime
    Dim oApp As Application
    Dim oDoc As Document
    Set oApp = ThisApplication
    Dim FSO As New FileSystemObject
    Dim oFld As Scripting.Folder
    Dim oFile As Scripting.File
    Path = "C:\myFolder"
        If FSO.FolderExists(Path) Then
            Set oFld = FSO.GetFolder(Path)
        Else
            MsgBox ("Folder Does Not Exist")
            Exit Sub
        End If
    oApp.SilentOperation = True
        For Each oFile In oFld.Files
            getExt = Split(oFile, ".")
            sExt = getExt(1)
                If InStr(sExt, "idw") Then
                    'Debug.Print oFile
                    Set oDoc = oApp.Documents.Open(oFile, True)
                    oDoc.Save
                    oDoc.Close
                End If
        Next
    oApp.SilentOperation = False
    Set oFile = Nothing
    Set oFld = Nothing
    Set FSO = Nothing
End Sub
Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


Message 5 of 17
akosi
in reply to: jdkriek

hi,

 ive checked the scripting tool but i have all these error?

what should i do?

 

Rule Compile Errors in Rule2, in Part6.ipt

Error on Line 6 : 'Let' and 'Set' assignment statements are no longer supported.

Error on Line 7 : Type 'FileSystemObject' is not defined.

Error on Line 8 : Type 'Scripting.Folder' is not defined.

Error on Line 9 : Type 'Scripting.File' is not defined.

Error on Line 10 : 'Path' is a type and cannot be used as an expression.

Error on Line 11 : 'Path' is a type and cannot be used as an expression.

Error on Line 12 : 'Let' and 'Set' assignment statements are no longer supported.

Error on Line 12 : 'Path' is a type and cannot be used as an expression.

Error on Line 23 : 'Let' and 'Set' assignment statements are no longer supported.

Error on Line 29 : 'Let' and 'Set' assignment statements are no longer supported.

Error on Line 30 : 'Let' and 'Set' assignment statements are no longer supported.

Error on Line 31 : 'Let' and 'Set' assignment statements are no longer supported.

Error on Line 34 : Statement cannot appear outside of a method body.

Message 6 of 17
jdkriek
in reply to: akosi

This is not iLogic; it's VBA and need to be put into a module in the Visual Basic Editor.

 

1. In Inventor got to Tools > VBA Editor

 

2. Once in the VBA Editor got to File > New Project 

 

3. You will see UserProject in the browser, click on it and hit save from the menu.

You will be prompted where to save the project and what name you want.

 

4. Now the project is loaded. Expand the [+] sign and you will see Module1.

 

5. Double click on Module1 and paste the code into it.

 

6. Click on the play button from the menu to run the script.

 

Don't forget the Microsoft Scripting Runtime

(From the VBA Editor > Tools > Refrences > Check Microsoft Scripting Runtime > Ok)

 

Note, VBA (Visual Basic For Applications) is very similar to iLogic which is more or less simplified VB.NET (Add-ins that I was talking about before), but certain syntax and methods are different. I didn't attempt this in iLogic, because that would require you to have a document open whereas VBA doesn't.

Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


Message 7 of 17
akosi
in reply to: jdkriek

thank you so much for replying immediately and giving time to my problem.

 

ive done what you mentioned but its giving me a compile error "variable not defined"

 

attached is a screenshot.

 

 

Message 8 of 17
jdkriek
in reply to: akosi

Remove Option Explicit at the top of the script. Option Explicit is used to avoid incorrectly typing the name of an existing variable or to avoid confusion in code where the scope of the variable is not clear, but for my script it's not needed.

Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


Message 9 of 17
jdkriek
in reply to: jdkriek

Also don't forget to set the path to your local path that you want to Open and Save from 😉

 

"C:\myFolder"
Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


Message 10 of 17
akosi
in reply to: jdkriek

it didnt give me any error now.

but i dont see anything happening and

how to launch this script?

Message 11 of 17
jdkriek
in reply to: akosi

Are there drawings in the folder you specified for the Path?

 

You can trigger the VBA script with iLogic by doing this in a rule:

(Make sure you change NameOfUserProject to the name that you gave it when you created the project earlier.)

 

 

InventorVb.RunMacro("NameOfUserProject", "Module1", "OpenAndSave") 

 

Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


Message 12 of 17
akosi
in reply to: jdkriek

it doesnt do anything if i put the path where my idw are

C:\Vault Projects\Projects\000111123J89\DRAWINGS\PARTS

 

but if i put C:\1 for the folder and copy some of the idw it  works with have some error

i attached a print screen.

 

 

 

 

Message 13 of 17
jdkriek
in reply to: akosi

Not exactly sure why you are having problems.

I tested the code on Inventor 2011 - same version as you and it worked fine.

 

Try this:

 

Public Sub OpenAndSave()
'JDK 4-30-13
'Include REF to Microsoft Scripting Runtime
    Dim oApp As Application
    Set oApp = ThisApplication
    Dim oDoc As DrawingDocument
    Dim FSO As New Scripting.FileSystemObject
    Dim oFld As Scripting.folder
    Dim oFile As Scripting.File
    Dim Path As String
    Path = "C:\myFolder\blah"
        If FSO.FolderExists(Path) Then
            Set oFld = FSO.GetFolder(Path)
        Else
            MsgBox ("Folder Does Not Exist")
            Exit Sub
        End If
    oApp.SilentOperation = True
        For Each oFile In oFld.Files
            getExt = Split(oFile, ".")
            sExt = getExt(1)
                If InStr(sExt, "idw") Then
                    'Debug.Print oFile
                    Set oDoc = oApp.Documents.Open(oFile, True)
                    If oDoc.DocumentType = kDrawingDocumentObject Then
                        With oDoc
                            .Activate
                            .Update
                            .Save
                            .Close
                        End With
                    End If
                End If
        Next
    oApp.SilentOperation = False
    Set oFile = Nothing
    Set oFld = Nothing
    Set FSO = Nothing
End Sub
Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


Message 14 of 17
jdkriek
in reply to: jdkriek

Also, are you sure there are .IDWs in the PARTS folder of your path?

 

Maybe it needs to be?

C:\Vault Projects\Projects\000111123J89\DRAWINGS

 

Robot surprised

Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


Message 15 of 17
akosi
in reply to: jdkriek

it works now.!!!

 

thank you so much...

 

this is my path where i get an error, sorry i forgot to put the  dots.

C:\Vault Projects\Projects\000111123...J89\DRAWINGS\\PARTS

 

when i removed the dots , it works perfectly..

 

you helped me so much ..thanks a lot..

 

you really are a mentor Woman Very Happy

 

Message 16 of 17
jdkriek
in reply to: akosi

You’re quite welcome.

 

Glad it's working now Robot wink

Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


Message 17 of 17
akosi
in reply to: jdkriek

Im using vb.net now and still wanted to try to checkin to the vault programmatically. can I checkin automatically after save? I tried :
g_inventorApplication.CommandManager.ControlDefinitions.Item("VaultCheckinTop").Execute2(True) , but it doesn't work on me.
Please help!!

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

Post to forums  

Autodesk Design & Make Report