Assemblies, parts, drawing in differents directories, How make a batch from assy

Assemblies, parts, drawing in differents directories, How make a batch from assy

Anonymous
Not applicable
462 Views
3 Replies
Message 1 of 4

Assemblies, parts, drawing in differents directories, How make a batch from assy

Anonymous
Not applicable

Hello everyone

Can you help me ? In my project, I structured with different directories, a directory for assemblies, directories based on the type of part, a directory for drawings. How from an assembly to make (for example)  pdfs from drawings when the drawings are not in the same directory with illogic.

 

 🙂

 

Capture.JPG

0 Likes
463 Views
3 Replies
Replies (3)
Message 2 of 4

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @Anonymous,

 

I have gone through your iLogic code. Only one thing is missing while exporting to pdf. PDF path file does not include .pdf extension properly. So, "." is required before pdf string and it is highlighted in red color below code.

 

Sub Main()
	Dim oAsmDoc As AssemblyDocument
	oAsmDoc = ThisApplication.ActiveDocument
	oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) -4)
	
	'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
	
	'get user input
	If 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) = vbNo Then
		
		Exit Sub
	End If
		
	Dim PDFAddIn As TranslatorAddIn
        Dim oContext As TranslationContext
	Dim oOptions As NameValueMap
	Dim oDataMedium As DataMedium
	
	Call ConfigurePDFAddinSettings(PDFAddIn, oContext, oOptions, oDataMedium)
	
	oPath = ThisDoc.Path
	oFolder = oPath & "\" & oAsmName & " PDF Files"
	
	If Not System.IO.Directory.Exists(oFolder) Then
		System.IO.Directory.CreateDirectory(oFolder)
	End If
	
	'- - - - - - - - - - - - -Component Drawings - - - - - - - - - - - -'look at the files referenced by the assembly
	Dim oRefDoc As Document
	
'	For Each oRefDoc In oRefDocs = oAsmDoc.AllReferencedDocuments
	For Each oRefDoc In oAsmDoc.AllReferencedDocuments
		idwPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentNaMe) - 3) & "idw"

		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
				oDataMedium.FileName = oFolder & "\" & oFileName & ".pdf"
				Call PDFAddIn.SaveCopyAs(oDrawDoc, oContext, oOptions, oDataMedium)
				oDrawDoc.Close
			On Error Goto 0
		End If
	Next
	'- - - - - - - - - - - - -
	
	'- - - - - - - - - - - - -Top Level Drawing - - - - - - - - - - - -
	Dim oAsmDrawingDoc As DrawingDocument
	oAsmDrawingDocName = ThisDoc.PathAndFileName(False) & ".idw"
	
	If(System.IO.File.Exists(oAsmDrawingDocName)) Then
	oAsmDrawingDoc = ThisApplication.Documents.Open(ThisDoc.ChangeExtension(".idw"), True)
	'oAsmDrawingDoc = ThisApplication.Documents.Open(oAsmDrawingDocName, True) 
	oAsmDrawingName = Left(oAsmDrawingDoc.DisplayName, Len(oAsmDrawingDoc.DisplayName) -3) 
	
	On Error Resume Next 
		oDataMedium.FileName = oFolder & "\" & oAsmDrawingName & ".pdf" 
		Call PDFAddIn.SaveCopyAs(oAsmDrawingDoc, oContext, oOptions, oDataMedium)
		oAsmDrawingDoc.Close 
	End If 

End Sub

Sub ConfigurePDFAddinSettings(ByRef PDFAddIn As TranslatorAddIn, ByRef oContext As TranslationContext, ByRef oOptions As NameValueMap, ByRef oDataMedium As DataMedium)

	oPath = ThisDoc.Path
	PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
	oContext = ThisApplication.TransientObjects.CreateTranslationContext
	oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
		
	oOptions = ThisApplication.TransientObjects.CreateNameValueMap
	oOptions.Value("All_Color_AS_Black") = 1
	oOptions.Value("Remove_Line_Weights") = 0
	oOptions.Value("Vector_Resolution") = 400
	oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
	oOptions.Value("Custom_Begin_Sheet") = 1
	oOptions.Value("Custom_End_Sheet") = 1

	oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
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
Message 3 of 4

Anonymous
Not applicable

hello,

 
thank you for your help Smiley Happy

I did not answer earlier, I had a lot of work.

I try the corrected code, but it launches the dialog for the creation of PDF but nothing happens. Apparently he does not find the drawings related to the parts.
 
Capture.JPG
0 Likes
Message 4 of 4

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @Anonymous,

 

idwPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentNaMe) - 3) & "idw"

The above iLogic code indicates that referenced drawing files are located at same folder of referenced part files. But as per the above folder structure, it's not true.

 

oAsmDrawingDocName = ThisDoc.PathAndFileName(False) & ".idw"

Here also, same thing is happening Assembly drawing is located at assembly folder. Is it true?

 

Can you please provide sample assembly and referenced part files? Not a large assembly. 2 to 4 parts inside assembly is also fine.

 

Please make sure that files are non confidential one.

 

Thanks and regards,

 


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes