iLogic Create Drawing File From Part

iLogic Create Drawing File From Part

JBMosco
Participant Participant
1,758 Views
2 Replies
Message 1 of 3

iLogic Create Drawing File From Part

JBMosco
Participant
Participant

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?

0 Likes
Accepted solutions (1)
1,759 Views
2 Replies
Replies (2)
Message 2 of 3

A.Acheson
Mentor
Mentor
Accepted solution

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
0 Likes
Message 3 of 3

JBMosco
Participant
Participant

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 

 

0 Likes