Drawing Sheet Revision iLogic

Drawing Sheet Revision iLogic

Anonymous
Not applicable
2,363 Views
5 Replies
Message 1 of 6

Drawing Sheet Revision iLogic

Anonymous
Not applicable

I'm trying to generate a revision history of PDFs. I have everything working except I cant figure out how to access the sheet revision. Currently I'm accessing the document revision which I don't want.

 

What do I need to change in the code below?

 

SyntaxEditor Code Snippet

oPath = ThisDoc.Path
oFileName = ThisDoc.FileName(False) 'without extension
oRevNum = iProperties.Value("Project", "Revision Number")
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

'Define the drawing
Dim oDrawing As DrawingDocument
oDrawing = ThisDoc.Document

Dim oSheet As Sheet
Dim lPos As Long
Dim rPos As Long
Dim sLen As Long
Dim sSheetName As String
Dim iSheetNumber As Integer

'step through each drawing sheet
For Each oSheet In oDrawing.Sheets

'find the seperator in the sheet name:number
lPos = InStr(oSheet.Name, ":")
'find the number of characters in the sheet name
sLen = Len(oSheet.Name)
'find the sheet name
sSheetName = Left(oSheet.Name, lPos -1)
'find the sheet number
iSheetNumber = Right(oSheet.Name, sLen -lPos)

'set PDF Options
If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
oOptions.Value("All_Color_AS_Black") = 1
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Vector_Resolution") = 400
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintSheetRange
oOptions.Value("Custom_Begin_Sheet") = iSheetNumber
oOptions.Value("Custom_End_Sheet") = iSheetNumber
End If

'get PDF target folder path
oFolder = Left(oPath, InStrRev(oPath, "\")) & oFileName & " PDFs"

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


'Set the PDF target file name
oDataMedium.FileName = oFolder & "\" & sSheetName & " Rev" & oRevNum  & ".pdf"

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

Next

 

0 Likes
Accepted solutions (2)
2,364 Views
5 Replies
Replies (5)
Message 2 of 6

MechMachineMan
Advisor
Advisor

Haaaa....... "Sheet Revision" isn't accessible directly through API.

 

Only if you use your revision table set to "Entire Drawing" will the revision number iProperty update IN THE DRAWING FILE (which is currently what your code calls).

 

If you are using "Active Sheet" as the scope... you have to use a convoluted workaround:

      - Place/Use a textbox in your titleblock that contains the accurate sheet revision field

      - write iLogic to fetch the value from this textbox

      - Continue on with winning!

OR:

      - Find revision table on sheet through macro

      - Find the max value in your revision number column.

      - Continue on with winning!

 

Good luck!


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 3 of 6

Anonymous
Not applicable

Thanks for the reply. I'm glad it is possible. Am I right that the easier route would be going through the title block? I already have the current sheet revision displayed in the title block. I'm not sure how you would retrieve this value though. Right now that text box calls for the active sheet revision property. Could you shed some light on how to retrieve a text box value?

0 Likes
Message 4 of 6

MechMachineMan
Advisor
Advisor
Accepted solution

2 ways I know of.

 

1) Iterate through textboxes and pull value when you find the one named "Sheet Revision"

 

Function GetSheetRevision(oSheet As Sheet) As String
          oTitleblock = oSheet.Titleblock

           For Each oTextBox In oTitleBlock.Definition.Sketch.TextBoxes             
                    If oTextBox.Text = "<Sheet Revision>" Then
                                 oRev=oTitleBlock.GetResultText(oTextBox)
                    End If
           Next
           Return oRev
End Function

 

 

 

2) Directly call the textbox.

 

   'Change 58 to the integer matching what # the titleblock is in your titleblock definition. If tbdef doesnt change, this field should always pull correctly.

 

Function GetSheetRevision(oSheet As Sheet) As String
          oTitleblock = oSheet.Titleblock
          oRev=oTitleBlock.GetResultText(  _
                     oTitleBlock.Definition.Sketch.TextBoxes.Item(58))
          Return oRev
End Function

 

Tool to help with finding the textbox# that corresponds with sheet revision (if using method 2):

 

Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument

'might have to erase the error skip and debug manually if you are getting issues
On Error Resume Next 'oWrite = System.IO.File.CreateText("C:\Users\Desktop\Test.txt") ' Change the filename as you like For j=1 To oDoc.ActiveSheet.TitleBlock.Definition.Sketch.TextBoxes.Count oStr = oStr & j & ") " & oDoc.ActiveSheet.TitleBlock.Definition.Sketch.TextBoxes.Item(j).Text 'oWrite.WriteLine(j & ") " & oDoc.ActiveSheet.TitleBlock.Definition.Sketch.TextBoxes.Item(j).Text) Next MsgBox(oStr) 'oWrite.Close 'ThisDoc.Launch("C:\Users\Desktop\Test.txt")

 


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 5 of 6

Anonymous
Not applicable

Option 1 looks to be the easiest and most reliable route. I copied the code to the top of my rule and changed the output from oRev to oRevNum. But I get a error saying all other subs or functions must be after the sub main. I'm not familiar with functions or know much about C+ code. Where should this go?

0 Likes
Message 6 of 6

MechMachineMan
Advisor
Advisor
Accepted solution
Sub Main()
oPath = ThisDoc.Path oFileName = ThisDoc.FileName(False) 'without extension 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 'Define the drawing Dim oDrawing As DrawingDocument oDrawing = ThisDoc.Document Dim oSheet As Sheet Dim lPos As Long Dim rPos As Long Dim sLen As Long Dim sSheetName As String Dim iSheetNumber As Integer 'step through each drawing sheet For Each oSheet In oDrawing.Sheets 'find the seperator in the sheet name:number lPos = InStr(oSheet.Name, ":") 'find the number of characters in the sheet name sLen = Len(oSheet.Name) 'find the sheet name sSheetName = Left(oSheet.Name, lPos -1) 'find the sheet number iSheetNumber = Right(oSheet.Name, sLen -lPos) 'set PDF Options If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then oOptions.Value("All_Color_AS_Black") = 1 oOptions.Value("Remove_Line_Weights") = 1 oOptions.Value("Vector_Resolution") = 400 oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintSheetRange oOptions.Value("Custom_Begin_Sheet") = iSheetNumber oOptions.Value("Custom_End_Sheet") = iSheetNumber End If 'get PDF target folder path oFolder = Left(oPath, InStrRev(oPath, "\")) & oFileName & " PDFs" 'Check for the PDF folder and create it if it does not exist If Not System.IO.Directory.Exists(oFolder) Then System.IO.Directory.CreateDirectory(oFolder) End If 'Set the PDF target file name oDataMedium.FileName = oFolder & "\" & sSheetName & " Rev" & GetSheetRevision(oSheet) & ".pdf" 'Publish document oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) Next End Sub

'In the same rule: paste sheet revision below here as it appears in option 1, except for the changes you made.
ie;

Function GetSheetRevision()
'''' Code here (replace titles also)
End Function

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type