Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
JBMosco
1383 Views, 2 Replies

iLogic Create Drawing File From Part

I am trying to run a rule that:

1) Checks if a Drawing file doesn't already exist

2) Creates a drawing file from a specified template

3) Places the front view of the current part in the center of the drawing

4) Saves this new drawing in the specified path

 

I would like this to happen all in the background, the end goal is to make the template part file have this script and automatically run it on each save using event triggers. This is my current code:

 

Sub Main()
	
	oFileName = ThisDoc.Path & "\Drawing Files\" & ThisDoc.FileName & ".dwg"
	
	If (System.IO.File.Exists(oFileName)) Then
		Exit Sub
	End If
	
	Template = ThisDoc.Path & "\.Resources\Templates\Sheet Metal Drawing.dwg"
	'Dim oDrawingDoc As Document= ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, Template, False)
	Dim oDrawingDoc As Document= ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject)
	Dim oSheet As Sheet = oDrawingDoc.Sheets.Item(1)
	Dim oCenter As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(oSheet.Width / 2, oSheet.Height / 2)
	
	oSheet.DrawingViews.AddBaseView(ThisDoc.Document, oCenter, 1, kFrontViewOrientation, kHiddenLineRemovedDrawingViewStyle, "Front")
	oDrawingDoc.SaveAs(oFileName, True)
	
End Sub

My code most works, only when I open the drawing file, the formatting seems wrong. the page border is missing and the background is black as if I saved a .dxf instead. Is there an alternate or correct way to save this drawing file?

A.Acheson
in reply to: JBMosco

In the save as snippet you are saving as an autocad dwg instead of inventor dwg. You will need to change the saving method. 

 

Replace 

DrawingDocument.SaveAsFileName As String, SaveCopyAs As Boolean )

with

DrawingDocument.SaveAsInventorDWGFullFileName As String, SaveCopyAs As Boolean )

 

Save as Inventor Method

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
JBMosco
in reply to: JBMosco

Thank you, that was it. Here's the revised code:

Sub Main()
	
	oFileName = ThisDoc.Path & "\Drawing Files\" & ThisDoc.FileName & ".dwg"
	
	If (System.IO.File.Exists(oFileName)) Then
		Exit Sub
	End If
	
	Template = ThisDoc.Path & "\.Resources\Templates\Sheet Metal Drawing.dwg"
	Dim oDrawingDoc As Document= ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, Template, False)
	Dim oSheet As Sheet = oDrawingDoc.Sheets.Item(1)
	Dim oCenter As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(oSheet.Width / 2, oSheet.Height / 2)
	
	oSheet.DrawingViews.AddBaseView(ThisDoc.Document, oCenter, 1, kFrontViewOrientation, kHiddenLineRemovedDrawingViewStyle, "Front")
	oDrawingDoc.SaveAsInventorDWG(oFileName, False)
	
End Sub