Hello
The API help & iLogic examples show Inventor with files already open - how can you open files?
I'd like a user form where the file path can be entered & then inventor open the file.
This is for two purposes where I've found example code, printing to pdf & shrinkwrapping.
(the folder structure here is preventing the task scheduler from running).
when the process is finished, close the file & move to the next.
Regards
Andrew
Hoping that answers in below forum discussion would be helpful
You can also refer below Youtube link to create user form
https://www.youtube.com/watch?v=5PN7lWJSobQ
Thanks and regards,
Thankyou - it's not an easy learning curve!
Very early stages - i understand the processing should be done in the module, not the userform.
I can't pass the value from the userform to the module:
The final screen shot shows the message box returning the value aa from the userform when the command button is clicked. However click exit the module message box only shows " _" ww & aa are both missing?
(aa is in the userform, ww is just a copy of aa)
Regards
Andrew
After some further study i've discovered passing values between the user form & the module isn't straight forward so concentrating on the userform for now.
Another discovery is having a variable = variable & looping number is difficult too (impossible?)
The idea is for the user to populate the textboxes with drawing numbers - then iterate through them.
open idw1, (defer updates on), print to pdf, close
next
open idw2, (defer updates on), print to pdf, close
What alternatives are there?
Regards
Andrew
Instead of creating a user form, maybe you can just use the FileDialog object. That gives you a more standard interface for selecting files. If necessary, you could use a FileDialog from a form.
I attached some sample code that could go in a VBA module. It will bring up a file dialog where you can select multiple drawings.
Thankyou - I like it, however..
There's a complication - I'm trying to recreate 'task scheduler' - to print pdf's (& later create shrinkwraps ; task scheduler will not work with the data management software here).
The drawings are large & take a while to open. (opening with deferred updates on is required too).
I was hoping to process the pdf printing overnight or an unoccupied machine.
The sequence being:
Open (deferred), print pdf, close, next.
Regards
Andrew
Try below iLogic code to open drawing and closing the same after action.
Sub Main() Dim path = "C:\Users\Peter\Desktop\TestFolder\" 'Searches directory and it's subdirectories for all files, which "*" stands for 'Say for example you only want to search for jpeg files... then change "*" to "*.jpg" Dim files() As String files = System.IO.Directory.GetFiles(path, "*.idw", System.IO.SearchOption.AllDirectories) For Each FileName As String In files Dim oDoc As DrawingDocument oDoc = ThisApplication.Documents.Open(FileName, True) oDoc.DrawingSettings.DeferUpdates = False Publish_PDF(oDoc) Call oDoc.Close(True) Next End Sub Sub Publish_PDF(oDoc As DrawingDocument) 'Code to publish pdf End Sub
Thanks and regards,
@andrew_canfield , if you're still getting a compile error:
Please copy and paste the full text of the iLogic rule and attach it here as a text file. Use Ctrl+A in the rule editor to select the entire text.
ProcessDrawingsTest.txt is VBA code. It's designed to be copied and pasted into the VBA editor.
The first part almost works!
I mean works as in the select file & file path is displayed, I can't pdf it though - only the idw holding the code gets printed - maybe sticking with vba is better?
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium Dim filenames() As String Dim oTextbox As Inventor.TextBox Dim oFileDlg As Inventor.FileDialog Call ThisApplication.CreateFileDialog(oFileDlg) oFileDlg.Filter = "Drawing Files (*.idw;*.dwg)|*.idw;*.dwg|All Files (*.*)|*.*" ' Define the part and assembly files filter to be the default filter. oFileDlg.FilterIndex = 1 ' Set the title for the dialog. oFileDlg.DialogTitle = "Open Drawings" oFileDlg.MultiSelectEnabled = True ' Set the flag so an error will be raised if the user clicks the Cancel button. oFileDlg.CancelError = True ' Show the open dialog. The same procedure is also used for the Save dialog. On Error Resume Next oFileDlg.ShowOpen GetFilenames = Split(oFileDlg.FileName, "|") ' if multiple names were selected, they will be separated by vertical bar characters For Each Fname In GetFilenames xxx = Fname MessageBox.Show(xxx, "Title")
''' hide everything below this line until the final NEXT & each selected file is displayed. oPrintMgr = ThisApplication.ActiveDocument.PrintManager
''it's not this doc to print as pdf but the xxx file
pdfname = "123" 'old line was'''ThisDoc.FileName(False) filePath = xxx 'old line was '''ThisDoc.Path
oPrintMgr.Printer = "Microsoft Print to PDF" oPrintMgr.AllColorsAsBlack = True oPrintMgr.Orientation = kLandscapeOrientation oPrintMgr.Scalemode = kCustomScale oPrintMgr.ScaleMode = PrintScaleModeEnum.kPrintBestFitScale oPrintMgr.PaperSize = kPaperSizeA4 oPrintMgr.PrintToFile(filePath+"\"+pdfname+".pdf") Next
You don't have any code to open the document.
Try replacing this line:
oPrintMgr = ThisApplication.ActiveDocument.PrintManager
with this:
Dim oDoc As DrawingDocument oDoc = ThisApplication.Documents.Open(FileName, True) oPrintMgr = oDoc.PrintManager