[VBA] Creating a new Sheet Model in Code

There is an archived thread with code that does not work as posted. It does create a sheet but has many caveats.

Here is my version:

 Sub createNewSheet(newModelName As String, newModelDescription As String)
'variables for new sheet model in memory
    Dim oSheet As SheetDefinition
    Dim oModel As ModelReference
    
    'both types must have default info to start with in order to update their settings
    Set oSheet = ActiveModelReference.GetSheetDefinition
    Set oModel = ActiveDesignFile.DefaultModelReference
    
    'Add any specific settings you want for your sheet and model here
    With oSheet
        .Origin.x = 0#
        .Origin.Y = 0#
        .Width = oModel.WorkingUnitsToDouble("11'") * oModel.UORsPerMasterUnit
        .Height = oModel.WorkingUnitsToDouble("8.5'") * oModel.UORsPerMasterUnit
      '  .Rotation = 0#
        .Rotation = Radians(90#)
    End With
    With oModel
        If .Type <> msdModelTypeSheet Then .Type = msdModelTypeSheet
        .SetSheetDefinition oSheet
    End With
    'Call this command to create the new sheet in the file
    ActiveDesignFile.Models.Add oModel, newModelName, newModelDescription, msdModelTypeSheet, False
    ActiveDesignFile.Models(ActiveDesignFile.Models.Count).Activate
End Sub

So here is what does not work still:

The code to define the origin - .origin.x =0 .origin.y=0

The origin remains the same as the active model when the new model was created in memory. Apparently, this code copies many of the active model properties when it creates the new model. I had to test if the new model was a sheet before attempting to set its type to msdModelTypeSheet. The original code for width and height used simply the two numbers. I found I had to use all of that extra code to get those to the correct size.

So my questions are:

  • Is there a way to set the sheet origin back to 0,0?
  • If not, is there a way to create a new model, in code, where it does not use the active model?

Parents Reply Children
No Data