Run Rule on all open drawings

Run Rule on all open drawings

donaldleigh
Advocate Advocate
1,806 Views
16 Replies
Message 1 of 17

Run Rule on all open drawings

donaldleigh
Advocate
Advocate

Hi all

 

I have the below rule to print PDFs of all open drawings.

 

This works perfect but I would like to be able to run an external rule on each drawing before the PDF is made.

 

Can anyone help me out please.

 

I run 2014

 

SyntaxEditor Code Snippet

Dim oDoc As Inventor.Document
For Each oDoc In ThisApplication.Documents.VisibleDocuments

     If (oDoc.documenttype = kDrawingDocumentObject) Then 'Found a drawing
        'find the postion of the last backslash in the path
    oFNamePos = InStrRev(oDoc.fullfileName, "\", -1)   
    'get the file name with the file extension
    oName = Right(oDoc.fullfileName, Len(oDoc.fullfileName) - oFNamePos)
    'get the path of the folder containing the file
    oPath = Left(oDoc.fullfileName, Len(oDoc.fullfileName) - Len(oName))
     'get the file name (without extension)
    oRevNum = oDoc.PropertySets("Inventor Summary Information")("Revision Number").Value
    If oRevNum <> 0 Then
        oShortName = Left(oName, Len(oName) - 4) & " - Rev " & oRevNum
    Else
        oShortName = Left(oName, Len(oName) - 4)
    End If
    
    oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _
    ("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
    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") = 600
    oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
    'oOptions.Value("Custom_Begin_Sheet") = 2
    'oOptions.Value("Custom_End_Sheet") = 4
    End If
    
    'get PDF target folder path
    oFolder = oPath & "\PDF"
    
    '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 & "\" & oShortName & ".pdf"

    
    On Error Goto handlePDFLock
    
    'Publish document
    oPDFAddIn.SaveCopyAs(oDoc, oContext, oOptions, oDataMedium)
      End If
Next oDoc

'Show message box
MessageBox.Show("PDF(s) exported to: " & oFolder , "iLogic") 
'--------------------------------------------------------------------------------

Exit Sub

handlePDFLock:MessageBox.Show("At least one PDF could not be saved, " _
& "most likely someone else has it open.", _
"No PDF for you " & ThisApplication.GeneralOptions.UserName & "!")
Resume Next
0 Likes
1,807 Views
16 Replies
Replies (16)
Message 2 of 17

Martin-Winkler-Consulting
Advisor
Advisor

Hi @donaldleigh

which content should be in the external rule you will run before?

For example you can create an additional rule and run it before you use your pdf export rule, or put in an additional For Each ...next before the pdf For each beginns:

 

For Each oDoc In ThisApplication.Documents.VisibleDocuments
 If (oDoc.documenttype = kDrawingDocumentObject) Then
  ' actions you will do before
 End if
Next oDoc

Martin Winkler
CAD Developer
Did you find this post helpful? Feel free to like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


EESignature

Message 3 of 17

MechMachineMan
Advisor
Advisor

The existing documentation is great for this.

 

http://lmgtfy.com/?q=iLogic+%2B+run+external+rule

 

Also, you need to make sure any rule you run with this is coded properly. If any have "ThisApplication.ActiveDocument" thing will likely run weird and unexpected. Instead, you should use ThisDoc.Document or ThisApplication.ActiveEditDocument

 

Sub Main()
	Dim oDoc As Inventor.Document
	For Each oDoc In ThisApplication.Documents.VisibleDocuments
	
		If (oDoc.documenttype = kDrawingDocumentObject) Then 'Found a drawing
			'find the postion of the last backslash in the path
			
			'INSERT CODE HERE TO RUN EXTERNAL RULE
			'iLogicVb.RunExternalRule("ruleFileName")
			
			oFNamePos = InStrRev(oDoc.fullfileName, "\", -1)   
			'get the file name with the file extension
			oName = Right(oDoc.fullfileName, Len(oDoc.fullfileName) - oFNamePos)
			'get the path of the folder containing the file
			oPath = Left(oDoc.fullfileName, Len(oDoc.fullfileName) - Len(oName))
			'get the file name (without extension)
			oRevNum = oDoc.PropertySets("Inventor Summary Information")("Revision Number").Value
			
			If oRevNum <> 0 Then
				oShortName = Left(oName, Len(oName) - 4) & " - Rev " & oRevNum
			Else
				oShortName = Left(oName, Len(oName) - 4)
			End If
		
			oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _
			("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
			oContext = ThisApplication.TransientObjects.CreateTranslationContext
			oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
			oOptions = ThisApplication.TransientObjects.CreateNameValueMap
			oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
			
			If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
			'If oPDFAddIn.HasSaveCopyAsOptions(oDoc, oContext, oOptions) Then 'If using 2018 or newer.
			
				'oOptions.Value("All_Color_AS_Black") = 0
				'oOptions.Value("Remove_Line_Weights") = 0
				oOptions.Value("Vector_Resolution") = 600
				oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
			'oOptions.Value("Custom_Begin_Sheet") = 2
			'oOptions.Value("Custom_End_Sheet") = 4
			End If
			
			'get PDF target folder path
			oFolder = oPath & "\PDF"
			
			'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 & "\" & oShortName & ".pdf"
			
			
			On Error Goto handlePDFLock
			
			'Publish document
			oPDFAddIn.SaveCopyAs(oDoc, oContext, oOptions, oDataMedium)
		End If
	Next oDoc
	
	'Show message box
	MessageBox.Show("PDF(s) exported to: " & oFolder , "iLogic") 
	'--------------------------------------------------------------------------------
	
	Exit Sub
	
handlePDFLock:MessageBox.Show("At least one PDF could not be saved, " _
	& "most likely someone else has it open.", _
	"No PDF for you " & ThisApplication.GeneralOptions.UserName & "!")
	Resume Next
End Sub

 


--------------------------------------
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 4 of 17

donaldleigh
Advocate
Advocate

Hi Justin

 

I had tried putting that line of code in exactly where you had it before posting here yesterday but that didn't work.

 

the rule I'm running is to update the mass on each drawing as we as always getting N/A for the mass

 

Here is that rule below

 

I have tried to change the first 2 lines of code as you stated but that causes this rule to fail.

 

SyntaxEditor Code Snippet

'For several parts in drawing environment'update mass to avoid the "N/A" in title block
Dim oApp As Application: oApp = ThisApplication
Dim oDoc As DrawingDocument:  oDoc = oApp.ActiveDocument
Dim oSheets As Sheets
Dim oSheet As Sheet
Dim oViews As DrawingViews
Dim oView As DrawingView
oSheets = oDoc.Sheets
For Each oSheet In oSheets
    oViews = oSheet.DrawingViews
    For Each oView In oViews
        modelName =  oView.ReferencedDocumentDescriptor.ReferencedDocument.DisplayName
        iProperties.Mass(modelName) = 1 'override automatic calculation
        iProperties.Mass(modelName) = -1 'set it back to automatic calculation
        mass = iProperties.Mass(modelName) 'force to read the property
    Next
Next
InventorVb.DocumentUpdate() 'update drawing 

.  

0 Likes
Message 5 of 17

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @donaldleigh,

 

Can you please provide sample drawing file to test? Please make sure that information is non confidential.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 6 of 17

donaldleigh
Advocate
Advocate

Hi Chandra

 

I could send something through but the chances of the drawing showing the mass as N/A would not work I think. as it would be updated once you open it.

 

The mass appears as N/A have a change has been made to a part inside an assembly that has a drawing.

 

IE.

 

Assembly 1 has parts 1 and 2 inside

 

Drawing is of Assembly 1

 

If you change one of the parts without updating the assembly while the drawing is open the mass will read as N/A.

 

The 2nd rule above will update the mass via the drawing and works well. I just need to be able to either add the 2nd rule to the 1st so it updates all open drawings or have a line of code that will run the 2nd rule from within the 1st

 

Donald

0 Likes
Message 7 of 17

MechMachineMan
Advisor
Advisor

Also, probably just add oDoc.Activate before the iLogicvb.RunExternal rule line in the other chunk....

 

...

 

'For several parts in drawing environment'update mass to avoid the "N/A" in title block
Dim oDoc As DrawingDocument:  oDoc = ThisDoc.Document
Dim oSheets As Sheets
Dim oSheet As Sheet
Dim oViews As DrawingViews
Dim oView As DrawingView
oSheets = oDoc.Sheets
For Each oSheet In oSheets
    oViews = oSheet.DrawingViews
    For Each oView In oViews
        modelName =  oView.ReferencedDocumentDescriptor.ReferencedDocument.DisplayName
        iProperties.Mass(modelName) = 1 'override automatic calculation
        iProperties.Mass(modelName) = -1 'set it back to automatic calculation
        mass = iProperties.Mass(modelName) 'force to read the property
    Next
Next
InventorVb.DocumentUpdate() 'update drawing  

 

 

 


--------------------------------------
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 8 of 17

donaldleigh
Advocate
Advocate

Hi Justin

 

I can get the PDF rule to run with no errors but the mass is not updating for each drawing

 

Is this because i'm trying to run the Mass rule within the PDF rule when its using this line of code 1st???

 

SyntaxEditor Code Snippet

Dim oDoc As Inventor.Document
    For Each oDoc In ThisApplication.Documents.VisibleDocuments

I'm thinking because each drawing is open in the background the mass rule is not running at all.

 

This make sense I hope.

 

Donald

0 Likes
Message 9 of 17

donaldleigh
Advocate
Advocate

this didn't not work also Smiley Sad

 

 

0 Likes
Message 10 of 17

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @donaldleigh,

 

Is oDoc is activated for before calling external rule?

 

@MechMachineMan suggested to oDoc.Activate before calling external rule.

 

Sub Main()
	Dim oDoc As Inventor.Document
	For Each oDoc In ThisApplication.Documents.VisibleDocuments
	
		If (oDoc.documenttype = kDrawingDocumentObject) Then 'Found a drawing
			'find the postion of the last backslash in the path

oDoc.Activate 'INSERT CODE HERE TO RUN EXTERNAL RULE 'iLogicVb.RunExternalRule("ruleFileName") oFNamePos = InStrRev(oDoc.fullfileName, "\", -1) 'get the file name with the file extension oName = Right(oDoc.fullfileName, Len(oDoc.fullfileName) - oFNamePos) 'get the path of the folder containing the file oPath = Left(oDoc.fullfileName, Len(oDoc.fullfileName) - Len(oName)) 'get the file name (without extension) oRevNum = oDoc.PropertySets("Inventor Summary Information")("Revision Number").Value If oRevNum <> 0 Then oShortName = Left(oName, Len(oName) - 4) & " - Rev " & oRevNum Else oShortName = Left(oName, Len(oName) - 4) End If oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _ ("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}") oContext = ThisApplication.TransientObjects.CreateTranslationContext oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism oOptions = ThisApplication.TransientObjects.CreateNameValueMap oDataMedium = ThisApplication.TransientObjects.CreateDataMedium If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then 'If oPDFAddIn.HasSaveCopyAsOptions(oDoc, oContext, oOptions) Then 'If using 2018 or newer. 'oOptions.Value("All_Color_AS_Black") = 0 'oOptions.Value("Remove_Line_Weights") = 0 oOptions.Value("Vector_Resolution") = 600 oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets 'oOptions.Value("Custom_Begin_Sheet") = 2 'oOptions.Value("Custom_End_Sheet") = 4 End If 'get PDF target folder path oFolder = oPath & "\PDF" '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 & "\" & oShortName & ".pdf" On Error Goto handlePDFLock 'Publish document oPDFAddIn.SaveCopyAs(oDoc, oContext, oOptions, oDataMedium) End If Next oDoc 'Show message box MessageBox.Show("PDF(s) exported to: " & oFolder , "iLogic") '-------------------------------------------------------------------------------- Exit Sub handlePDFLock:MessageBox.Show("At least one PDF could not be saved, " _ & "most likely someone else has it open.", _ "No PDF for you " & ThisApplication.GeneralOptions.UserName & "!") Resume Next End Sub

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 11 of 17

donaldleigh
Advocate
Advocate

Hi Chandra

 

Thanks for your help but now when each drawing open on the screen the error come up that the .iam file was not found.

 

Error in rule: Update Mass, in document: 17093-01-05.idw

iProperties:The document named "General Arrangement.iam" was not found.

 

this happens for each drawing

 

Donald

0 Likes
Message 12 of 17

donaldleigh
Advocate
Advocate

OK I have the rule working now with no errors.

 

Needed to change the Update Mass rule as per Justins comment

 

Only issue now is if I have 3 Drawings open, Say "Drawing 1.idw", "Drawing 2.idw" and "Drawing 3.idw" and "Drawing 1.idw" is the active one open on the screen. and all have the mass shown as N/A. After running the PDF rule "Drawing 1.pdf" will have Mass correct but the others still show N/A on the PDF . But when I open the other 2 .idw drawings their mass has been updated.

 

here are both codes again

 

Thanks heaps once more

 

Print PDF

SyntaxEditor Code Snippet

Sub Main()
    Dim oDoc As Inventor.Document
    For Each oDoc In ThisApplication.Documents.VisibleDocuments
    
        If (oDoc.documenttype = kDrawingDocumentObject) Then 'Found a drawing
            
            oDoc.Activate
            
            'INSERT CODE HERE TO RUN EXTERNAL RULE
            iLogicVb.RunExternalRule("Update Mass")
            
            InventorVb.DocumentUpdate()

            'find the postion of the last backslash in the path
            oFNamePos = InStrRev(oDoc.fullfileName, "\", -1)   
            'get the file name with the file extension
            oName = Right(oDoc.fullfileName, Len(oDoc.fullfileName) - oFNamePos)
            'get the path of the folder containing the file
            oPath = Left(oDoc.fullfileName, Len(oDoc.fullfileName) - Len(oName))
            'get the file name (without extension)
            oRevNum = oDoc.PropertySets("Inventor Summary Information")("Revision Number").Value
            
            If oRevNum <> 0 Then
                oShortName = Left(oName, Len(oName) - 4) & " - Rev " & oRevNum
            Else
                oShortName = Left(oName, Len(oName) - 4)
            End If
        
            oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _
            ("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
            oContext = ThisApplication.TransientObjects.CreateTranslationContext
            oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
            oOptions = ThisApplication.TransientObjects.CreateNameValueMap
            oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
            
            If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
            'If oPDFAddIn.HasSaveCopyAsOptions(oDoc, oContext, oOptions) Then 'If using 2018 or newer.
            
                'oOptions.Value("All_Color_AS_Black") = 0
                'oOptions.Value("Remove_Line_Weights") = 0
                oOptions.Value("Vector_Resolution") = 600
                oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
            'oOptions.Value("Custom_Begin_Sheet") = 2
            'oOptions.Value("Custom_End_Sheet") = 4
            End If
            
            'get PDF target folder path
            oFolder = oPath & "\PDF"
            
            '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 & "\" & oShortName & ".pdf"
            
            
            On Error Goto handlePDFLock
                        
            'Publish document
            oPDFAddIn.SaveCopyAs(oDoc, oContext, oOptions, oDataMedium)
        End If
    Next oDoc
    
    'Show message box
    MessageBox.Show("PDF(s) exported to: " & oFolder , "iLogic") 
    '--------------------------------------------------------------------------------
    
    Exit Sub
    
handlePDFLock:MessageBox.Show("At least one PDF could not be saved, " _
    & "most likely someone else has it open.", _
    "No PDF for you " & ThisApplication.GeneralOptions.UserName & "!")
    Resume Next
End Sub

 

Update Mass

SyntaxEditor Code Snippet

'For several parts in drawing environment'update mass to avoid the "N/A" in title block
Dim oDoc As DrawingDocument:  oDoc = ThisDoc.Document
Dim oSheets As Sheets
Dim oSheet As Sheet
Dim oViews As DrawingViews
Dim oView As DrawingView
oSheets = oDoc.Sheets
For Each oSheet In oSheets
    oViews = oSheet.DrawingViews
    For Each oView In oViews
        modelName =  oView.ReferencedDocumentDescriptor.ReferencedDocument.DisplayName
        iProperties.Mass(modelName) = 1 'override automatic calculation
        iProperties.Mass(modelName) = -1 'set it back to automatic calculation
        mass = iProperties.Mass(modelName) 'force to read the property
    Next
Next
InventorVb.DocumentUpdate() 'update drawing

 

0 Likes
Message 13 of 17

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @donaldleigh,

 

Try the following changes in iLogic. Initially, update mass details for each document and then publish a pdf for each document.

 

Sub Main()
    Dim oDoc As Inventor.Document
    For Each oDoc In ThisApplication.Documents.VisibleDocuments
    
        If (oDoc.documenttype = kDrawingDocumentObject) Then 'Found a drawing
            
            oDoc.Activate
            
            'INSERT CODE HERE TO RUN EXTERNAL RULE
            iLogicVb.RunExternalRule("Update Mass")
            
            InventorVb.DocumentUpdate()
		
		End If

            
    Next oDoc
    
	PublishPDF()
    
End Sub

Sub PublishPDF()

    Dim oDoc As Inventor.Document
    For Each oDoc In ThisApplication.Documents.VisibleDocuments
    
        If (oDoc.documenttype = kDrawingDocumentObject) Then 'Found a drawing
            
            oDoc.Activate        
            
            'find the postion of the last backslash in the path
            oFNamePos = InStrRev(oDoc.fullfileName, "\", -1)   
            'get the file name with the file extension
            oName = Right(oDoc.fullfileName, Len(oDoc.fullfileName) - oFNamePos)
            'get the path of the folder containing the file
            oPath = Left(oDoc.fullfileName, Len(oDoc.fullfileName) - Len(oName))
            'get the file name (without extension)
            oRevNum = oDoc.PropertySets("Inventor Summary Information")("Revision Number").Value
            
            If oRevNum <> 0 Then
                oShortName = Left(oName, Len(oName) - 4) & " - Rev " & oRevNum
            Else
                oShortName = Left(oName, Len(oName) - 4)
            End If
        
            oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _
            ("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
            oContext = ThisApplication.TransientObjects.CreateTranslationContext
            oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
            oOptions = ThisApplication.TransientObjects.CreateNameValueMap
            oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
            
            If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
            'If oPDFAddIn.HasSaveCopyAsOptions(oDoc, oContext, oOptions) Then 'If using 2018 or newer.
            
                'oOptions.Value("All_Color_AS_Black") = 0
                'oOptions.Value("Remove_Line_Weights") = 0
                oOptions.Value("Vector_Resolution") = 600
                oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
            'oOptions.Value("Custom_Begin_Sheet") = 2
            'oOptions.Value("Custom_End_Sheet") = 4
            End If
            
            'get PDF target folder path
            oFolder = oPath & "\PDF"
            
            '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 & "\" & oShortName & ".pdf"
            
            
            On Error Goto handlePDFLock
                        
            'Publish document
            oPDFAddIn.SaveCopyAs(oDoc, oContext, oOptions, oDataMedium)
        End If
    Next oDoc
    
    'Show message box
    MessageBox.Show("PDF(s) exported to: " & oFolder , "iLogic") 
    '--------------------------------------------------------------------------------
    
    Exit Sub
    
handlePDFLock:MessageBox.Show("At least one PDF could not be saved, " _
    & "most likely someone else has it open.", _
    "No PDF for you " & ThisApplication.GeneralOptions.UserName & "!")
    Resume Next


End Sub

Thanks and regards,

 


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 14 of 17

donaldleigh
Advocate
Advocate

Hi Chandra

 

Sill not updating

 

I have even tried to have the update mass rule on all drawings open with out PDFing.

 

This didn't work also. It appears to open each drawing but will only update what ever drawing is open 1st when run. 

 

SyntaxEditor Code Snippet

Sub Main()
    Dim oDoc As Inventor.Document
    For Each oDoc In ThisApplication.Documents.VisibleDocuments
    
        If (oDoc.documenttype = kDrawingDocumentObject) Then 'Found a drawing
            oDoc.Activate
            
            'INSERT CODE HERE TO RUN EXTERNAL RULE
            iLogicVb.RunExternalRule("Update Mass")
            
            InventorVb.DocumentUpdate()
        
        End If
    
    Next oDoc
            
End Sub

I don't expect you to spend much more time on this please

 

Cheers

Donald

 

0 Likes
Message 15 of 17

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @donaldleigh,

 

Try the following changes in rule for updating mass property.

 

'For several parts in drawing environment'update mass to avoid the "N/A" in title block
Dim oDoc As DrawingDocument:  oDoc = ThisDoc.Document
Dim oSheets As Sheets
Dim oSheet As Sheet
Dim oViews As DrawingViews
Dim oView As DrawingView
oSheets = oDoc.Sheets
For Each oSheet In oSheets
    oViews = oSheet.DrawingViews
    For Each oView In oViews
        modelName =  oView.ReferencedDocumentDescriptor.ReferencedDocument.DisplayName
        iProperties.Mass(modelName) = 1 'override automatic calculation
        iProperties.Mass(modelName) = -1 'set it back to automatic calculation
ThisApplication.UserInterfaceManager.DoEvents() mass = iProperties.Mass(modelName) 'force to read the property Next Next InventorVb.DocumentUpdate() 'update drawing

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 16 of 17

donaldleigh
Advocate
Advocate

Hi Chandra

 

This didn't work also

 

I'm at the point where I feel like giving up.

 

The "PDF all Drawings Open" works and the "mass update" works on individual drawings but cant get the 2 working together

 

Cheers

0 Likes
Message 17 of 17

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @donaldleigh,

 

Try the following iLogic code to update mass and publish pdf individually. Here, all documents are closed and reopened except current drawing.

 

Unfortunately, the code is tested in Inventor 2017. Currently, Inventor 2014 is old version and unavailable to test.

 

Sub Main()
	Dim oDocList As New List(Of String)
	Dim currDoc as String 
	currDoc = ThisDoc.PathAndFileName(True)
    Dim oDoc As Inventor.Document
    For Each oDoc In ThisApplication.Documents.VisibleDocuments    
        If (oDoc.documenttype = kDrawingDocumentObject) Then 'Found a drawing
			If Not currDoc = oDoc.fullfileName Then
				oDocList.Add(oDoc.fullfileName)
				oDoc.Close
			Else
				
				iLogicVb.RunExternalRule("Update Mass")            
            	InventorVb.DocumentUpdate()
				
				PublishPDF()				
			End If			
		End If            
    Next 
	
	For i= 0 To oDocList.Count-1
		
		ThisDoc.Launch(oDocList(i))
		
		iLogicVb.RunExternalRule("Update Mass")            
        InventorVb.DocumentUpdate()
		
		PublishPDF()
		
	Next
End Sub

Sub PublishPDF()

    Dim oDoc As Inventor.Document
    oDOc = ThisApplication.ActiveDocument
    oDoc.Activate        
    
    'find the postion of the last backslash in the path
    oFNamePos = InStrRev(oDoc.fullfileName, "\", -1)   
    'get the file name with the file extension
    oName = Right(oDoc.fullfileName, Len(oDoc.fullfileName) - oFNamePos)
    'get the path of the folder containing the file
    oPath = Left(oDoc.fullfileName, Len(oDoc.fullfileName) - Len(oName))
    'get the file name (without extension)
    oRevNum = oDoc.PropertySets("Inventor Summary Information")("Revision Number").Value
    
    If oRevNum <> 0 Then
        oShortName = Left(oName, Len(oName) - 4) & " - Rev " & oRevNum
    Else
        oShortName = Left(oName, Len(oName) - 4)
    End If

    oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _
    ("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
    oContext = ThisApplication.TransientObjects.CreateTranslationContext
    oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
    oOptions = ThisApplication.TransientObjects.CreateNameValueMap
    oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
    
    If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
    'If oPDFAddIn.HasSaveCopyAsOptions(oDoc, oContext, oOptions) Then 'If using 2018 or newer.
    
        'oOptions.Value("All_Color_AS_Black") = 0
        'oOptions.Value("Remove_Line_Weights") = 0
        oOptions.Value("Vector_Resolution") = 600
        oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
    'oOptions.Value("Custom_Begin_Sheet") = 2
    'oOptions.Value("Custom_End_Sheet") = 4
    End If
    
    'get PDF target folder path
    oFolder = oPath & "\PDF"
    
    '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 & "\" & oShortName & ".pdf"
        
        
        On Error Goto handlePDFLock
                    
        'Publish document
        oPDFAddIn.SaveCopyAs(oDoc, oContext, oOptions, oDataMedium)
    End If
   
    
    'Show message box
    MessageBox.Show("PDF(s) exported to: " & oFolder , "iLogic") 
    

End Sub

Please feel free to contact if there is any queries.

 

If solves problem, click on "Accept as solution" / give a "Kudo".

 

Thanks and regards,

 

 

 

 

 


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes