Skip to content

Commit 2b33d5f

Browse files
committed
Update IDW_Export_PDF + DXF.iLogicVB
1 parent 10bd30d commit 2b33d5f

File tree

1 file changed

+142
-8
lines changed

1 file changed

+142
-8
lines changed

Scripts/IDW_Export_PDF + DXF.iLogicVB

Lines changed: 142 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
Imports system.Windows.Forms
22
' Title: Export Drawings To PDF + DXF
33
' Description: This exports drawings to PDF + DXF
4-
' Version: 0.2
4+
' Version: 0.3
55

66
' Notes:
77
' Export folders can be set below strFolderPDF & strFolderDXF
88

99
Sub Main()
10-
10+
1111
' Check active document is a drawing
1212
If ThisApplication.ActiveDocumentType <> Inventor.DocumentTypeEnum.kDrawingDocumentObject Then
1313
MessageBox.Show("A drawing document need to be active", "Document Print Error") : Exit Sub
@@ -26,12 +26,16 @@ Sub Main()
2626
' Get active document
2727
Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
2828

29-
' Check if there is a referenced model, update mass if there is (prevents an error on sheets with no model)
30-
If oDoc.ReferencedDocuments.Count > 1 Then
31-
' Read the mass to prevent N/A issue / triggers generation of mass (This will crash on a presentation file)
32-
Dim oMassStr As String = Round(ThisDrawing.ModelDocument.ComponentDefinition.MassProperties.Mass, 0)
33-
' Update to trigger the change in the drawing
34-
InventorVb.DocumentUpdate()
29+
' Update mass
30+
If UpdateMass(oDoc) = False Then
31+
MessageBox.Show("There was an error updating the mass","Mass Update")
32+
Exit Sub
33+
End If
34+
35+
' Update all views / check for raster views
36+
If UpdateAllViews(oDoc) = False Then
37+
MessageBox.Show("There was an error updating the drawings views","View Update")
38+
Exit Sub
3539
End If
3640

3741
' Get path + filename
@@ -171,6 +175,126 @@ Sub ExportDXF(ByRef oDoc As DrawingDocument, ByVal strfolder As String, ByVal st
171175
DXFAddIn.SaveCopyAs(oDoc, oContext, oOptions, oDataMedium)
172176
End Sub
173177

178+
''' <summary>
179+
''' Update mass for all directly referenced documents in the drawing (anything that has its own view)
180+
''' </summary>
181+
''' <param name="oDoc"></param>
182+
''' <returns>Boolean</returns>
183+
Function UpdateMass(ByRef oDoc As DrawingDocument) As Boolean
184+
185+
' Define sheet + view objects
186+
Dim oSheet As Inventor.Sheet = Nothing
187+
Dim oView As Inventor.DrawingView = Nothing
188+
189+
' Check if there is a referenced model, update mass if there is (prevents an error on sheets with no model)
190+
If oDoc.referencedocuments.count = 0 Then Return False
191+
192+
' Define flag
193+
Dim bFound As Boolean = False
194+
195+
' Define referenced doc / temporary object
196+
Dim oRefDoc As Inventor.Document
197+
198+
' Update the mass only if it finds the model reference
199+
' Iterate though first level referenced documents
200+
For Each oRefDoc In oDoc.ReferencedDocuments
201+
202+
' If all drawings only had assembly as the main view, wouldn't need to process parts aswell
203+
' Check it is an iam / ipt - not presentation
204+
If oRefDoc.DocumentType <> Inventor.DocumentTypeEnum.kAssemblyDocumentObject AndAlso Inventor.DocumentTypeEnum.kPartDocumentObject Then
205+
' Not a model document so skip to next view
206+
Continue For
207+
End If
208+
209+
'Update Reference Document - some documents don't have mass and it triggers an error if this isnt done
210+
oRefDoc.Update2(True)
211+
212+
' Read the mass to prevent N/A issue / triggers generation of mass.
213+
Dim oMassStr As String = ""
214+
Dim oMassStr2 As String = ""
215+
Dim bMassErr As Boolean = False ' Flag to indicate is there is an issue with the mass or it didnt work
216+
217+
Try
218+
oMassStr = oRefDoc.ComponentDefinition.MassProperties.Mass.ToString() ' This throws an error on some random assemblies, when mass doesn't exist for some reason
219+
oMassStr2 = oRefDoc.PropertySets.Item("Design Tracking Properties").Item("Mass").Value / 1000
220+
Catch
221+
' Do nothing, Know it throws a random error
222+
bMassErr = True
223+
End Try
224+
225+
' Check both masses are the same, if not, needs an update
226+
If bMassErr = True AndAlso oMassStr <> oMassStr2 Then
227+
'Try update ref document again
228+
oRefDoc.Update2(True)
229+
Try
230+
' Re-get properties(not to string on this turn, no reason, just an alternative)
231+
oMassStr = oRefDoc.ComponentDefinition.MassProperties.Mass
232+
oMassStr2 = oRefDoc.PropertySets.Item("Design Tracking Properties").Item("Mass").Value / 1000
233+
Catch
234+
' Return False, If it didnt work, there is likely an issue with the part
235+
Return False
236+
End Try
237+
End If
238+
Next
239+
240+
' Release reference document model
241+
oRefDoc = Nothing
242+
243+
244+
' Update drawing document (ignore errors)
245+
oDoc.Update2(True)
246+
247+
' Mass update succeeded, return true
248+
Return True
249+
250+
End Function
251+
252+
''' <summary>
253+
''' Update all drawing views in a document and check they are all precise / not raster views. Change them if the are
254+
''' </summary>
255+
''' <param name="oDoc"></param>
256+
''' <returns>Boolean</returns>
257+
Function UpdateAllViews(ByRef oDoc As DrawingDocument) As Boolean
258+
' Update application status bar for user to monitor progress
259+
ThisApplication.StatusBarText = "Updating drawing views"
260+
261+
' Make sure there are no raster views, not going to use as unsure if it is efficient as checking all views separately
262+
'oDoc.MakeAllViewsPrecise()
263+
264+
' Ensure all views are updated before printing, this prevents raster view printouts on large assemblies
265+
For Each oSheet As Inventor.Sheet In oDoc.Sheets ' Iterate through all sheets
266+
267+
' This was on a couple of drawings where someone mistakenly selected this
268+
' Check if sheet is excluded from count but is being printed aswell, add it back to the count to prevent export sheet number issues
269+
If oSheet.ExcludeFromCount = True AndAlso oSheet.ExcludeFromPrinting = False Then
270+
' Add sheet back into count
271+
oSheet.ExcludeFromCount = False
272+
End If
273+
274+
' Iterate through all drawing views
275+
For Each oView In oSheet.DrawingViews
276+
ThisApplication.StatusBarText = "Checking if view is raster"
277+
If oView.IsRasterView Then ' Check if view is raster
278+
ThisApplication.StatusBarText = "View is raster so changing to precise"
279+
oView.IsRasterView = False ' Set view to precise / not a raster
280+
End If
281+
282+
' Wait for view to update
283+
ThisApplication.StatusBarText = "Checking if view is updated"
284+
Do While oView.IsUpdateComplete = False
285+
Wait_Inventor(1) ' Just wait fro one second, don't do anything
286+
ThisApplication.StatusBarText = "Updating drawing views"
287+
Loop
288+
Next
289+
Next
290+
291+
ThisApplication.StatusBarText = "Drawing views updated"
292+
293+
' Succeeded, return true
294+
Return True
295+
296+
End Function
297+
174298
''' <summary>
175299
''' Create a new INI file with the relevant export settings defined
176300
''' </summary>
@@ -252,3 +376,13 @@ MessageBox.Show(strPath)
252376

253377
End Function
254378

379+
''' <summary>
380+
''' Wait for a length of time in seconds
381+
''' </summary>
382+
''' <param name="seconds"></param>
383+
Public Sub Wait_Inventor(ByVal seconds As Integer)
384+
For i As Integer = 0 To seconds * 100
385+
System.Threading.Thread.Sleep(10)
386+
ThisApplication.UserInterfaceManager.DoEvents() ' Inventor do events
387+
Next
388+
End Sub

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy