Closing ipt file even when its not the active document...

Closing ipt file even when its not the active document...

Anonymous
Not applicable
1,303 Views
5 Replies
Message 1 of 6

Closing ipt file even when its not the active document...

Anonymous
Not applicable

Hi,

 

Im using vb.net and would like to know if a particular ipt file is open if so close it... I can get the name of an active document and cross check that with a ipt file name but It may verywel be that the ipt file (for arguments sake TEST.ipt) is not the active document how can I close it without saving in that case?

 

The reason is because my test.ipt file is a template which vb.net calls up and uses but in order to do so it cant have any instance of it open to begin with

0 Likes
1,304 Views
5 Replies
Replies (5)
Message 2 of 6

BrandonBG
Collaborator
Collaborator

From the API help:

 

Brandon

 

PartDocument.Close Method

Parent Object: PartDocument

Description Closes this document. Syntax

PartDocument.Close( [SkipSave] As Boolean )

Parameters

NameDescription
SkipSaveOptional input Boolean that specifies whether to skip the save. If SkipSave is set to True, it indicates that the changes to the document should not be saved and that the document should be closed silently. If SkipSave is set to False, it indicates that the normal save process should be followed (including prompting a dialog to the user). In addition, if Application.SilentOperation is set to True, the default choice on the dialog should be accepted. The method will fail if the combination of SkipSave = False and SilentOperation = True is used for a previously unsaved document.
0 Likes
Message 3 of 6

Anonymous
Not applicable

Okay wel lI have badage fixed it by, opeing the file regardlessly and closiing without saving all instances of it with that name (See code)... In my opinion it would be more neat to check IF the document was open to begin with.... checking if an active document is open is reletivly easy because I know how to access an active document however, if it is not an active document thats where I run into a problem.

 

        Dim oApp As Inventor.Application
        Dim oDoc As Inventor.Document
        Dim oDocs As Inventor.Documents

        oApp = Marshal.GetActiveObject("Inventor.Application")
        oDocs = oApp.Documents
        oDoc = oDocs.Open("C:\Template.ipt", True)
        oDoc.Close(True)
0 Likes
Message 4 of 6

Owner2229
Advisor
Advisor

HI, you can try this, if you want to close specific file by name:

 

Dim oApp As Inventor.Application
Dim oDoc As Inventor.Document
Dim oDocs As Inventor.Documents

oApp = ThisApplication
oDocs = oApp.Documents
For Each oDoc In oDocs
    Dim sTS As String = oDoc.FullFileName
    Dim FNamePos As Long = InStrRev(sTS, "\", - 1)
    Dim docFName As String = Mid(sTS, FNamePos + 1, Len(sTS) - FNamePos - 4)
    If docFName = "filename without extension"
	oDoc.Close(True)
    End If
Next

Or this if you want to close all files:

 

Dim oApp As Inventor.Application
Dim oDoc As Inventor.Document
Dim oDocs As Inventor.Documents

oApp = ThisApplication
oDocs = oApp.Documents
For Each oDoc In oDocs
    oDoc.Close(True)
Next

 

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 5 of 6

MechMachineMan
Advisor
Advisor
OR better yet:

Try
oTestDoc = ThisApplication.Documents.ItemByName("Name")
oTestDoc.Close
Catch
End Try

--------------------------------------
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
Message 6 of 6

Owner2229
Advisor
Advisor

Justin scores again 😉

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes