iLogic to export STP file for individual Model State

iLogic to export STP file for individual Model State

frahaman7SKBG
Advocate Advocate
1,229 Views
2 Replies
Message 1 of 3

iLogic to export STP file for individual Model State

frahaman7SKBG
Advocate
Advocate

Does anyone know how to export individual Model States in STP format using iLogic? I have 100+ Model State with Multibody in a single ipt file, need to export them in STP file. 

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

theo.bot
Collaborator
Collaborator
Accepted solution

You should Loop thru the modelstates, activate each modelstate and then do a save as Step

Here is a small sample:

 

Sub Main
	
Dim oDoc As PartDocument
oDoc = ThisDoc.Document 

Dim oModelState As ModelState

For Each oModelState In oDoc.ComponentDefinition.ModelStates
	Logger.Info(oModelState.Name)
	If oModelState.Name <> "Master" Then
		oModelState.Activate
		
		ExportStep(oModelState.Name)
	End If
Next

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

oPath = ThisDoc.Path
oFolder = oPath & "\Step"

'Check for the PDF folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
    System.IO.Directory.CreateDirectory(oFolder)
End If

If oSTEPTranslator.HasSaveCopyAsOptions(ThisDoc.Document, 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
    oData = ThisApplication.TransientObjects.CreateDataMedium
    oData.FileName = oFolder & "\" & ThisDoc.FileName(False) & "-" & oState & ".stp"
oSTEPTranslator.SaveCopyAs(ThisDoc.Document, oContext, oOptions, oData)
End If
End Sub
0 Likes
Message 3 of 3

frahaman7SKBG
Advocate
Advocate
Thank you so much @ theo.bot, it works flawlessly.