Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic - Perform an action on all opened drawings ?

0 REPLIES 0
Reply
Message 1 of 1
Jhak
795 Views, 0 Replies

iLogic - Perform an action on all opened drawings ?

Hello,

 

We use an iLogic rule triggered by a shortcut (through a macro) in order to create PDF versions of our drawings with a tuned file name that includes the revision number. That actually works pretty well, thanks to you all for having shared your codes, ideas and solutions. I didn't kno anything about VBA and iLogic rules and it took me just one day to code the Rule (see at the end of this message, I added some little things that I haven't seen here).

 

I have one last things I would very much like to add to the code : I would like to be able to burn a PDF for each drawing open. In other words, at the end of the modification of an assembly, I would like to be able to create the revised PDF drawing in one click (or shortcut), provided I have already opened all the document I want to be converted and closed any other file.

 

Any ideas ? I don't know if it is possible to do that within the iLogic rule, or if I have to use a macro, or ... ?

 

Thank you very much in advance and please excuse my english, I am not a native speaker 😉

 

'Debugging
   'Check if the active document is a drawing or a model, end the rule if it is not a drawing
   Dim OpenDoc As Document
   OpenDoc = ThisDoc.Document
   Dim docfile As Document

   If OpenDoc.DocumentType = 12291 Then  '------12291 = IAM
     MessageBox.Show("It is forbidden to perform this action with a model", _
     "iLogic", MessageBoxButtons.OK)
	 Return
     Else
   End If
   '
   If OpenDoc.DocumentType = 12290 Then  '------12290 = IPT
     MessageBox.Show("It is forbidden to perform this action with a model", _
     "iLogic", MessageBoxButtons.OK)
     Return
     Else
   End If

   'Look for the model referenced within the drawing. End the Rule if the drawing is empty.
   Dim MDocFile As Document
   If ThisDoc.ModelDocument IsNot Nothing Then
     MDocFile = ThisDoc.ModelDocument
     Else
     MessageBox.Show("It is forbiden to perform this action with en empty _ drawing", "iLogic")
     Return
   End If

'Formate model file name
  Dim FNamePos As Long
  FNamePos = InStrRev(MDocFile.FullFileName, "\", -1)                
  Dim docFName As String 
  docFName = Right(MDocFile.FullFileName, Len(MDocFile.FullFileName) - FNamePos) 

‘Transfer the revision number from the model to the drawing.
 If iProperties.Value(docFName, "Project", "Revision Number") Is "" Then
   MessageBox.Show("Model" & docFname & _
   " does not have a revision number, unable to perform action", _
   "iLogic", MessageBoxButtons.OK)
   Return
   Else
   iProperties.Value("Project", "Revision Number") = iProperties.Value(docFName, _
   "Project", "Revision Number")
 End If
 
 ' Check if the drawing has already been saved at least one time, by checking if the field Part Number if populated
 If iProperties.Value("project", "Part Number") Is "" Then
    MessageBox.Show("You must save this file before performing this action", _
	"iLogic", MessageBoxButtons.OK)
	Return
	Else
 End If
	
'Misc
  oRevNum = iProperties.Value("Project", "Revision Number")
  oFileName = ThisDoc.FileName(False) 'sans extention
  oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _
  ("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
  oDocument = ThisApplication.ActiveDocument
  oContext = ThisApplication.TransientObjects.CreateTranslationContext
  oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
  oOptions = ThisApplication.TransientObjects.CreateNameValueMap
  oDataMedium = ThisApplication.TransientObjects.CreateDataMedium 

If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
  oOptions.Value("All_Color_AS_Black") = 0
  oOptions.Value("Remove_Line_Weights") = 0
  oOptions.Value("Vector_Resolution") = 400
  oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
  'oOptions.Value("Custom_Begin_Sheet") = 2
  'oOptions.Value("Custom_End_Sheet") = 4
End If


'Acquire PDF file destination folder
  oFolder = "X:\you path"

 'Format PDF file name
  oDataMedium.FileName = oFolder & oFileName & _
  " - Rev" & oRevNum & ".pdf"

'Publication
  oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)

'confirmation message
  MessageBox.Show("PDF created : " & oDataMedium.FileName ,"DONE", _
  MessageBoxButtons.OK)

 

Tags (3)
0 REPLIES 0

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

Post to forums  

Autodesk Design & Make Report