iLogic code for exporting all model states in part document

iLogic code for exporting all model states in part document

raymaster
Contributor Contributor
373 Views
2 Replies
Message 1 of 3

iLogic code for exporting all model states in part document

raymaster
Contributor
Contributor

Hello All

 

tried to have an ilogic that can export all model states of my part document to a seperate IPT ot X_T files, but it ended in exporting all the models but didnt chage the model state for each one, so they got different names but with the same current model state.

here is the code:

Dim oDoc As PartDocument = ThisApplication.ActiveDocument

Dim oFolderName As String
FolderName = InputBox("Insert Folder Name", "Export Folder", oFolderName)
Dim oPath As String = "C:\X_T\" & FolderName ' Change this to the correct path

For Each oState As ModelState In oDoc.ComponentDefinition.ModelStates

    Try
        Dim oXtPath As String = oPath & "\" & oState.Name & ".ipt"
        oDoc.SaveAs(oXtPath, True)
    Catch ex As Exception
        MessageBox.Show("Error processing " & oState.Name & ": " & ex.Message, "iLogic")
    End Try

Next

MessageBox.Show("New Files Created in: " & vbLf & oPath, "iLogic")


A help needed!

Thanks

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

m_baczewski
Advocate
Advocate

Hello,

 

I'm not entirely sure if that's exactly what you were referring to, but it seems to me that you just need to activate the specific model state before saving it. I changed some part of code to myself.

 

 

Dim oDoc As PartDocument = ThisApplication.ActiveDocument
Dim oPath As String = ThisDoc.Path

For Each oState As ModelState In oDoc.ComponentDefinition.ModelStates
	Try
		oState.Activate
	Catch ex As Exception
                MessageBox.Show("Error processing " & oState.Name & ": " & ex.Message, "iLogic")
	End Try
    Dim oXtPath As String = oPath & "\" & oState.Name & ".ipt"
    oDoc.SaveAs(oXtPath, True)

Next

MessageBox.Show("New Files Created in: " & vbLf & oPath, "iLogic")

 

 

0 Likes
Message 3 of 3

raymaster
Contributor
Contributor
Accepted solution

I edited it like so and it worked:

    Dim oDoc As PartDocument
    oDoc = ThisDoc.Document 
	
	Dim oFolderName As String
	FolderName = InputBox("Insert Folder Name", "Export Folder", oFolderName)
	Dim oPath As String = "C:\Export_ipt\" & FolderName ' Change this to the correct path
    
    Dim oModelState As ModelState
    
    For Each oModelState In oDoc.ComponentDefinition.ModelStates
        Logger.Info(oModelState.Name)
        If oModelState.Name <> "Master" Then
            oModelState.Activate
		Try
        Dim oXtPath As String = oPath & "\" & oModelState.Name & ".IPT"
        oDoc.SaveAs(oXtPath, True)
    	Catch ex As Exception
        MessageBox.Show("Error processing " & oModelState.Name & ": " & ex.Message, "iLogic")
    	End Try
			
        End If
    Next