Rule for naming STEP files with Prompted Texts

Rule for naming STEP files with Prompted Texts

lsensenbrenner
Contributor Contributor
145 Views
1 Reply
Message 1 of 2

Rule for naming STEP files with Prompted Texts

lsensenbrenner
Contributor
Contributor

Hi,

I'd like to create a rule "like Save in STEP format" to use the Prompted Texts "Numéro du plan" in the STEP file name.

Dim doc As DrawingDocument = ThisDoc.Document
Dim sheet As Sheet = doc.ActiveSheet
Dim view As DrawingView = sheet.DrawingViews.Item(1)
Dim partDoc As PartDocument = view.ReferencedDocumentDescriptor.ReferencedDocument

' Get current location of this file
Dim ExportPath As String = ThisDoc.Path

' Check that this file has been saved and actually exists on disk
If String.IsNullOrEmpty(ExportPath) Then
	MsgBox("This file has not yet been saved and doesn't exist on disk!" _
	& vbLf & "Please save it first", 64, "Lord iLogic")
	Return
End If

Dim drawingNumber = 'the Prompted Texts "Numéro du plan" 

Dim dialog As Inventor.FileDialog
ThisApplication.CreateFileDialog(dialog)

dialog.InitialDirectory = ExportPath
dialog.FileName = drawingNumber
dialog.DialogTitle = "Save"
dialog.Filter = "Step files(*.stp)|*.stp|All Files (*.*)|*.*"
dialog.CancelError = True
Try
	dialog.ShowSave()
Catch ex As Exception
	Return
End Try

' Get the STEP translator Add-In.
Dim oSTEPTranslator As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap

If oSTEPTranslator.HasSaveCopyAsOptions(partDoc, oContext, oOptions) Then
	' Set application protocol.
	' 2 = AP 203 - Configuration Controlled Design
	' 3 = AP 214 - Automotive Design
	oOptions.Value("ApplicationProtocolType") = 3
	' Other options...
	'oOptions.Value("Author") = ""
	'oOptions.Value("Authorization") = ""
	'oOptions.Value("Description") = ""
	'oOptions.Value("Organization") = ""
	oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism

	Dim oData As DataMedium = ThisApplication.TransientObjects.CreateDataMedium
	oData.FileName = dialog.FileName

	oSTEPTranslator.SaveCopyAs(partDoc, oContext, oOptions, oData)
End If 

 

Thank in advance and have a nice day

 

0 Likes
146 Views
1 Reply
Reply (1)
Message 2 of 2

Michael.Navara
Advisor
Advisor

Do you want to write your prompt to the FileDialog as default value and the user must overwrite it? You can try following code.

It is just a part of your code, where the user selects the file name. For ExportPath is used empty string. Result is written to the iLogic log window.

 

Dim ExportPath = ""

'***********************
Dim drawingNumber = "Numéro du plan" 'the Prompted Texts "Numéro du plan" 

Dim dialog As Inventor.FileDialog
ThisApplication.CreateFileDialog(dialog)

dialog.InitialDirectory = ExportPath
dialog.FileName = drawingNumber
dialog.DialogTitle = "Save"
dialog.Filter = "Step files(*.stp)|*.stp|All Files (*.*)|*.*"
dialog.CancelError = True
Try
	Do
		dialog.ShowSave()
		If (dialog.FileName.EndsWith(drawingNumber & ".stp")) Then
			MsgBox("Enter valid file name")
		Else
			Exit Do
		End If
	Loop
Catch ex As Exception
	Return
End Try
'***********************


logger.Debug(dialog.FileName)

 

 

 

0 Likes