iLogic check if part/assembly has got a drawing

iLogic check if part/assembly has got a drawing

frederik_vollbrecht
Advocate Advocate
4,927 Views
8 Replies
Message 1 of 9

iLogic check if part/assembly has got a drawing

frederik_vollbrecht
Advocate
Advocate

Hi guys,

 

I'm searching for some code to check if any Part of an assembly (sub too) has got a drawing. Also I want to create a result-list in excel. My idea is to rewrite a code i have to batch export pdf's from an assembly but I don't know how to create the resulting list..

Here is my export-script:

 

'based on script from curtis Waguespack
'customization by Frederik Vollbrecht



'check that the active document is an assembly file
If ThisApplication.ActiveDocument.DocumentType  <>  kAssemblyDocumentObject Then
	MessageBox.Show("Please run this rule from the assembly file.", "iLogic")
	Exit Sub
End If


'define the active document as an assembly file
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) -4)


'get user input
RUsure = MessageBox.Show ( _
"This will create a PDF file for all of the asembly components that have drawings files." _
& vbLf & "This rule expects that the drawing file shares the same name and location as the component." _
& vbLf & " " _
& vbLf & "Are you sure you want to create PDF Drawings for all of the assembly components?" _
& vbLf & "This could take a while.", "iLogic  - Batch Output PDFs ",MessageBoxButtons.YesNo)

If RUsure = vbNo Then
Return
Else
End If

'- - - - - - - - - - - - -PDF setup - - - - - - - - - - - -
oPath = ThisDoc.Path
PDFAddIn = 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 PDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
'oOptions.Value("All_Color_AS_Black") = 0
oOptions.Value("Remove_Line_Weights") = 1
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


'get target folder path
oFolder = oPath & "\" & "Export"

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

'- - - - - - - - - - - - -Component PDF Drawings - - - - - - - - - - - -
'look at the files referenced by the assembly
Dim oRefDocs As DocumentsEnumerator
oRefDocs = oAsmDoc.AllReferencedDocuments
Dim oRefDoc As Document

'work the the drawing files for the referenced models
'this expects that the model has a drawing of the same path and name 
For Each oRefDoc In oRefDocs
idwPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName) - 3) & "idw"
'check to see that the model has a drawing of the same path and name 
If(System.IO.File.Exists(idwPathName)) Then
        Dim oDrawDoc As DrawingDocument
    oDrawDoc = ThisApplication.Documents.Open(idwPathName, True)
    oFileName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName) -3)

    On Error Resume Next ' if PDF exists and is open or read only, resume next
     'Set the PDF target file name
    oDataMedium.FileName = oFolder & "\" & oFileName & "pdf"
		
    'Write out the PDF
    Call PDFAddIn.SaveCopyAs(oDrawDoc, oContext, oOptions, oDataMedium)
	oDrawDoc.Close
	
Else
'If the model has no drawing of the same path and name - do nothing
End If
Next

'- - - - - - - - - - - - -Top Level PDF Drawing - - - - - - - - - - - -
oAsmDrawing = ThisDoc.ChangeExtension(".idw")
oAsmDrawingDoc = ThisApplication.Documents.Open(oAsmDrawing, True)
oAsmDrawingName = Left(oAsmDrawingDoc.DisplayName, Len(oAsmDrawingDoc.DisplayName) -3)
'write out the PDF for the Top Level Assembly Drawing file
 On Error Resume Next ' if PDF exists and is open or read only, resume next
     'Set the PDF target file name
    oDataMedium.FileName = oFolder & "\" & oAsmDrawingName & "pdf"

	
    'Write out the PDF
    Call PDFAddIn.SaveCopyAs(oAsmDrawingDoc, oContext, oOptions, oDataMedium)

'- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

MessageBox.Show("New Files Created in: " & vbLf & oFolder, "iLogic")
'open the folder where the new files are saved
Shell("explorer.exe " & oFolder,vbNormalFocus)
0 Likes
Accepted solutions (1)
4,928 Views
8 Replies
Replies (8)
Message 2 of 9

