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

Sorry to hijack your post @raymaster 

I was facing a similar issue, but the suggestion of @WCrihfield got me to a working result. The next issue I'm facing is that this method is not copying dimensions that are already placed on the first sheet :disappointed_face: If that could also be done, it would be perfect.

It takes an .idw and uses the single sheet present as a temporary sheetformat. Then it steps through the model states and creates new sheets with names equal to the model states and it changes the model state in the base view for each new sheet created. I also still have to figure out a clean way to skip the [Primary] model state.

 

EDIT: a simple solution to skip the Primary model state is to start counting at 2 at line 27

 

 

' iLogic Rule: Duplicate Sheets for Model States
' This rule duplicates an existing sheet for each model state in the referenced part/assembly,
' updates the base view to match the corresponding model state, and renames the sheet.

' Get the active document (assumes it is a .idw file)
Dim oDrawingDoc As DrawingDocument = ThisApplication.ActiveDocument

' Get the first sheet (this will serve as the template for duplication)
Dim oTemplateSheet As Sheet = oDrawingDoc.Sheets.Item(1)
Dim oSheetFormats As SheetFormats = oDrawingDoc.SheetFormats
Dim oTempSheetFormat As SheetFormat = oSheetFormats.Add(oTemplateSheet,"Geo-IT Temp SheetFormat")

' Get the referenced model from the base view on the template sheet
Dim oBaseView As DrawingView = oTemplateSheet.DrawingViews.Item(1)
Dim oReferencedModel As Document = oBaseView.ReferencedDocumentDescriptor.ReferencedDocument

' Get the model states from the referenced model
Dim oModelStates As ModelStates = oReferencedModel.ComponentDefinition.ModelStates

' Ensure the model states collection is not empty
If oModelStates.Count = 0 Then
    MessageBox.Show("No model states found in the referenced model.", "Error")
    Return
End If

' Loop through the model states and create a sheet for each
For i As Integer = 1 To oModelStates.Count
    Dim oModelState As ModelState = oModelStates.Item(i)
    
    ' Create a new sheet by duplicating the template sheet, reference the model and change the name
    Dim oNewSheet As Sheet = oDrawingDoc.Sheets.AddUsingSheetFormat(oTempSheetFormat,oReferencedModel,oModelState.Name)
    
    ' Update the base view on the new sheet to reference the corresponding model state
    Dim oNewBaseView As DrawingView = oNewSheet.DrawingViews.Item(1)
    oNewBaseView.SetActiveModelState(oModelState.Name)
Next

 'Remove the temp sheet format
 oTempSheetFormat.Delete()