open drawing, apply ilogic (print pdf) then close

open drawing, apply ilogic (print pdf) then close

Anonymous
Not applicable
2,395 Views
16 Replies
Message 1 of 17

open drawing, apply ilogic (print pdf) then close

Anonymous
Not applicable

Hi,

 

Is there a way to open drawings, like batch print, trigger the ilogic code (print PDF) then close the drawings?

 

is there  a way to do this? I been using inventor drawing porter which is good for printing pdf but the PDF illogic code that I have is very specific, takes the first 7 letters and adds the sheet size and puts the pdf in the right place.  Drawing porter cant do this.

 

Thanks!

0 Likes
Accepted solutions (3)
2,396 Views
16 Replies
Replies (16)
Message 2 of 17

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi Joel.Manrique,

 

I created an iLogic Batch tool in the past that you can use for this, see this link:

https://forums.autodesk.com/t5/inventor-forum/any-way-to-automatically-update-all-related-drawings/m...

 

  1. You will add your rule to this file and name it with ***
  2. You might need to rewrite the rule to use ThisApplication.ActiveEditDocument rather than ThisApplication.ActiveDocument
  3. Also this is an Inventor 2015 file

post back if you can't get it to work.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

0 Likes
Message 3 of 17

Anonymous
Not applicable

Hi Curtis, it works but not quite....

 

it prints out the pdf but only produces one pdf and it overwrites it.

 

heres my ***autopdf illogic rule

 

 

Sub Main()
'get drawing border size
Dim drawingsize As String
drawingsize=ActiveSheet.Size
'get filename
Filename=ThisDoc.FileName(False)
'get drawing folder
pdffolder=Left(filename,3)
'get the drawing number
drawingnumber=Left(filename,8)
'set the drawing path
drawingpath="r:\eng\mecdata\mec_dwgs"
'drawingsize=InputBox("Enter The Drawing Size","Drawing Size",size)'MsgBox(drawingsize)

PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
oDocument = ThisApplication.ActiveEditDocument
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

If PDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
oOptions.Value("All_Colors_As_Black") = 1
oOptions.Value("Remove_Object_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

'Set the destination file name
oFolder = drawingpath & "\" & pdffolder & "\PDF\"
oDataMedium.FileName = drawingpath & "\" & pdffolder & "\PDF\" & drawingnumber & drawingsize & ".pdf" 


'Check for the DXF folder and create it if it does not exist
    If Not System.IO.Directory.Exists(oFolder) Then
        System.IO.Directory.CreateDirectory(oFolder)
    End If

'Publish document.
Call PDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
MsgBox ("PDF saved to: " & oDataMedium.FileName)
Shell("explorer.exe " & oFolder,vbNormalFocus)
End Sub

 

the outcome of the pdf goes here: R:\Eng\MecData\mec_dwgs\iLo\PDF then its illogic A.pdf its reading the file that I downloaded from you.  also the drawings doesn't close after the pdf is done.

 

 

 

0 Likes
Message 4 of 17

Curtis_Waguespack
Consultant
Consultant

Hi Joel.Manrique,

 

Try changing:

 

Filename=ThisDoc.FileName(False)

 

to:

 

 

text_string = ThisApplication.ActiveEditDocument.FullFileName
oPathArray = text_string.Split("\") 'split path using backslash
Filename = oPathArray(UBound(oPathArray)) 'use last item in array
Filename = Left(Filename,Len(Filename)-4) 'trim off extension

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

0 Likes
Message 5 of 17

Anonymous
Not applicable

Curtis, you are a genius!!

 

I knew it was something to that but I have no idea how to program..haha. One last question is that its taking your drawings size sheet..so the end result of my drawing is always A size instead of C,B,D how can I modify it to read the sheet size of the actual drawing?  Also is it possible to close the drawing after? (no big deal here I can do this manually :))

0 Likes
Message 6 of 17

Curtis_Waguespack
Consultant
Consultant

Hi Joel.Manrique,

 

I noticed the sheet size and  was just about to post this Smiley Wink

 

 

drawingsize= ActiveSheet.Size

 

if you're wanting to close the batch drawing you can edit the rule called "Batch Rule" and add this line to the very end

 

ThisDoc.Document.Close

 

but it'll throw an error, as iLogic is tied to the open document, there might be a better way, I'll try to look if I have time later.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

0 Likes
Message 7 of 17

Anonymous
Not applicable

what do I change this to?

 

drawingsize = ActiveSheet.Size

 

0 Likes
Message 8 of 17

Curtis_Waguespack
Consultant
Consultant

Hi Joel.Manrique,

 

oops, I got distracted when trying to reply earlier.

 

I meant to type,  change this:

 

'drawingsize=InputBox("Enter The Drawing Size","Drawing Size",size)'MsgBox(drawingsize)

 

to this:

 

drawingsize = ActiveSheet.Size

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

0 Likes
Message 9 of 17

Anonymous
Not applicable

Curtis,

 

Drawing size should be automatic based on the sheet size.

 

'drawingsize=InputBox("Enter The Drawing Size","Drawing Size",size)'MsgBox(drawingsize) - this code is asking me to put the drawing size which I wouldn't really know if I'm batch plotting a whole bunch.  or did I complete misunderstood what you ask me to do?

 

this is the new code..sstill not getting the active.sheet size

 

 

Sub Main()
'get drawing border size

'get filename
text_string = ThisApplication.ActiveEditDocument.FullFileName 
oPathArray = text_string.Split("\") 'split path using backslash 
Filename = oPathArray(UBound(oPathArray)) 'use last item in array 
Filename = Left(Filename,Len(Filename)-4) 'trim off extension'get drawing folder
pdffolder =Left(filename,3)
'get the drawing number
drawingnumber=Left(filename,3) & Mid(filename, 5,4)
'set the drawing path
drawingpath="r:\eng\mecdata\mec_dwgs"
drawingsize = ActiveSheet.Size
'MsgBox(drawingsize)
0 Likes
Message 10 of 17

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi Joel.Manrique,

 

ooops! I lied. Smiley Embarassed

 

drawingsize = ActiveSheet.Size is going to get the ActiveDocument Sheet size rather than the ActiveEditDocument sheet size. The ActiveDocument is the batch file the ActiveEditDocument is each of the files the batch is opening.

 

So .... try this:

 

SheetSizeEnum = ThisApplication.ActiveEditDocument.ActiveSheet.Size 

If SheetSizeEnum = 9987 Then
drawingsize = "A"
Else If SheetSizeEnum = 9988 Then
drawingsize = "B"
Else If SheetSizeEnum = 9989 Then
drawingsize = "C"
Else If SheetSizeEnum = 9990 Then
drawingsize = "D"
Else If SheetSizeEnum = 9991 Then
drawingsize = "E"
Else If SheetSizeEnum = 9992 Then
drawingsize = "F"
Else
drawingsize = ""
End If

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

also here's a list of all the sheet size enums in case you're using something other than those listed in my example:

 

k12x18InDrawingSheetSize 9999 12 in x 18 in (typically for architectural drawings).
k18x24InDrawingSheetSize 10000 18 in x 24 in (typically for architectural drawings).
k24x36InDrawingSheetSize 10001 24 in x 36 in (typically for architectural drawings).
k30x42InDrawingSheetSize 10003 30 in x 42 in (typically for architectural drawings).
k36x48InDrawingSheetSize 10002 36 in x 48 in (typically for architectural drawings).
k9x12InDrawingSheetSize 9998 9 in x 12 in (typically for architectural drawings). Default page orientation is Portrait.
kA0DrawingSheetSize 9993 A0 size (typically for metric units).
kA1DrawingSheetSize 9994 A1 size (typically for metric units).
kA2DrawingSheetSize 9995 A2 size (typically for metric units).
kA3DrawingSheetSize 9996 A3 size (typically for metric units).
kA4DrawingSheetSize 9997 A4 size (typically for metric units).
kADrawingSheetSize 9987 A size (typically for inch units).
kBDrawingSheetSize 9988 B size (typically for inch units).
kCDrawingSheetSize 9989 C size (typically for inch units).
kCustomDrawingSheetSize 9986 Custom size. Does (may) not fit one of the standard sizes.
kDDrawingSheetSize 9990 D size (typically for inch units).
kDefaultDrawingSheetSize 9985 Specifies the default setting. The more strongly typed value is the one returned in a query.
kEDrawingSheetSize 9991 E size (typically for inch units).
kFDrawingSheetSize 9992 F size (typically for inch units).

EESignature

0 Likes
Message 11 of 17

Anonymous
Not applicable

Hi Curtis,

 

Actually while I was waiting for your response. I did try

 

drawingsize = ThisApplication.ActiveEditDocument.ActiveSheet.Size

 

and it was giving me 9987 in the end..I'm like what on earth is 9987..haha.. Now I know..anyway, I really appreciate the quick response and all the help I got from you! Keep up the good work! Any tips for me on how to learn to start programming?

 

Cheers!!

Message 12 of 17

Curtis_Waguespack
Consultant
Consultant

Hi Joel.Manrique,

 

Doing what you're doing now is the a great way to get started.

 

As for finding some of the information on your own, you can search Inventor's API help files (see the image at this link). Often I search this forum to find a start, and then search the API help files to build on it.

 

http://inventortrenches.blogspot.com/2013/10/ilogic-how-to-learn-inventors.html

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

0 Likes
Message 13 of 17

Anonymous
Not applicable

Thanks Curtis,

 

The plot runs great now, but I was wondering if I can add the plot stamp, coz when it produces the pdf its not updating the plot stamp so I added this in front of the rule but doesn't seem to work... it works fine on its own (open one drawing run this plot rule) I have changed it to ACtiveEDITDocument too

 

'autoupdate plotstamp
Dim oTrans As Transaction
oTrans = ThisApplication.TransactionManager.StartTransaction( _
ThisApplication.ActiveEditDocument, "plot date")

Dim odrawdoc As DrawingDocument
odrawdoc = ThisApplication.ActiveEditDocument
customPropertySet = odrawdoc.PropertySets.Item("Inventor User Defined Properties")
Try
      prop = customPropertySet.Item("Plotdatestamp")
Catch
      customPropertySet.Add("", "Plotdatestamp")
End Try

Dim PlotDate As Date
PlotDate = Now

Dim PlotTime As String
PlotTime = Now.ToShortTimeString

Try
      prop = customPropertySet.Item("Plottimestamp")
Catch
      customPropertySet.Add("", "Plottimestamp")
End Try

iProperties.Value("Custom", "Plottimestamp") = PlotTime

iProperties.Value("Custom", "Plotdatestamp") = PlotDate

InventorVb.DocumentUpdate()(I'm trying to find if there is a ACTIVEEDITDOCUMENT?)

'get drawing border size
SheetSizeEnum = ThisApplication.ActiveEditDocument.ActiveSheet.Size 
If SheetSizeEnum = 9987 Then
drawingsize = "A"

 

0 Likes
Message 14 of 17

Curtis_Waguespack
Consultant
Consultant

Hi Joel.Manrique,

 

If I read correctly, you just need the update part of this? If so try this:

 

odrawdoc.Update

 

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

0 Likes
Message 15 of 17

Anonymous
Not applicable

doesn't work

 

here's the whole code, all is good but it still gives me OLD date and time.  I just want to refresh the time and date from the date the pdfs are made.

 

 

Sub Main()

'autoupdate plotstamp
Dim oTrans As Transaction
oTrans = ThisApplication.TransactionManager.StartTransaction( _
ThisApplication.ActiveEditDocument, "plot date")

Dim odrawdoc As DrawingDocument
odrawdoc = ThisApplication.ActiveEditDocument
customPropertySet = odrawdoc.PropertySets.Item("Inventor User Defined Properties")
Try
      prop = customPropertySet.Item("Plotdatestamp")
Catch
      customPropertySet.Add("", "Plotdatestamp")
End Try

Dim PlotDate As Date
PlotDate = Now

Dim PlotTime As String
PlotTime = Now.ToShortTimeString

Try
      prop = customPropertySet.Item("Plottimestamp")
Catch
      customPropertySet.Add("", "Plottimestamp")
End Try

iProperties.Value("Custom", "Plottimestamp") = PlotTime

iProperties.Value("Custom", "Plotdatestamp") = PlotDate

odrawdoc.Update

'get drawing border size
SheetSizeEnum = ThisApplication.ActiveEditDocument.ActiveSheet.Size 
If SheetSizeEnum = 9987 Then
drawingsize = "A"
Else If SheetSizeEnum = 9988 Then
drawingsize = "B"
Else If SheetSizeEnum = 9989 Then
drawingsize = "C"
Else If SheetSizeEnum = 9990 Then
drawingsize = "D"
Else If SheetSizeEnum = 9991 Then
drawingsize = "E"
Else If SheetSizeEnum = 9992 Then
drawingsize = "F"
Else
drawingsize = ""
End If
'get filename
text_string = ThisApplication.ActiveEditDocument.FullFileName 
oPathArray = text_string.Split("\") 'split path using backslash 
Filename = oPathArray(UBound(oPathArray)) 'use last item in array 
Filename = Left(Filename,Len(Filename)-4) 'trim off extension'get drawing folder
pdffolder =Left(filename,3)
'get the drawing number
drawingnumber=Left(filename,3) & Mid(filename, 5,4)
'set the drawing path
drawingpath="r:\eng\mecdata\mec_dwgs"
'drawingsize = ActiveSheet.Size'MsgBox(drawingsize)

PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
oDocument = ThisApplication.ActiveEditDocument
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

If PDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
oOptions.Value("All_Colors_As_Black") = 1
oOptions.Value("Remove_Object_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

'Set the destination file name
oFolder = drawingpath & "\" & pdffolder & "\PDF\"
oDataMedium.FileName = drawingpath & "\" & pdffolder & "\PDF\" & drawingnumber & drawingsize & ".pdf" 


'Check for the DXF folder and create it if it does not exist
    If Not System.IO.Directory.Exists(oFolder) Then
        System.IO.Directory.CreateDirectory(oFolder)
    End If

'Publish document.
Call PDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)

End Sub

 

0 Likes
Message 16 of 17

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi Joel.Manrique,

 

 

ahhh, I missed the way the iproperties were being set before. What you had was setting the iProperty in the batch file. Here's an updated version of the iPeoperty part

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

Sub Main()

'autoupdate plotstamp
Dim oTrans As Transaction
oTrans = ThisApplication.TransactionManager.StartTransaction( _
ThisApplication.ActiveEditDocument, "plot date")

Dim odrawdoc As DrawingDocument
odrawdoc = ThisApplication.ActiveEditDocument
customPropertySet = odrawdoc.PropertySets.Item("Inventor User Defined Properties")
Try
      oProp = customPropertySet.Item("Plotdatestamp")
Catch
      oProp = customPropertySet.Add("", "Plotdatestamp")
End Try

Dim PlotTime As String
PlotTime = Now.ToShortTimeString

oProp.Value = PlotTime

Try
      oProp = customPropertySet.Item("Plottimestamp")
Catch
      oProp = customPropertySet.Add("", "Plottimestamp")
End Try

Dim PlotDate As Date
PlotDate = Now

oProp.Value = PlotDate

odrawdoc.Update

'.... rest of the code here...

EESignature

Message 17 of 17

Anonymous
Not applicable

yay another kudos to you 🙂 🙂 🙂

 

Many Thanks!