frederik_vollbrecht
Advocate
Advocate
Accepted solution
'script by Frederik Vollbrecht

'check that the active document is an assembly file
If ThisApplication.ActiveDocument.DocumentType  <>  kAssemblyDocumentObject Then
	MessageBox.Show("Please run this rule from the assembly file.", "iLogic")
	Exit Sub
End If

'define the active document as an assembly file
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) -4)

'get user input
RUsure = MessageBox.Show ( _
"This will create a TXT file for all of the asembly components that don't have drawings files." _
& vbLf & "This rule expects that the drawing file shares the same name and location as the component." _
& vbLf & " " _
& vbLf & "Are you sure you want to create TXT for all of the assembly components?" _
& vbLf & "This could take a while.", "iLogic  - Batch Output TXT ",MessageBoxButtons.YesNo)

If RUsure = vbNo Then
Return
Else
End If

Dim oDocument As Document
oDocument = ThisApplication.ActiveDocument
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
' Create a NameValueMap object
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
' Create a DataMedium object
Dim oDataMedium As DataMedium
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
' Check whether the translator has 'SaveCopyAs' options

'get target folder path
oFolder = oPath & "\" & "Export"

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

'- - - - - - - - - - - - -Component PDF Drawings - - - - - - - - - - - -
'look at the files referenced by the assembly
Dim oRefDocs As DocumentsEnumerator
oRefDocs = oAsmDoc.AllReferencedDocuments
Dim oRefDoc As Document

'work the the drawing files for the referenced models
'this expects that the model has a drawing of the same path and name 
For Each oRefDoc In oRefDocs
idwPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName) - 3) & "idw"
'check to see that the model has a drawing of the same path and name 
If(System.IO.File.Exists(idwPathName))=0 Then

'____Open and append to an existing text file_______
Dim oAppend As System.IO.StreamWriter

oFile = ThisDoc.PathAndFileName(False) & ".txt"
oAppend = IO.File.AppendText(oFile)

oAppend.WriteLine(oRefDoc.FullDocumentName)
oAppend.Flush()
oAppend.Close()
	
Else
'If the model has no drawing of the same path and name - do nothing

End If
Next
'- - - - - - - - - - - - -
ThisDoc.Launch(oFile)

Solved by my self again 😄

Message 3 of 9

Anonymous
Not applicable

How would you modify this code to simply check if there has been a drawing created for each part/assembly & return an error report of a list of parts with missing drawings?

0 Likes
Message 4 of 9

Anonymous
Not applicable

Could you help me modify this to check for .plt files in a gaving location (P:). I don't need PDFs, just checking for the plt files.

Also the IDW, IPT, and IAM are not in the same location as the plt.

 

THank you

 

0 Likes
Message 5 of 9

frederik_vollbrecht
Advocate
Advocate

I don't know a way to append Text in a messagebox, sorry.

0 Likes
Message 6 of 9

Anonymous
Not applicable

Hi Craig,

 

Did you ever solve this?

"How would you modify this code to simply check if there has been a drawing created for each part/assembly & return an error report of a list of parts with missing drawings?"

If so would you care to share please?

 

Thanks,

Miles

0 Likes
Message 7 of 9

davis.j
Advocate
Advocate

Thanks @frederik_vollbrecht , this is really helpful.

 

Any wiz's on here that could adopt this code and make it search for vault drawings that are in a different folder location and has the exact same file name?

 

image.png

0 Likes
Message 8 of 9

frederik_vollbrecht
Advocate
Advocate

Sorry, but this is straightly against my workflow. You could have a look at this thread:
https://forums.autodesk.com/t5/inventor-customization/ilogic-open-drawing-from-vault-default/td-p/88...

 

May you will have to open a new thread.

0 Likes
Message 9 of 9

inventor4578
Advocate
Advocate

Hi !

Thank you very much for this iLogic it is working good !

Is it possible to exclude content center part ?

Thank you again!

0 Likes