Hi,
I'm trying to create an iLogic rule which opens every drawing of every part in a assembly and then launches my rule to create a PDF and then closes the document one by one. I thought i'd be as simple as this but apperently I'm wrong.
With this code it only opens the drawing of the assembly and then closes it and then does that again.
Dim oAsmDoc As AssemblyDocument oAsmDoc = ThisApplication.ActiveDocument Dim oRefDocs As DocumentsEnumerator oRefDocs = oAsmDoc.AllReferencedDocuments Dim oRefDoc As Document For Each oRefDoc In oRefDocs iLogicVb.RunExternalRule("Overige - open drawing") iLogicVb.RunExternalRule("Export - PDF in assembly") ThisApplication.ActiveDocument.Close(True) Next
Can anyone help me?
Thanks!
Stan
Solved! Go to Solution.
Solved by rossano_praderi. Go to Solution.
Stan,
It is as simple as this :
http://inventortrenches.blogspot.co.uk/2012/11/ilogic-batch-output-pdfs-from-assembly.html
The maestro has it all. Clone his website all completely like I did.
Thank You Curtis!
I've tried that, except it doesn't work for me. My PDF export rule is more worked-out than Curtis' rule and I can't combine it (tried it without success), one of the reasons why it won't work is because we have different filenames for .ipt, .idw and .iam files.
If somebody could strip his rule down to only the part where i can fire a rule on each part, that would solve it.
Thanks
is there some sort of logic between the drawing filename, part filename and assembly filename?
Yes, the drawings have as filename the parts or assemblies part number. And i already have a rule which opens the drawing when i'm in the part or assembly. So i just need to fire this and the PDF rule in every part, then i've got it i think.
aPath = ThisDoc.Path ParNum = iProperties.Value("Project", "Part Number") aName = aPath & "\" & ParNum & ".idw" InventorVb.DocumentUpdate() ThisDoc.Save ThisDoc.Launch(aName)
Thanks!
Hi Stan,
is it possible to have a look to your external rules?
Maybe you are referencing "ThisDoc" in each rule, this will cause a wrong result.
Within the following post there is an explanation of this bad practice used with external rules.
Bregs
Rossano Praderi
Right! That's probably what I'm doing wrong. I've tried some things before i wrote this response but i can't get it to work. The external rules you asked for:
Open drawing:
aPath = ThisDoc.Path ParNum = iProperties.Value("Project", "Part Number") aName = aPath & "\" & ParNum & ".idw" ThisDoc.Launch(aName)
PDF:
Sub Main() oDoc = ThisDoc.Document aModel = IO.Path.GetFileName(ThisDoc.ModelDocument.FullFileName) If Not oDoc.DocumentType = Inventor.DocumentTypeEnum.kDrawingDocumentObject Then MessageBox.Show("This is not a drawing. Please open a drawing to create a PDF-file.", "iLogic", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1) Exit Sub Else If iProperties.Value(aModel, "Project", "Part Number") = "" Then question = MessageBox.Show("The part number is not filled out in the iProperties, do you want to enter a part number?", "iLogic", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) If question = vbNo Then Exit Sub ElseIf question = vbYes Then iProperties.Value(aModel, "Project", "Part Number") = InputBox("Enter a part number.", "iLogic", "") End If Else InventorVb.DocumentUpdate() ThisDoc.Save Update Create Move Export Message End If End Sub Public Sub Update aModel = IO.Path.GetFileName(ThisDoc.ModelDocument.FullFileName) iProperties.Value("Summary", "Title") = iProperties.Value(aModel, "Summary", "Title") iProperties.Value("Summary", "Subject") = iProperties.Value(aModel, "Summary", "Subject") iProperties.Value("Project", "Part Number") = iProperties.Value(aModel, "Project", "Part Number") iProperties.Value("Project", "Revision Number") = iProperties.Value(aModel, "Project", "Revision Number") End Sub Public Sub Create aPath = ThisDoc.Path aFolder = aPath & "\" & "DXF" bFolder = aPath & "\" & "Oud" If Not System.IO.Directory.Exists(aFolder) Then System.IO.Directory.CreateDirectory(aFolder) End If If Not System.IO.Directory.Exists(bFolder) Then System.IO.Directory.CreateDirectory(bFolder) End If End Sub Public Sub Move aPath = ThisDoc.Path iPropParNum = iProperties.Value("Project", "Part Number") noneFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & ".pdf" noneLocation = aPath & "\" & "Oud" & "\" & iPropParNum & ".pdf" none2FileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & " rev.pdf" none2Location = aPath & "\" & "Oud" & "\" & iPropParNum & " rev.pdf" aFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & " revA.pdf" aLocation = aPath & "\" & "Oud" & "\" & iPropParNum & " revA.pdf" bFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & " revB.pdf" bLocation = aPath & "\" & "Oud" & "\" & iPropParNum & " revB.pdf" cFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & " revC.pdf" cLocation = aPath & "\" & "Oud" & "\" & iPropParNum & " revC.pdf" dFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & " revD.pdf" dLocation = aPath & "\" & "Oud" & "\" & iPropParNum & " revD.pdf" eFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & " revE.pdf" eLocation = aPath & "\" & "Oud" & "\" & iPropParNum & " revE.pdf" fFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & " revF.pdf" fLocation = aPath & "\" & "Oud" & "\" & iPropParNum & " revF.pdf" gFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & " revG.pdf" gLocation = aPath & "\" & "Oud" & "\" & iPropParNum & " revG.pdf" hFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & " revH.pdf" hLocation = aPath & "\" & "Oud" & "\" & iPropParNum & " revH.pdf" iFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & " revI.pdf" iLocation = aPath & "\" & "Oud" & "\" & iPropParNum & " revI.pdf" jFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & " revJ.pdf" jLocation = aPath & "\" & "Oud" & "\" & iPropParNum & " revJ.pdf" kFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & " revK.pdf" kLocation = aPath & "\" & "Oud" & "\" & iPropParNum & " revK.pdf" lFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & " revL.pdf" lLocation = aPath & "\" & "Oud" & "\" & iPropParNum & " revL.pdf" mFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & " revM.pdf" mLocation = aPath & "\" & "Oud" & "\" & iPropParNum & " revM.pdf" nFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & " revN.pdf" nLocation = aPath & "\" & "Oud" & "\" & iPropParNum & " revN.pdf" oFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & " revO.pdf" oLocation = aPath & "\" & "Oud" & "\" & iPropParNum & " revO.pdf" pFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & " revP.pdf" pLocation = aPath & "\" & "Oud" & "\" & iPropParNum & " revP.pdf" qFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & " revQ.pdf" qLocation = aPath & "\" & "Oud" & "\" & iPropParNum & " revQ.pdf" rFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & " revR.pdf" rLocation = aPath & "\" & "Oud" & "\" & iPropParNum & " revR.pdf" sFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & " revS.pdf" sLocation = aPath & "\" & "Oud" & "\" & iPropParNum & " revS.pdf" tFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & " revT.pdf" tLocation = aPath & "\" & "Oud" & "\" & iPropParNum & " revT.pdf" uFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & " revU.pdf" uLocation = aPath & "\" & "Oud" & "\" & iPropParNum & " revU.pdf" vFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & " revV.pdf" vLocation = aPath & "\" & "Oud" & "\" & iPropParNum & " revV.pdf" wFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & " revW.pdf" wLocation = aPath & "\" & "Oud" & "\" & iPropParNum & " revW.pdf" xFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & " revX.pdf" xLocation = aPath & "\" & "Oud" & "\" & iPropParNum & " revX.pdf" yFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & " revY.pdf" yLocation = aPath & "\" & "Oud" & "\" & iPropParNum & " revY.pdf" zFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & " revZ.pdf" zLocation = aPath & "\" & "Oud" & "\" & iPropParNum & " revZ.pdf" auFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & "_revA.pdf" auLocation = aPath & "\" & "Oud" & "\" & iPropParNum & "_revA.pdf" buFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & "_revB.pdf" buLocation = aPath & "\" & "Oud" & "\" & iPropParNum & "_revB.pdf" cuFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & "_revC.pdf" cuLocation = aPath & "\" & "Oud" & "\" & iPropParNum & "_revC.pdf" duFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & "_revD.pdf" duLocation = aPath & "\" & "Oud" & "\" & iPropParNum & "_revD.pdf" euFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & "_revE.pdf" euLocation = aPath & "\" & "Oud" & "\" & iPropParNum & "_revE.pdf" fuFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & "_revF.pdf" fuLocation = aPath & "\" & "Oud" & "\" & iPropParNum & "_revF.pdf" guFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & "_revG.pdf" guLocation = aPath & "\" & "Oud" & "\" & iPropParNum & "_revG.pdf" huFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & "_revH.pdf" huLocation = aPath & "\" & "Oud" & "\" & iPropParNum & "_revH.pdf" iuFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & "_revI.pdf" iuLocation = aPath & "\" & "Oud" & "\" & iPropParNum & "_revI.pdf" juFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & "_revJ.pdf" juLocation = aPath & "\" & "Oud" & "\" & iPropParNum & "_revJ.pdf" kuFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & "_revK.pdf" kuLocation = aPath & "\" & "Oud" & "\" & iPropParNum & "_revK.pdf" luFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & "_revL.pdf" luLocation = aPath & "\" & "Oud" & "\" & iPropParNum & "_revL.pdf" muFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & "_revM.pdf" muLocation = aPath & "\" & "Oud" & "\" & iPropParNum & "_revM.pdf" nuFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & "_revN.pdf" nuLocation = aPath & "\" & "Oud" & "\" & iPropParNum & "_revN.pdf" ouFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & "_revO.pdf" ouLocation = aPath & "\" & "Oud" & "\" & iPropParNum & "_revO.pdf" puFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & "_revP.pdf" puLocation = aPath & "\" & "Oud" & "\" & iPropParNum & "_revP.pdf" quFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & "_revQ.pdf" quLocation = aPath & "\" & "Oud" & "\" & iPropParNum & "_revQ.pdf" ruFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & "_revR.pdf" ruLocation = aPath & "\" & "Oud" & "\" & iPropParNum & "_revR.pdf" suFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & "_revS.pdf" suLocation = aPath & "\" & "Oud" & "\" & iPropParNum & "_revS.pdf" tuFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & "_revT.pdf" tuLocation = aPath & "\" & "Oud" & "\" & iPropParNum & "_revT.pdf" uuFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & "_revU.pdf" uuLocation = aPath & "\" & "Oud" & "\" & iPropParNum & "_revU.pdf" vuFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & "_revV.pdf" vuLocation = aPath & "\" & "Oud" & "\" & iPropParNum & "_revV.pdf" wuFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & "_revW.pdf" wuLocation = aPath & "\" & "Oud" & "\" & iPropParNum & "_revW.pdf" xuFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & "_revX.pdf" xuLocation = aPath & "\" & "Oud" & "\" & iPropParNum & "_revX.pdf" yuFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & "_revY.pdf" yuLocation = aPath & "\" & "Oud" & "\" & iPropParNum & "_revY.pdf" zuFileToMove = aPath & "\" & "DXF" & "\" & iPropParNum & "_revZ.pdf" zuLocation = aPath & "\" & "Oud" & "\" & iPropParNum & "_revZ.pdf" If System.IO.File.Exists( noneFileToMove ) = True Then System.IO.File.Delete( noneLocation ) System.IO.File.Move( noneFileToMove, noneLocation ) End If If System.IO.File.Exists( none2FileToMove ) = True Then System.IO.File.Delete( none2Location ) System.IO.File.Move( none2FileToMove, none2Location ) End If If System.IO.File.Exists( aFileToMove ) = True Then System.IO.File.Delete( aLocation ) System.IO.File.Move( aFileToMove, aLocation ) End If If System.IO.File.Exists( bFileToMove ) = True Then System.IO.File.Delete( bLocation ) System.IO.File.Move( bFileToMove, bLocation ) End If If System.IO.File.Exists( cFileToMove ) = True Then System.IO.File.Delete( cLocation ) System.IO.File.Move( cFileToMove, cLocation ) End If If System.IO.File.Exists( dFileToMove ) = True Then System.IO.File.Delete( dLocation ) System.IO.File.Move( dFileToMove, dLocation ) End If If System.IO.File.Exists( eFileToMove ) = True Then System.IO.File.Delete( eLocation ) System.IO.File.Move( eFileToMove, eLocation ) End If If System.IO.File.Exists( fFileToMove ) = True Then System.IO.File.Delete( fLocation ) System.IO.File.Move( fFileToMove, fLocation ) End If If System.IO.File.Exists( gFileToMove ) = True Then System.IO.File.Delete( gLocation ) System.IO.File.Move( gFileToMove, gLocation ) End If If System.IO.File.Exists( hFileToMove ) = True Then System.IO.File.Delete( hLocation ) System.IO.File.Move( hFileToMove, hLocation ) End If If System.IO.File.Exists( iFileToMove ) = True Then System.IO.File.Delete( iLocation ) System.IO.File.Move( iFileToMove, iLocation ) End If If System.IO.File.Exists( jFileToMove ) = True Then System.IO.File.Delete( jLocation ) System.IO.File.Move( jFileToMove, jLocation ) End If If System.IO.File.Exists( kFileToMove ) = True Then System.IO.File.Delete( kLocation ) System.IO.File.Move( kFileToMove, kLocation ) End If If System.IO.File.Exists( lFileToMove ) = True Then System.IO.File.Delete( lLocation ) System.IO.File.Move( lFileToMove, lLocation ) End If If System.IO.File.Exists( mFileToMove ) = True Then System.IO.File.Delete( mLocation ) System.IO.File.Move( mFileToMove, mLocation ) End If If System.IO.File.Exists( nFileToMove ) = True Then System.IO.File.Delete( nLocation ) System.IO.File.Move( nFileToMove, nLocation ) End If If System.IO.File.Exists( oFileToMove ) = True Then System.IO.File.Delete( oLocation ) System.IO.File.Move( oFileToMove, oLocation ) End If If System.IO.File.Exists( pFileToMove ) = True Then System.IO.File.Delete( pLocation ) System.IO.File.Move( pFileToMove, pLocation ) End If If System.IO.File.Exists( qFileToMove ) = True Then System.IO.File.Delete( qLocation ) System.IO.File.Move( qFileToMove, qLocation ) End If If System.IO.File.Exists( rFileToMove ) = True Then System.IO.File.Delete( rLocation ) System.IO.File.Move( rFileToMove, rLocation ) End If If System.IO.File.Exists( sFileToMove ) = True Then System.IO.File.Delete( sLocation ) System.IO.File.Move( sFileToMove, sLocation ) End If If System.IO.File.Exists( tFileToMove ) = True Then System.IO.File.Delete( tLocation ) System.IO.File.Move( tFileToMove, tLocation ) End If If System.IO.File.Exists( uFileToMove ) = True Then System.IO.File.Delete( uLocation ) System.IO.File.Move( uFileToMove, uLocation ) End If If System.IO.File.Exists( vFileToMove ) = True Then System.IO.File.Delete( vLocation ) System.IO.File.Move( vFileToMove, vLocation ) End If If System.IO.File.Exists( wFileToMove ) = True Then System.IO.File.Delete( wLocation ) System.IO.File.Move( wFileToMove, wLocation ) End If If System.IO.File.Exists( xFileToMove ) = True Then System.IO.File.Delete( xLocation ) System.IO.File.Move( xFileToMove, xLocation ) End If If System.IO.File.Exists( yFileToMove ) = True Then System.IO.File.Delete( yLocation ) System.IO.File.Move( yFileToMove, yLocation ) End If If System.IO.File.Exists( zFileToMove ) = True Then System.IO.File.Delete( zLocation ) System.IO.File.Move( zFileToMove, zLocation ) End If If System.IO.File.Exists( auFileToMove ) = True Then System.IO.File.Delete( auLocation ) System.IO.File.Move( auFileToMove, auLocation ) End If If System.IO.File.Exists( buFileToMove ) = True Then System.IO.File.Delete( buLocation ) System.IO.File.Move( buFileToMove, buLocation ) End If If System.IO.File.Exists( cuFileToMove ) = True Then System.IO.File.Delete( cuLocation ) System.IO.File.Move( cuFileToMove, cuLocation ) End If If System.IO.File.Exists( duFileToMove ) = True Then System.IO.File.Delete( duLocation ) System.IO.File.Move( duFileToMove, duLocation ) End If If System.IO.File.Exists( euFileToMove ) = True Then System.IO.File.Delete( euLocation ) System.IO.File.Move( euFileToMove, euLocation ) End If If System.IO.File.Exists( fuFileToMove ) = True Then System.IO.File.Delete( fuLocation ) System.IO.File.Move( fuFileToMove, fuLocation ) End If If System.IO.File.Exists( guFileToMove ) = True Then System.IO.File.Delete( guLocation ) System.IO.File.Move( guFileToMove, guLocation ) End If If System.IO.File.Exists( huFileToMove ) = True Then System.IO.File.Delete( huLocation ) System.IO.File.Move( huFileToMove, huLocation ) End If If System.IO.File.Exists( iuFileToMove ) = True Then System.IO.File.Delete( iuLocation ) System.IO.File.Move( iuFileToMove, iuLocation ) End If If System.IO.File.Exists( juFileToMove ) = True Then System.IO.File.Delete( juLocation ) System.IO.File.Move( juFileToMove, juLocation ) End If If System.IO.File.Exists( kuFileToMove ) = True Then System.IO.File.Delete( kuLocation ) System.IO.File.Move( kuFileToMove, kuLocation ) End If If System.IO.File.Exists( luFileToMove ) = True Then System.IO.File.Delete( luLocation ) System.IO.File.Move( luFileToMove, luLocation ) End If If System.IO.File.Exists( muFileToMove ) = True Then System.IO.File.Delete( muLocation ) System.IO.File.Move( muFileToMove, muLocation ) End If If System.IO.File.Exists( nuFileToMove ) = True Then System.IO.File.Delete( nuLocation ) System.IO.File.Move( nuFileToMove, nuLocation ) End If If System.IO.File.Exists( ouFileToMove ) = True Then System.IO.File.Delete( ouLocation ) System.IO.File.Move( ouFileToMove, ouLocation ) End If If System.IO.File.Exists( puFileToMove ) = True Then System.IO.File.Delete( puLocation ) System.IO.File.Move( puFileToMove, puLocation ) End If If System.IO.File.Exists( quFileToMove ) = True Then System.IO.File.Delete( quLocation ) System.IO.File.Move( quFileToMove, quLocation ) End If If System.IO.File.Exists( ruFileToMove ) = True Then System.IO.File.Delete( ruLocation ) System.IO.File.Move( ruFileToMove, ruLocation ) End If If System.IO.File.Exists( suFileToMove ) = True Then System.IO.File.Delete( suLocation ) System.IO.File.Move( suFileToMove, suLocation ) End If If System.IO.File.Exists( tuFileToMove ) = True Then System.IO.File.Delete( tuLocation ) System.IO.File.Move( tuFileToMove, tuLocation ) End If If System.IO.File.Exists( uuFileToMove ) = True Then System.IO.File.Delete( uuLocation ) System.IO.File.Move( uuFileToMove, uuLocation ) End If If System.IO.File.Exists( vuFileToMove ) = True Then System.IO.File.Delete( vuLocation ) System.IO.File.Move( vuFileToMove, vuLocation ) End If If System.IO.File.Exists( wuFileToMove ) = True Then System.IO.File.Delete( wuLocation ) System.IO.File.Move( wuFileToMove, wuLocation ) End If If System.IO.File.Exists( xuFileToMove ) = True Then System.IO.File.Delete( xuLocation ) System.IO.File.Move( xuFileToMove, xuLocation ) End If If System.IO.File.Exists( yuFileToMove ) = True Then System.IO.File.Delete( yuLocation ) System.IO.File.Move( yuFileToMove, yuLocation ) End If If System.IO.File.Exists( zuFileToMove ) = True Then System.IO.File.Delete( zuLocation ) System.IO.File.Move( zuFileToMove, zuLocation ) End If End Sub Public Sub Export() aPath = ThisDoc.Path iPropParNum = iProperties.Value("Project", "Part Number") iPropRevNum = iProperties.Value("Project", "Revision Number") aPDF = ThisApplication.ApplicationAddIns.ItemById _ ("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}") aDocument = ThisApplication.ActiveDocument aContext = ThisApplication.TransientObjects.CreateTranslationContext aContext.Type = IOMechanismEnum.kFileBrowseIOMechanism aPDFOptions = ThisApplication.TransientObjects.CreateNameValueMap aDataMedium = ThisApplication.TransientObjects.CreateDataMedium aFolder = aPath & "\" & "DXF" bFolder = aPath & "\" & "oud" aDataMedium.FileName = aFolder & "\" & iPropParNum & " rev" & iPropRevNum & ".pdf" aName = aDataMedium.FileName If aPDF.HasSaveCopyAsOptions(aDataMedium, aContext, aPDFOptions) Then aPDFOptions.Value("All_Color_AS_Black") = 1 aPDFOptions.Value("Remove_Line_Weights") = 1 aPDFOptions.Value("Vector_Resolution") = 4800 aPDFOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets End If aPDF.SaveCopyAs(aDocument, aContext, aPDFOptions, aDataMedium) If System.IO.File.Exists( aFolder & "\" & iPropRevNum & ".pdf" ) = True Then System.IO.File.Delete( aFolder & "\" & iPropRevNum & ".pdf" ) End If If System.IO.File.Exists( aFolder & "\" & " rev" & iPropRevNum & ".pdf" ) = True Then System.IO.File.Delete( aFolder & "\" & " rev" & iPropRevNum & ".pdf" ) End If If System.IO.File.Exists( aFolder & "\" & " rev" & ".pdf" ) = True Then System.IO.File.Delete( aFolder & "\" & " rev" & ".pdf" ) End If If System.IO.File.Exists( aFolder & "\" & iPropParNum & " rev" & ".pdf" ) = True Then System.IO.File.Move( aFolder & "\" & iPropParNum & " rev" & ".pdf", aFolder & "\" & iPropParNum & ".pdf" ) End If If System.IO.File.Exists( aFolder & "\" & iPropParNum & " rev-" & ".pdf" ) = True Then System.IO.File.Move( aFolder & "\" & iPropParNum & " rev-" & ".pdf", aFolder & "\" & iPropParNum & ".pdf" ) End If If System.IO.File.Exists( aFolder & "\" & iPropParNum & ".pdf" ) = True Then System.IO.File.Delete( bFolder & "\" & iPropParNum & ".pdf" ) End If If System.IO.File.Exists( aFolder & "\" & iPropParNum & " rev" & iPropRevNum & ".pdf" ) = True Then System.IO.File.Delete( bFolder & "\" & iPropParNum & " rev" & iPropRevNum & ".pdf" ) End If End Sub Public Sub Message() aPath = ThisDoc.Path aFolder = aPath & "\" & "DXF" iPropParNum = iProperties.Value("Project", "Part Number") iPropRevNum = iProperties.Value("Project", "Revision Number") aDataMedium = ThisApplication.TransientObjects.CreateDataMedium aDataMedium.FileName = aFolder & "\" & iPropParNum & " rev" & iPropRevNum & ".pdf" aName = aDataMedium.FileName If iPropRevNum = "" Then aName = aFolder & "\" & iPropParNum & ".pdf" Else If iPropRevNum = "-" Then aName = aFolder & "\" & iPropParNum & ".pdf" End If If Not aName = aFolder & "\" & ".pdf" Then question = MessageBox.Show("Het bestand is opgeslagen in " & aName _ & vbNewLine _ & vbNewLine & "Bestand openen?" , "Opgeslagen",MessageBoxButtons.YesNo,MessageBoxIcon.Question) If question = vbYes Then ThisDoc.Launch(aName) End If End If End Sub
If you could show me how I get the "open drawing" code to work I think I can figure out the rest.
Thanks!
Hi Stan,
I think this is the correct code for your solution.
Main Rule:
Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument Dim oRefDocs As DocumentsEnumerator = oAsmDoc.AllReferencedDocuments ' the following two lines are necessary to pass arguments to the external rule Dim map As Inventor.NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap() map.Add("aPath", ThisDoc.Path) 'map.Add("aFullFileName", "") Dim oRefDoc As Document For Each oRefDoc In oRefDocs 'map.Value("aFullFileName") = oRefDoc.FullFileName ' I've used this line for my tests, but is a useful information for your code 'ThisDoc.Launch(oRefDoc.FullFileName) ' If you want open the referenced filename, I've used this line for my tests iLogicVb.RunExternalRule("Overige - open drawing", map) ' your external rule receive the aPath argument iLogicVb.RunExternalRule("Export - PDF in assembly", map) ' your external rule receive the aPath argument oRefDoc.Close(True) ' this close the referenced document Next
External Rule to Open the referenced document (I think is a better solution if you integrate this code in the main rule):
'aPath = ThisDoc.Path ParNum = iProperties.Value("Project", "Part Number") aName = RuleArguments("aPath") & "\" & ParNum & ".idw" ' this line read the given argument ThisDoc.Launch(aName)
External Rule to export PDF:
(Please read and check carefully this rule before you run it)
Sub Main() ' this information can be easily passed as an argument ' in some cases this code give you wrong information, for example when you call it from an assembly ' this is the right code: ' Dim oDoc As inventor._Document=ThisApplication.documents.itembyname(RuleArguments("aFullFileName")) oDoc = ThisDoc.Document aModel = IO.Path.GetFileName(ThisDoc.ModelDocument.FullFileName) ' RuleArguments("aFullFileName") If Not oDoc.DocumentType = Inventor.DocumentTypeEnum.kDrawingDocumentObject Then MessageBox.Show("This is not a drawing. Please open a drawing to create a PDF-file.", "iLogic", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1) Exit Sub Else If iProperties.Value(aModel, "Project", "Part Number") = "" Then question = MessageBox.Show("The part number is not filled out in the iProperties, do you want to enter a part number?", "iLogic", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) If question = vbNo Then Exit Sub ElseIf question = vbYes Then iProperties.Value(aModel, "Project", "Part Number") = InputBox("Enter a part number.", "iLogic", "") End If Else InventorVb.DocumentUpdate() ThisDoc.Save ' oDoc.Save Update Create Move Export Message End If End Sub Public Sub Update ' this information can be easily passed as an argument ' in some cases this code give you wrong information, for example when you call it from an assembly aModel = IO.Path.GetFileName(ThisDoc.ModelDocument.FullFileName) ' RuleArguments("aFullFileName") iProperties.Value("Summary", "Title") = iProperties.Value(aModel, "Summary", "Title") iProperties.Value("Summary", "Subject") = iProperties.Value(aModel, "Summary", "Subject") iProperties.Value("Project", "Part Number") = iProperties.Value(aModel, "Project", "Part Number") iProperties.Value("Project", "Revision Number") = iProperties.Value(aModel, "Project", "Revision Number") End Sub Public Sub Create 'aPath = ThisDoc.Path aPath = RuleArguments("aPath") ' **** my correction aFolder = aPath & "\" & "DXF" bFolder = aPath & "\" & "Oud" If Not System.IO.Directory.Exists(aFolder) Then System.IO.Directory.CreateDirectory(aFolder) End If If Not System.IO.Directory.Exists(bFolder) Then System.IO.Directory.CreateDirectory(bFolder) End If End Sub Public Sub Move 'aPath = ThisDoc.Path aPath = RuleArguments("aPath") ' **** my correction iPropParNum = iProperties.Value("Project", "Part Number") ' *** my suggestion pDXF = aPath & "\" & "DXF" & "\"& iPropParNum pOUD = aPath & "\" & "Oud" & "\"& iPropParNum noneFileToMove = pDXF & ".pdf" ' you don't need to assign this text to a variable noneLocation = pOUD & ".pdf" ' used it as subroutine argument none2FileToMove = pDXF & " rev.pdf" none2Location = pOUD & " rev.pdf" aFileToMove = pDXF & " revA.pdf" aLocation = pOUD & " revA.pdf" bFileToMove = pDXF & " revB.pdf" bLocation = pOUD & " revB.pdf" cFileToMove = pDXF & " revC.pdf" cLocation = pOUD & " revC.pdf" dFileToMove = pDXF & " revD.pdf" dLocation = pOUD & " revD.pdf" eFileToMove = pDXF & " revE.pdf" eLocation = pOUD & " revE.pdf" fFileToMove = pDXF & " revF.pdf" fLocation = pOUD & " revF.pdf" gFileToMove = pDXF & " revG.pdf" gLocation = pOUD & " revG.pdf" hFileToMove = pDXF & " revH.pdf" hLocation = pOUD & " revH.pdf" iFileToMove = pDXF & " revI.pdf" iLocation = pOUD & " revI.pdf" jFileToMove = pDXF & " revJ.pdf" jLocation = pOUD & " revJ.pdf" kFileToMove = pDXF & " revK.pdf" kLocation = pOUD & " revK.pdf" lFileToMove = pDXF & " revL.pdf" lLocation = pOUD & " revL.pdf" mFileToMove = pDXF & " revM.pdf" mLocation = pOUD & " revM.pdf" nFileToMove = pDXF & " revN.pdf" nLocation = pOUD & " revN.pdf" oFileToMove = pDXF & " revO.pdf" oLocation = pOUD & " revO.pdf" pFileToMove = pDXF & " revP.pdf" pLocation = pOUD & " revP.pdf" qFileToMove = pDXF & " revQ.pdf" qLocation = pOUD & " revQ.pdf" rFileToMove = pDXF & " revR.pdf" rLocation = pOUD & " revR.pdf" sFileToMove = pDXF & " revS.pdf" sLocation = pOUD & " revS.pdf" tFileToMove = pDXF & " revT.pdf" tLocation = pOUD & " revT.pdf" uFileToMove = pDXF & " revU.pdf" uLocation = pOUD & " revU.pdf" vFileToMove = pDXF & " revV.pdf" vLocation = pOUD & " revV.pdf" wFileToMove = pDXF & " revW.pdf" wLocation = pOUD & " revW.pdf" xFileToMove = pDXF & " revX.pdf" xLocation = pOUD & " revX.pdf" yFileToMove = pDXF & " revY.pdf" yLocation = pOUD & " revY.pdf" zFileToMove = pDXF & " revZ.pdf" zLocation = pOUD & " revZ.pdf" auFileToMove = pDXF & "_revA.pdf" auLocation = pOUD & "_revA.pdf" buFileToMove = pDXF & "_revB.pdf" buLocation = pOUD & "_revB.pdf" cuFileToMove = pDXF & "_revC.pdf" cuLocation = pOUD & "_revC.pdf" duFileToMove = pDXF & "_revD.pdf" duLocation = pOUD & "_revD.pdf" euFileToMove = pDXF & "_revE.pdf" euLocation = pOUD & "_revE.pdf" fuFileToMove = pDXF & "_revF.pdf" fuLocation = pOUD & "_revF.pdf" guFileToMove = pDXF & "_revG.pdf" guLocation = pOUD & "_revG.pdf" huFileToMove = pDXF & "_revH.pdf" huLocation = pOUD & "_revH.pdf" iuFileToMove = pDXF & "_revI.pdf" iuLocation = pOUD & "_revI.pdf" juFileToMove = pDXF & "_revJ.pdf" juLocation = pOUD & "_revJ.pdf" kuFileToMove = pDXF & "_revK.pdf" kuLocation = pOUD & "_revK.pdf" luFileToMove = pDXF & "_revL.pdf" luLocation = pOUD & "_revL.pdf" muFileToMove = pDXF & "_revM.pdf" muLocation = pOUD & "_revM.pdf" nuFileToMove = pDXF & "_revN.pdf" nuLocation = pOUD & "_revN.pdf" ouFileToMove = pDXF & "_revO.pdf" ouLocation = pOUD & "_revO.pdf" puFileToMove = pDXF & "_revP.pdf" puLocation = pOUD & "_revP.pdf" quFileToMove = pDXF & "_revQ.pdf" quLocation = pOUD & "_revQ.pdf" ruFileToMove = pDXF & "_revR.pdf" ruLocation = pOUD & "_revR.pdf" suFileToMove = pDXF & "_revS.pdf" suLocation = pOUD & "_revS.pdf" tuFileToMove = pDXF & "_revT.pdf" tuLocation = pOUD & "_revT.pdf" uuFileToMove = pDXF & "_revU.pdf" uuLocation = pOUD & "_revU.pdf" vuFileToMove = pDXF & "_revV.pdf" vuLocation = pOUD & "_revV.pdf" wuFileToMove = pDXF & "_revW.pdf" wuLocation = pOUD & "_revW.pdf" xuFileToMove = pDXF & "_revX.pdf" xuLocation = pOUD & "_revX.pdf" yuFileToMove = pDXF & "_revY.pdf" yuLocation = pOUD & "_revY.pdf" zuFileToMove = pDXF & "_revZ.pdf" zuLocation = pOUD & "_revZ.pdf"
' you don' need to assign a variable for each line
' Check_Del_Move_File( pDXF & ".pdf", pOUD & ".pdf")
Check_Del_Move_File( noneFileToMove, noneLocation ) Check_Del_Move_File( none2FileToMove, none2Location ) Check_Del_Move_File( aFileToMove, aLocation ) Check_Del_Move_File( bFileToMove, bLocation ) Check_Del_Move_File( cFileToMove, cLocation ) Check_Del_Move_File( dFileToMove, dLocation ) Check_Del_Move_File( eFileToMove, eLocation ) Check_Del_Move_File( fFileToMove, fLocation ) Check_Del_Move_File( gFileToMove, gLocation ) Check_Del_Move_File( hFileToMove, hLocation ) Check_Del_Move_File( iFileToMove, iLocation ) Check_Del_Move_File( jFileToMove, jLocation ) Check_Del_Move_File( kFileToMove, kLocation ) Check_Del_Move_File( lFileToMove, lLocation ) Check_Del_Move_File( mFileToMove, mLocation ) Check_Del_Move_File( nFileToMove, nLocation ) Check_Del_Move_File( oFileToMove, oLocation ) Check_Del_Move_File( pFileToMove, pLocation ) Check_Del_Move_File( qFileToMove, qLocation ) Check_Del_Move_File( rFileToMove, rLocation ) Check_Del_Move_File( sFileToMove, sLocation ) Check_Del_Move_File( tFileToMove, tLocation ) Check_Del_Move_File( uFileToMove, uLocation ) Check_Del_Move_File( vFileToMove, vLocation ) Check_Del_Move_File( wFileToMove, wLocation ) Check_Del_Move_File( xFileToMove, xLocation ) Check_Del_Move_File( yFileToMove, yLocation ) Check_Del_Move_File( zFileToMove, zLocation ) Check_Del_Move_File( auFileToMove, auLocation ) Check_Del_Move_File( buFileToMove, buLocation ) Check_Del_Move_File( cuFileToMove, cuLocation ) Check_Del_Move_File( duFileToMove, duLocation ) Check_Del_Move_File( euFileToMove, euLocation ) Check_Del_Move_File( fuFileToMove, fuLocation ) Check_Del_Move_File( guFileToMove, guLocation ) Check_Del_Move_File( huFileToMove, huLocation ) Check_Del_Move_File( iuFileToMove, iuLocation ) Check_Del_Move_File( juFileToMove, juLocation ) Check_Del_Move_File( kuFileToMove, kuLocation ) Check_Del_Move_File( luFileToMove, luLocation ) Check_Del_Move_File( muFileToMove, muLocation ) Check_Del_Move_File( nuFileToMove, nuLocation ) Check_Del_Move_File( ouFileToMove, ouLocation ) Check_Del_Move_File( puFileToMove, puLocation ) Check_Del_Move_File( quFileToMove, quLocation ) Check_Del_Move_File( ruFileToMove, ruLocation ) Check_Del_Move_File( suFileToMove, suLocation ) Check_Del_Move_File( tuFileToMove, tuLocation ) Check_Del_Move_File( uuFileToMove, uuLocation ) Check_Del_Move_File( vuFileToMove, vuLocation ) Check_Del_Move_File( wuFileToMove, wuLocation ) Check_Del_Move_File( xuFileToMove, xuLocation ) Check_Del_Move_File( yuFileToMove, yuLocation ) Check_Del_Move_File( zuFileToMove, zuLocation ) ' *** end of suggestion End Sub Public Sub Export() 'aPath = ThisDoc.Path aPath = RuleArguments("aPath") ' *** my correction iPropParNum = iProperties.Value("Project", "Part Number") iPropRevNum = iProperties.Value("Project", "Revision Number") aPDF = ThisApplication.ApplicationAddIns.ItemById _ ("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}") aDocument = ThisApplication.ActiveDocument aContext = ThisApplication.TransientObjects.CreateTranslationContext aContext.Type = IOMechanismEnum.kFileBrowseIOMechanism aPDFOptions = ThisApplication.TransientObjects.CreateNameValueMap aDataMedium = ThisApplication.TransientObjects.CreateDataMedium aFolder = aPath & "\" & "DXF" bFolder = aPath & "\" & "oud" aDataMedium.FileName = aFolder & "\" & iPropParNum & " rev" & iPropRevNum & ".pdf" aName = aDataMedium.FileName ' *** this variable is not used *** If aPDF.HasSaveCopyAsOptions(aDataMedium, aContext, aPDFOptions) Then aPDFOptions.Value("All_Color_AS_Black") = 1 aPDFOptions.Value("Remove_Line_Weights") = 1 aPDFOptions.Value("Vector_Resolution") = 4800 aPDFOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets End If aPDF.SaveCopyAs(aDocument, aContext, aPDFOptions, aDataMedium) ' *** the follow code has been adapted on my suggested subroutines Check_Del_File(aFolder & "\" & iPropRevNum & ".pdf", aFolder & "\" & iPropRevNum & ".pdf") Check_Del_File(aFolder & "\" & " rev" & iPropRevNum & ".pdf", aFolder & "\" & " rev" & iPropRevNum & ".pdf") Check_Del_File(aFolder & "\" & " rev" & ".pdf", aFolder & "\" & " rev" & ".pdf") Check_Move_File(aFolder & "\" & iPropParNum & " rev" & ".pdf", _ aFolder & "\" & iPropParNum & " rev" & ".pdf", aFolder & "\" & iPropParNum & ".pdf") Check_Move_File(aFolder & "\" & iPropParNum & " rev-" & ".pdf", _ aFolder & "\" & iPropParNum & " rev-" & ".pdf", aFolder & "\" & iPropParNum & ".pdf" ) Check_Del_File(aFolder & "\" & iPropParNum & ".pdf", bFolder & "\" & iPropParNum & ".pdf" ) Check_Del_File(aFolder & "\" & iPropParNum & " rev" & iPropRevNum & ".pdf", _ bFolder & "\" & iPropParNum & " rev" & iPropRevNum & ".pdf" ) End Sub Sub Check_Del_File(oExist As String, oDelete As String) ' my suggestion ' Try If System.IO.File.Exists(oExist) = True Then System.IO.File.Delete(oDelete) End If ' is a good practice to add an error control code ' Catch e As Exception ' MsgBox("The process failed: {0}", e.ToString()) ' End Try End Sub Sub Check_Move_File(oFileToMove As String, oLocation As String) ' my suggestion ' Try If System.IO.File.Exists(oFileToMove) = True Then System.IO.File.Move(oFileToMove, oLocation) End If ' is a good practice to add an error control code ' Catch e As Exception ' MsgBox("The process failed: {0}", e.ToString()) ' End Try End Sub Sub Check_Del_Move_File(oFileToMove As String, oLocation As String) ' my suggestion ' Try If System.IO.File.Exists(oFileToMove) = True Then System.IO.File.Delete(oLocation) System.IO.File.Move(oFileToMove, oLocation) End If ' is a good practice to add an error control code ' Catch e As Exception ' MsgBox("The process failed: {0}", e.ToString()) ' End Try End Sub Public Sub Message() 'aPath = ThisDoc.Path 'aFolder = aPath & "\" & "DXF" aFolder = RuleArguments("aPath") & "\" & "DXF" ' *** my correction iPropParNum = iProperties.Value("Project", "Part Number") iPropRevNum = iProperties.Value("Project", "Revision Number") aDataMedium = ThisApplication.TransientObjects.CreateDataMedium aDataMedium.FileName = aFolder & "\" & iPropParNum & " rev" & iPropRevNum & ".pdf" aName = aDataMedium.FileName ' I don't think you need this line ' *** this condition don't do nothing, may be contain an error*** If iPropRevNum = "" Then aName = aFolder & "\" & iPropParNum & ".pdf" Else If iPropRevNum = "-" Then aName = aFolder & "\" & iPropParNum & ".pdf" End If ' *** If Not aName = aFolder & "\" & ".pdf" Then question = MessageBox.Show("Het bestand is opgeslagen in " & aName _ & vbNewLine _ & vbNewLine & "Bestand openen?" , "Opgeslagen",MessageBoxButtons.YesNo,MessageBoxIcon.Question) If question = vbYes Then ThisDoc.Launch(aName) End If End If End Sub
Please let me know if my corrections and my suggestions are helpful for you.
Bregs
Rossano Praderi
Hi Stan,
this my solution to your problem.
Main Rule:
Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument Dim oRefDocs As DocumentsEnumerator = oAsmDoc.AllReferencedDocuments ' the following two lines are necessary to pass arguments to the external rule Dim map As Inventor.NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap() map.Add("aPath", ThisDoc.Path) 'map.Add("aFullFileName", "") Dim oRefDoc As Document For Each oRefDoc In oRefDocs 'map.Value("aFullFileName") = oRefDoc.FullFileName ' I've used this line for my tests, but is a useful information for your code 'ThisDoc.Launch(oRefDoc.FullFileName) ' If you want open the referenced filename, I've used this line for my tests iLogicVb.RunExternalRule("Overige - open drawing", map) ' your external rule receive the aPath argument iLogicVb.RunExternalRule("Export - PDF in assembly", map) ' your external rule receive the aPath argument oRefDoc.Close(True) ' this close the referenced document Next
Open Document Rule:
'aPath = ThisDoc.Path ParNum = iProperties.Value("Project", "Part Number") aName = RuleArguments("aPath") & "\" & ParNum & ".idw" ' this line read the given argument ThisDoc.Launch(aName)
PDF export Rule: (check carefully this rule before use it)
Sub Main() ' this information can be easily passed as an argument ' in some cases this code give you wrong information, for example when you call it from an assembly ' this is the right code: ' Dim oDoc As inventor._Document=ThisApplication.documents.itembyname(RuleArguments("aFullFileName")) oDoc = ThisDoc.Document aModel = IO.Path.GetFileName(ThisDoc.ModelDocument.FullFileName) ' RuleArguments("aFullFileName") If Not oDoc.DocumentType = Inventor.DocumentTypeEnum.kDrawingDocumentObject Then MessageBox.Show("This is not a drawing. Please open a drawing to create a PDF-file.", "iLogic", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1) Exit Sub Else If iProperties.Value(aModel, "Project", "Part Number") = "" Then question = MessageBox.Show("The part number is not filled out in the iProperties, do you want to enter a part number?", "iLogic", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) If question = vbNo Then Exit Sub ElseIf question = vbYes Then iProperties.Value(aModel, "Project", "Part Number") = InputBox("Enter a part number.", "iLogic", "") End If Else InventorVb.DocumentUpdate() ThisDoc.Save ' oDoc.Save Update Create Move Export Message End If End Sub Public Sub Update ' this information can be easily passed as an argument ' in some cases this code give you wrong information, for example when you call it from an assembly aModel = IO.Path.GetFileName(ThisDoc.ModelDocument.FullFileName) ' RuleArguments("aFullFileName") iProperties.Value("Summary", "Title") = iProperties.Value(aModel, "Summary", "Title") iProperties.Value("Summary", "Subject") = iProperties.Value(aModel, "Summary", "Subject") iProperties.Value("Project", "Part Number") = iProperties.Value(aModel, "Project", "Part Number") iProperties.Value("Project", "Revision Number") = iProperties.Value(aModel, "Project", "Revision Number") End Sub Public Sub Create 'aPath = ThisDoc.Path aPath = RuleArguments("aPath") ' **** my correction aFolder = aPath & "\" & "DXF" bFolder = aPath & "\" & "Oud" If Not System.IO.Directory.Exists(aFolder) Then System.IO.Directory.CreateDirectory(aFolder) End If If Not System.IO.Directory.Exists(bFolder) Then System.IO.Directory.CreateDirectory(bFolder) End If End Sub Public Sub Move 'aPath = ThisDoc.Path aPath = RuleArguments("aPath") ' **** my correction iPropParNum = iProperties.Value("Project", "Part Number") ' *** my suggestion pDXF = aPath & "\" & "DXF" & "\"& iPropParNum ' you don't need to assign a variable for each revision pOUD = aPath & "\" & "Oud" & "\"& iPropParNum ' use this text as subroutine argument noneFileToMove = pDXF & ".pdf" ' this will give you a shorter code noneLocation = pOUD & ".pdf" none2FileToMove = pDXF & " rev.pdf" none2Location = pOUD & " rev.pdf" aFileToMove = pDXF & " revA.pdf" aLocation = pOUD & " revA.pdf" bFileToMove = pDXF & " revB.pdf" bLocation = pOUD & " revB.pdf" cFileToMove = pDXF & " revC.pdf" cLocation = pOUD & " revC.pdf" dFileToMove = pDXF & " revD.pdf" dLocation = pOUD & " revD.pdf" eFileToMove = pDXF & " revE.pdf" eLocation = pOUD & " revE.pdf" fFileToMove = pDXF & " revF.pdf" fLocation = pOUD & " revF.pdf" gFileToMove = pDXF & " revG.pdf" gLocation = pOUD & " revG.pdf" hFileToMove = pDXF & " revH.pdf" hLocation = pOUD & " revH.pdf" iFileToMove = pDXF & " revI.pdf" iLocation = pOUD & " revI.pdf" jFileToMove = pDXF & " revJ.pdf" jLocation = pOUD & " revJ.pdf" kFileToMove = pDXF & " revK.pdf" kLocation = pOUD & " revK.pdf" lFileToMove = pDXF & " revL.pdf" lLocation = pOUD & " revL.pdf" mFileToMove = pDXF & " revM.pdf" mLocation = pOUD & " revM.pdf" nFileToMove = pDXF & " revN.pdf" nLocation = pOUD & " revN.pdf" oFileToMove = pDXF & " revO.pdf" oLocation = pOUD & " revO.pdf" pFileToMove = pDXF & " revP.pdf" pLocation = pOUD & " revP.pdf" qFileToMove = pDXF & " revQ.pdf" qLocation = pOUD & " revQ.pdf" rFileToMove = pDXF & " revR.pdf" rLocation = pOUD & " revR.pdf" sFileToMove = pDXF & " revS.pdf" sLocation = pOUD & " revS.pdf" tFileToMove = pDXF & " revT.pdf" tLocation = pOUD & " revT.pdf" uFileToMove = pDXF & " revU.pdf" uLocation = pOUD & " revU.pdf" vFileToMove = pDXF & " revV.pdf" vLocation = pOUD & " revV.pdf" wFileToMove = pDXF & " revW.pdf" wLocation = pOUD & " revW.pdf" xFileToMove = pDXF & " revX.pdf" xLocation = pOUD & " revX.pdf" yFileToMove = pDXF & " revY.pdf" yLocation = pOUD & " revY.pdf" zFileToMove = pDXF & " revZ.pdf" zLocation = pOUD & " revZ.pdf" auFileToMove = pDXF & "_revA.pdf" auLocation = pOUD & "_revA.pdf" buFileToMove = pDXF & "_revB.pdf" buLocation = pOUD & "_revB.pdf" cuFileToMove = pDXF & "_revC.pdf" cuLocation = pOUD & "_revC.pdf" duFileToMove = pDXF & "_revD.pdf" duLocation = pOUD & "_revD.pdf" euFileToMove = pDXF & "_revE.pdf" euLocation = pOUD & "_revE.pdf" fuFileToMove = pDXF & "_revF.pdf" fuLocation = pOUD & "_revF.pdf" guFileToMove = pDXF & "_revG.pdf" guLocation = pOUD & "_revG.pdf" huFileToMove = pDXF & "_revH.pdf" huLocation = pOUD & "_revH.pdf" iuFileToMove = pDXF & "_revI.pdf" iuLocation = pOUD & "_revI.pdf" juFileToMove = pDXF & "_revJ.pdf" juLocation = pOUD & "_revJ.pdf" kuFileToMove = pDXF & "_revK.pdf" kuLocation = pOUD & "_revK.pdf" luFileToMove = pDXF & "_revL.pdf" luLocation = pOUD & "_revL.pdf" muFileToMove = pDXF & "_revM.pdf" muLocation = pOUD & "_revM.pdf" nuFileToMove = pDXF & "_revN.pdf" nuLocation = pOUD & "_revN.pdf" ouFileToMove = pDXF & "_revO.pdf" ouLocation = pOUD & "_revO.pdf" puFileToMove = pDXF & "_revP.pdf" puLocation = pOUD & "_revP.pdf" quFileToMove = pDXF & "_revQ.pdf" quLocation = pOUD & "_revQ.pdf" ruFileToMove = pDXF & "_revR.pdf" ruLocation = pOUD & "_revR.pdf" suFileToMove = pDXF & "_revS.pdf" suLocation = pOUD & "_revS.pdf" tuFileToMove = pDXF & "_revT.pdf" tuLocation = pOUD & "_revT.pdf" uuFileToMove = pDXF & "_revU.pdf" uuLocation = pOUD & "_revU.pdf" vuFileToMove = pDXF & "_revV.pdf" vuLocation = pOUD & "_revV.pdf" wuFileToMove = pDXF & "_revW.pdf" wuLocation = pOUD & "_revW.pdf" xuFileToMove = pDXF & "_revX.pdf" xuLocation = pOUD & "_revX.pdf" yuFileToMove = pDXF & "_revY.pdf" yuLocation = pOUD & "_revY.pdf" zuFileToMove = pDXF & "_revZ.pdf" zuLocation = pOUD & "_revZ.pdf" ' Check_Del_Move_File( pDXF & ".pdf", pOUD & ".pdf" ) ' use this instead of assign variables Check_Del_Move_File( noneFileToMove, noneLocation ) Check_Del_Move_File( none2FileToMove, none2Location ) Check_Del_Move_File( aFileToMove, aLocation ) Check_Del_Move_File( bFileToMove, bLocation ) Check_Del_Move_File( cFileToMove, cLocation ) Check_Del_Move_File( dFileToMove, dLocation ) Check_Del_Move_File( eFileToMove, eLocation ) Check_Del_Move_File( fFileToMove, fLocation ) Check_Del_Move_File( gFileToMove, gLocation ) Check_Del_Move_File( hFileToMove, hLocation ) Check_Del_Move_File( iFileToMove, iLocation ) Check_Del_Move_File( jFileToMove, jLocation ) Check_Del_Move_File( kFileToMove, kLocation ) Check_Del_Move_File( lFileToMove, lLocation ) Check_Del_Move_File( mFileToMove, mLocation ) Check_Del_Move_File( nFileToMove, nLocation ) Check_Del_Move_File( oFileToMove, oLocation ) Check_Del_Move_File( pFileToMove, pLocation ) Check_Del_Move_File( qFileToMove, qLocation ) Check_Del_Move_File( rFileToMove, rLocation ) Check_Del_Move_File( sFileToMove, sLocation ) Check_Del_Move_File( tFileToMove, tLocation ) Check_Del_Move_File( uFileToMove, uLocation ) Check_Del_Move_File( vFileToMove, vLocation ) Check_Del_Move_File( wFileToMove, wLocation ) Check_Del_Move_File( xFileToMove, xLocation ) Check_Del_Move_File( yFileToMove, yLocation ) Check_Del_Move_File( zFileToMove, zLocation ) Check_Del_Move_File( auFileToMove, auLocation ) Check_Del_Move_File( buFileToMove, buLocation ) Check_Del_Move_File( cuFileToMove, cuLocation ) Check_Del_Move_File( duFileToMove, duLocation ) Check_Del_Move_File( euFileToMove, euLocation ) Check_Del_Move_File( fuFileToMove, fuLocation ) Check_Del_Move_File( guFileToMove, guLocation ) Check_Del_Move_File( huFileToMove, huLocation ) Check_Del_Move_File( iuFileToMove, iuLocation ) Check_Del_Move_File( juFileToMove, juLocation ) Check_Del_Move_File( kuFileToMove, kuLocation ) Check_Del_Move_File( luFileToMove, luLocation ) Check_Del_Move_File( muFileToMove, muLocation ) Check_Del_Move_File( nuFileToMove, nuLocation ) Check_Del_Move_File( ouFileToMove, ouLocation ) Check_Del_Move_File( puFileToMove, puLocation ) Check_Del_Move_File( quFileToMove, quLocation ) Check_Del_Move_File( ruFileToMove, ruLocation ) Check_Del_Move_File( suFileToMove, suLocation ) Check_Del_Move_File( tuFileToMove, tuLocation ) Check_Del_Move_File( uuFileToMove, uuLocation ) Check_Del_Move_File( vuFileToMove, vuLocation ) Check_Del_Move_File( wuFileToMove, wuLocation ) Check_Del_Move_File( xuFileToMove, xuLocation ) Check_Del_Move_File( yuFileToMove, yuLocation ) Check_Del_Move_File( zuFileToMove, zuLocation ) ' *** end of suggestion End Sub Public Sub Export() 'aPath = ThisDoc.Path aPath = RuleArguments("aPath") ' *** my correction iPropParNum = iProperties.Value("Project", "Part Number") iPropRevNum = iProperties.Value("Project", "Revision Number") aPDF = ThisApplication.ApplicationAddIns.ItemById _ ("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}") aDocument = ThisApplication.ActiveDocument aContext = ThisApplication.TransientObjects.CreateTranslationContext aContext.Type = IOMechanismEnum.kFileBrowseIOMechanism aPDFOptions = ThisApplication.TransientObjects.CreateNameValueMap aDataMedium = ThisApplication.TransientObjects.CreateDataMedium aFolder = aPath & "\" & "DXF" bFolder = aPath & "\" & "oud" aDataMedium.FileName = aFolder & "\" & iPropParNum & " rev" & iPropRevNum & ".pdf" aName = aDataMedium.FileName ' *** this variable is not used *** If aPDF.HasSaveCopyAsOptions(aDataMedium, aContext, aPDFOptions) Then aPDFOptions.Value("All_Color_AS_Black") = 1 aPDFOptions.Value("Remove_Line_Weights") = 1 aPDFOptions.Value("Vector_Resolution") = 4800 aPDFOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets End If aPDF.SaveCopyAs(aDocument, aContext, aPDFOptions, aDataMedium) ' *** the follow code has been adapted on my suggested subroutines Check_Del_File(aFolder & "\" & iPropRevNum & ".pdf", aFolder & "\" & iPropRevNum & ".pdf") Check_Del_File(aFolder & "\" & " rev" & iPropRevNum & ".pdf", aFolder & "\" & " rev" & iPropRevNum & ".pdf") Check_Del_File(aFolder & "\" & " rev" & ".pdf", aFolder & "\" & " rev" & ".pdf") Check_Move_File(aFolder & "\" & iPropParNum & " rev" & ".pdf", _ aFolder & "\" & iPropParNum & " rev" & ".pdf", aFolder & "\" & iPropParNum & ".pdf") Check_Move_File(aFolder & "\" & iPropParNum & " rev-" & ".pdf", _ aFolder & "\" & iPropParNum & " rev-" & ".pdf", aFolder & "\" & iPropParNum & ".pdf" ) Check_Del_File(aFolder & "\" & iPropParNum & ".pdf", bFolder & "\" & iPropParNum & ".pdf" ) Check_Del_File(aFolder & "\" & iPropParNum & " rev" & iPropRevNum & ".pdf", _ bFolder & "\" & iPropParNum & " rev" & iPropRevNum & ".pdf" ) End Sub Sub Check_Del_File(oExist As String, oDelete As String) ' my suggestion ' Try If System.IO.File.Exists(oExist) = True Then System.IO.File.Delete(oDelete) End If ' is a good practice to add an error control code ' Catch e As Exception ' MsgBox("The process failed: {0}", e.ToString()) ' End Try End Sub Sub Check_Move_File(oFileToMove As String, oLocation As String) ' my suggestion ' Try If System.IO.File.Exists(oFileToMove) = True Then System.IO.File.Move(oFileToMove, oLocation) End If ' is a good practice to add an error control code ' Catch e As Exception ' MsgBox("The process failed: {0}", e.ToString()) ' End Try End Sub Sub Check_Del_Move_File(oFileToMove As String, oLocation As String) ' my suggestion ' Try If System.IO.File.Exists(oFileToMove) = True Then System.IO.File.Delete(oLocation) System.IO.File.Move(oFileToMove, oLocation) End If ' is a good practice to add an error control code ' Catch e As Exception ' MsgBox("The process failed: {0}", e.ToString()) ' End Try End Sub Public Sub Message() 'aPath = ThisDoc.Path 'aFolder = aPath & "\" & "DXF" aFolder = RuleArguments("aPath") & "\" & "DXF" ' *** my correction iPropParNum = iProperties.Value("Project", "Part Number") iPropRevNum = iProperties.Value("Project", "Revision Number") aDataMedium = ThisApplication.TransientObjects.CreateDataMedium aDataMedium.FileName = aFolder & "\" & iPropParNum & " rev" & iPropRevNum & ".pdf" aName = aDataMedium.FileName ' I don't think you need this line ' *** this condition don't do nothing, may be contain an error*** If iPropRevNum = "" Then aName = aFolder & "\" & iPropParNum & ".pdf" Else If iPropRevNum = "-" Then aName = aFolder & "\" & iPropParNum & ".pdf" End If ' *** If Not aName = aFolder & "\" & ".pdf" Then question = MessageBox.Show("Het bestand is opgeslagen in " & aName _ & vbNewLine _ & vbNewLine & "Bestand openen?" , "Opgeslagen",MessageBoxButtons.YesNo,MessageBoxIcon.Question) If question = vbYes Then ThisDoc.Launch(aName) End If End If End Sub
Please let me know if you have troubles with this code.
Bregs
Rossano Praderi
Rossano Praderi,
I appreciate the time and effort you're taking to help me. Right now I am busy with other things at work, but I will have a good look at your comment this week! Just letting you know.
Thanks
I tried it out but without success. If we could break it down in to opening drawings and exporting PDF's that would be easier for me to follow.
Well, i tried your rules but it only opens the models, not the drawings. And of course i tried to get it to work, but without any success. I've made some parts, assemblies and drawings with the rules in them, for you. I've made it so that it opens the models correctly but nothing more. If you could help me understand how to open the drawings that'd be great.
Thanks!
I'm sorry if my English isn't always accurate.
Hi Stan,
thank you for give me these files, now I can test the code.
In my last post I haven't checked the rule for which kind of document would be open. I thought this part of code should be correct.
Of course you english is better than my.
Bregs
Rossano Praderi
Hi Stan,
this is your code, you have to make some modifications on the external rule "Export - Pdf in assembly".
With this rule you can open all the connected .idw, is a good idea to check if the file exist before launch it (this is missed in your code).
Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument Dim oRefDocs As DocumentsEnumerator = oAsmDoc.AllReferencedDocuments 'the following two lines are necessary to pass arguments to the external rule 'Dim map As Inventor.NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap() 'map.Add("aPath", ThisDoc.Path) 'map.Add("aFullFileName", "") For Each oOcc In oRefDocs ' open the .idw of each referenced document ThisDoc.Launch(oOcc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value & ".idw") 'ThisDoc.Launch(ThisDoc.Path & "\" & oOcc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value & ".idw") ' with fullpath ' Here you can run your PDF rule (remember to pass the fullfilename of your .idw as argument) ' your external "open" rule is unnecessary Next
Bregs
Rossano Praderi
Awesome, that works great!
This is what I did; i stripped it down to this code (because I like to keep it simple):
Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument Dim oRefDocs As DocumentsEnumerator = oAsmDoc.AllReferencedDocuments Dim map As Inventor.NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap() map.Add("aPath", ThisDoc.Path) For Each oOcc In oRefDocs ThisDoc.Launch(oOcc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value & ".idw") iLogicVb.RunRule("PDF", map) Next
and this one for PDF export:
aPath = RuleArguments("aPath") aDocument = ThisApplication.ActiveDocument iPropParNum = iProperties.Value("Project", "Part Number") iPropRevNum = iProperties.Value("Project", "Revision Number") aPDF = ThisApplication.ApplicationAddIns.ItemById _ ("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}") aContext = ThisApplication.TransientObjects.CreateTranslationContext aContext.Type = IOMechanismEnum.kFileBrowseIOMechanism aPDFOptions = ThisApplication.TransientObjects.CreateNameValueMap aDataMedium = ThisApplication.TransientObjects.CreateDataMedium aFolder = aPath & "\DXF" bFolder = aPath & "\oud" aDataMedium.FileName = aFolder & "\" & iPropParNum & " rev" & iPropRevNum & ".pdf" If aPDF.HasSaveCopyAsOptions(aDataMedium, aContext, aPDFOptions) Then aPDFOptions.Value("All_Color_AS_Black") = 1 aPDFOptions.Value("Remove_Line_Weights") = 1 aPDFOptions.Value("Vector_Resolution") = 4800 aPDFOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets End If aPDF.SaveCopyAs(aDocument, aContext, aPDFOptions, aDataMedium)
It opens and generates the PDF correctly. Except, it doesn't save the PDF with the right part number. I've tried some things, but didn't succeed again 😞 . I'm really trying to understand it, but I'm new to it and it's still a bit complicated.
Thanks!
Hi Stan,
you didn't checked my last posts, if you will do it, you will find the solution.
Try this modifications.
map.Add("aPath", ThisDoc.Path)
map.Add("aFullFileName", "")
For Each oOcc In oRefDocs map.Value("aFullFileName")= oOcc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value & ".idw" ThisDoc.Launch(RuleArguments("aFullFilename")) iLogicVb.RunRule("PDF", map) Next
aPath = RuleArguments("aPath")
Dim aDocument As inventor._Document=ThisApplication.documents.itembyname(RuleArguments("aFullFileName"))
'aDocument = ThisApplication.ActiveDocument
iPropParNum = iProperties.Value("Project", "Part Number")
iPropRevNum = iProperties.Value("Project", "Revision Number")
I didn't check the rest of your code, if read carefully you will learn something new 🙂
Bregs
Rossano Praderi
Dshortway,
Thank you very much for taking the time, and you're a great teacher also haha. I do understand it now, first i wasn't sure how to handle the maps.
Thanks!
Stan
Hi, thanks for all great codes here.
I am working on creating a template for in.ex a HVAC Flange, that can be changed by using ilogic : if/elseif and True/False etc
But I have allready "standard" assemblys with idw drawings ready for the Flanges
I would like to add the possibility that when you choose one of the flanges, that the .idw file from the standard assembly will be opened (from outside project folder) and a pdf. will be generated and copied into my project folder with a new prefix in the filename.
in ex.
I have my ilogic configurator called:
L1234_000_Flange ø300.ipt
the .idw I want to copy from is named
_Flange ø300.idw
and I want the pdf to take the prefix on my configurator and add it to the pdf like this:
L1234_000_Flange ø300.pdf
and If i for some reason change the configurator it will delete the previous one and replace with new pdf
in.ex
L1234_000_Flange ø500.ipt
_Flange ø500.idw
to:
L1234_000_Flange ø500.pdf
Is this possible?