Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Macro to create PDF and STP from assembly

daaGQPWD
Explorer

Macro to create PDF and STP from assembly

daaGQPWD
Explorer
Explorer

Hi,

Hope you can help, i am running Inventor Pro 2024

I would like a macro/rule that saves all the parts in an open assembly as a stp and the parts corresponding drawing as a pdf. Would that be possible? 

So from an assembly, save all the subparts, and subassemblies as STP and their corresponding drawings as PDF's?

0 Likes
Reply
Accepted solutions (1)
675 Views
6 Replies
Replies (6)

WCrihfield
Mentor
Mentor

Hi @daaGQPWD.  The short answer is, yes this is possible.  However, there are several variables involved that would need to be clarified before we could even get started.  Also, have you spent any time using the search functionality of this forum yet, to see if anyone else has already asked about a similar task before?  I am pretty sure you would find several related posts that would be helpful, because this is a fairly popular task for many preople.

  • Will the STEP file (.stp) of each model file be exported to the same folder that the model file already resides?
    • If not, please explain in as much detail as possible.
  • Will the STEP file (.stp) be named exactly the same as the model file, just with different file extension?
    • If not, please explain in as much detail as possible.
  • Will the drawing file for each model file be located in the same folder as the model file it represents?
    • If not, please explain in as much detail as possible.
  • Will the drawing file for each model file be named exactly the same as the model file it represents?
    • If not, please explain in as much detail as possible.
  • What options / settings do you want applied to the PDF when it gets exported?
    • To see what options are available, try exporting a PDF manually, and use the Options button to see the options.
  • What options / settings do you want applied to the STEP file when it gets exported?
    • To see what options are available, try exporting a STEP manually, and use the Options button to see the options.
  • There are likely more questions that need to be asked too, so if you think of something else we might need to know, please provide the details.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

berry.lejeune
Advocate
Advocate

Hi @daaGQPWD,

 

I'm using this rule to convert alll of the parts of an assembly to steps. The assembly itself will also get a step.

The folder where the steps will be made in is a subfolder off the folder where the assembly is in. This folder will be automatically made by the rule. When the rule has finished it'll open the folder where the steps have been made in. 

'define the active document as an assembly file
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
oAsmName = ThisDoc.FileName(False) 'without extension

If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
    MessageBox.Show("Please run this rule from the assembly file.", "iLogic")
    Exit Sub
End If
'get user input
RUsure = MessageBox.Show ( _
"This will create a STEP file for all components." _
& vbLf & " " _
& vbLf & "Are you sure you want to create STEP Drawings for all of the assembly components?" _
& vbLf & "This could take a while.", "iLogic - Batch Output STEPs ",MessageBoxButtons.YesNo)
If RUsure = vbNo Then
    Return
Else
End If
'- - - - - - - - - - - - -STEP setup - - - - - - - - - - - -
oPath = ThisDoc.Path
'get STEP target folder path
oFolder = oPath & "\" & oAsmName & " STEP Files"
'Check for the step folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
System.IO.Directory.CreateDirectory(oFolder)
End If



'- - - - - - - - - - - - -Assembly - - - - - - - - - - - -
ThisDoc.Document.SaveAs(oFolder & "\" & oAsmName &(".stp") , True)

'- - - - - - - - - - - - -Components - - - - - - - - - - - -
'look at the files referenced by the assembly
Dim oRefDocs As DocumentsEnumerator
oRefDocs = oAsmDoc.AllReferencedDocuments
Dim oRefDoc As Document
'work the referenced models
For Each oRefDoc In oRefDocs
    Dim oCurFile As Document
    oCurFile = ThisApplication.Documents.Open(oRefDoc.FullFileName, True)
    oCurFileName = oCurFile.FullFileName
   
    'defines backslash As the subdirectory separator
    Dim strCharSep As String = System.IO.Path.DirectorySeparatorChar
   
    'find the postion of the last backslash in the path
    FNamePos = InStrRev(oCurFileName, "\", -1)  
    'get the file name with the file extension
    Name = Right(oCurFileName, Len(oCurFileName) - FNamePos)
    'get the file name (without extension)
    ShortName = Left(Name, Len(Name) - 4)

    Try
        oCurFile.SaveAs(oFolder & "\" & ShortName & (".stp") , True)
    Catch
        MessageBox.Show("Error processing " & oCurFileName, "ilogic")
    End Try
    oCurFile.Close
Next
'- - - - - - - - - - - - -
MessageBox.Show("New Files Created in: " & vbLf & oFolder, "iLogic")
'open the folder where the new files are saved
Shell("explorer.exe " & oFolder,vbNormalFocus)

With the pdf rule I can't help you 

petHYD9W
Observer
Observer

Hi @WCrihfield,
Thank you for your reply, I have scouted the forum and I was able to find help regarding exporting the assemblies and their subparts as STP, however opening and exporting the associated drawings, not so much.
Regarding your questions:
- Everything may be exported to a specified dir. or to the main assemblies parent dir, or to the subparts dir. Whatever is easier.
- Yes, same naming.
- Same as the first question.
- Yes same naming.
- Export all sheets, remove objects' line weights, 600 DPI
- Default settings.

0 Likes

WCrihfield
Mentor
Mentor
Accepted solution

Hi @petHYD9W.  Attached to this response is a text file containing the code for an iLogic rule (not a VBA macro).  You copy & paste that code over into a new external iLogic rule, which can then be used on any Inventor assembly type document.  Just make sure that the main assembly is visibly open on your screen when you run this rule, and it will 'process' the main assembly file itself, as well as every other document being referenced within every level of that assembly.  By process, I mean it will export the model file to a .stp file, then attempt to find an .idw drawing file for that model in the same folder as the model file, with the same name, and when found, it will open that drawing invisibly, in the background, try to export it to a PDF, then release its reference to that drawing file.  Then at the end it will close all of those unreferenced files, to clean up Inventor session memory a bit.  The .stp files & .pdf files will simply be created directly in the same folder where the model files reside, and with the same file names, except for the file extension, or course.  I set the PDF export option to export all sheets, remove line weights, and 600dpi, as you requested.  As for the .stp files, I am not sure about 'default' settings, so I set it to the same settings I generally use, which option 3 (Automotive Design settings), include sketches, fit tolerance set to high accuracy, and include Description from the iProperties of that file, and fill in the Organization from the Company iProperty, and leaving the Authorization part empty.  You can review the code itself, and customize it however you want, if those settings do not suit your needs perfectly.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

daaGQPWD
Explorer
Explorer

Hi @WCrihfield.
Thank you! Worked like a charm!

0 Likes

daaGQPWD
Explorer
Explorer

Hi Again,
Again thank you for your help.
I've been trying to get add a suffix on the name of the saved files. I would like to read a custom property and add it.

However i takes the main assembly's property and not the "subparts" property.

What i tried is:

 

Dim RevNo1 As String = iProperties.Value(oDDoc,"Summary", "Revision Number")
Dim sPDFfile As String = System.IO.Path.Combine(savePath, System.IO.Path.GetFileNameWithoutExtension(oDDoc.FullFileName) & "_" & RevNo1 & ".pdf")

Inside the function:

Function ExportIDWToPDF(oDDoc As DrawingDocument, savePath As String) As Boolean

 Can you help me out once again @WCrihfield 

0 Likes