Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
WCrihfield
in reply to: denis.semeniuc

Here is a similar iLogic rule that will either silently open the template drawing, without using an open file dialog, or can use the open file dialog, depending on which lines you leave commented out.  If not using the open file dialog, make sure the path and name of the template drawing are correct in the rule before running it.  Since I am not sure which 'named' sheets you want to copy over, I removed the 'filter' question, and the code will now try to copy all sheets over.  If you need it to be more specific, I would need to know how to filter for which sheets to copy.  If there is a list of specific sheet names, we could include them into the rule, as the filter.

 

Sub Main
	If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
		MsgBox("A Drawing document must be active for this code to work. Exiting.", vbCritical, "")
		Exit Sub
	End If
	Dim oDDoc As DrawingDocument = ThisDoc.Document
	Dim sTemplatesPath As String = ThisApplication.DesignProjectManager.ActiveDesignProject.TemplatesPath
	Dim sTemplateFile As String = sTemplatesPath & "\Drawing.idw" '<<< EDIT THIS >>>>
	'Dim sTemplateFile As String = BrowseForDrawing 'calls the custom Function below
	'If sTemplateFile = "" Then Exit Sub
	Dim oTemplate As DrawingDocument = ThisApplication.Documents.Open(sTemplateFile, False)
	For Each oSheet As Sheet In oTemplate.Sheets
		oSheet.CopyTo(oDDoc)
	Next
	oDDoc.Update2(True)
End Sub

Function BrowseForDrawing() As String
	Dim oFileDialog As Inventor.FileDialog
	ThisApplication.CreateFileDialog(oFileDialog)
	oFileDialog.DialogTitle = "Select Source Template Drawing."
	oFileDialog.InitialDirectory = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath
	oFileDialog.Filter = "Autodesk Inventor Drawings (*.dwg;*.idw) | *.dwg;*.idw"
	oFileDialog.MultiSelectEnabled = False
	oFileDialog.OptionsEnabled = False
	oFileDialog.CancelError = True
	oFileDialog.InsertMode = False
	Try
		oFileDialog.ShowOpen
	Catch
	End Try
	Return oFileDialog.FileName
End Function

 

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) :thumbs_up:.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)