Attribute VB_Name = "ChannelPMP"
' -------------------------------------------------------------------11/13/2007
' Channel-StructuralPMP.swp     Copyright 2007 by Leonard Kikstra
'                               PropertyManagerPage Interface to change nominal
'                               size of structural angle.
' -----------------------------------------------------------------------------
'                               Portions of code supplied by SolidWorks Corp.
' -----------------------------------------------------------------------------

  Global swApp        As Object
  Global Part         As Object
  Global ModelDocExt  As Object
  Global MassValue    As Variant
  Global MassStatus   As Long

' The controls on the page
  Global ChanCombo                As SldWorks.PropertyManagerPageCombobox
  Global ChanNumbr                As SldWorks.PropertyManagerPageNumberbox

' The application's PropertyManagerPage
  Global swPage                 As ChanMgr
  
  Global UpdateModel As Boolean
  
' Channel Definitions
  Global ChannelDef(60, 7)
  Global ChannelCnt As Integer

Sub ChannelData(ChanNam As String, ChanTyp As String, ChanHgt As Double, _
                ChanWgt As Double, ChanWeb As Double, ChanLeg As Double, _
                ChanThk As Double, ChanDesc As String)
  ChannelDef(ChannelCnt, 0) = ChanNam
  ChannelDef(ChannelCnt, 1) = ChanTyp
  ChannelDef(ChannelCnt, 2) = ChanHgt
  ChannelDef(ChannelCnt, 3) = ChanWgt
  ChannelDef(ChannelCnt, 4) = ChanWeb
  ChannelDef(ChannelCnt, 5) = ChanLeg
  ChannelDef(ChannelCnt, 6) = ChanThk
  ChannelDef(ChannelCnt, 7) = ChanDesc
  ChannelCnt = ChannelCnt + 1
End Sub

Sub BuildChanData()
  ChannelCnt = 0
  ChannelData "C3 x 4.1LB/FT", "C", 3, 4.1, 0.17, 1.41, 0.273, "CHAN C3X4.1LB/FT"
  ChannelData "C3 x 5LB/FT", "C", 3, 5, 0.258, 1.498, 0.273, "CHAN C3X5LB/FT"
  ChannelData "C3 x 6LB/FT", "C", 3, 6, 0.356, 1.596, 0.273, "CHAN C3X6LB/FT"
  ChannelData "C4 x 5.4LB/FT", "C", 4, 5.4, 0.184, 1.584, 0.296, "CHAN C4X5.4LB/FT"
  ChannelData "C4 x 6.25LB/FT", "C", 4, 6.25, 0.247, 1.647, 0.296, "CHAN C4X6.25LB/FT"
  ChannelData "C4 x 7.25LB/FT", "C", 4, 7.25, 0.321, 1.721, 0.296, "CHAN C4X7.25LB/FT"
  ChannelData "C5 x 6.7LB/FT", "C", 5, 6.7, 0.19, 1.75, 0.32, "CHAN C5X6.7LB/FT"
  ChannelData "C5 x 9LB/FT", "C", 5, 9, 0.325, 1.885, 0.32, "CHAN C5X9LB/FT"
  ChannelData "C6 x 8.2LB/FT", "C", 6, 8.2, 0.2, 1.92, 0.343, "CHAN C6X8.2LB/FT"
  ChannelData "C6 x 10.5LB/FT", "C", 6, 10.5, 0.314, 2.034, 0.343, "CHAN C6X10.5LB/FT"
  ChannelData "C6 x 13LB/FT", "C", 6, 13, 0.437, 2.157, 0.343, "CHAN C6X13LB/FT"
  ChannelData "C7 x 9.8LB/FT", "C", 7, 9.8, 0.21, 2.09, 0.366, "CHAN C7X9.8LB/FT"
  ChannelData "C7 x 12.25LB/FT", "C", 7, 12.25, 0.314, 2.194, 0.366, "CHAN C7X12.25LB/FT"
  ChannelData "C7 x 14.75LB/FT", "C", 7, 14.75, 0.419, 2.999, 0.366, "CHAN C7X14.75LB/FT"
  ChannelData "C8 x 11.5LB/FT", "C", 8, 11.5, 0.22, 2.26, 0.39, "CHAN C8X11.5LB/FT"
  ChannelData "C8 x 13.75LB/FT", "C", 8, 13.75, 0.303, 2.343, 0.39, "CHAN C8X13.75LB/FT"
  ChannelData "C8 x 18.75LB/FT", "C", 8, 18.75, 0.487, 2.527, 0.39, "CHAN C8X18.75LB/FT"
  ChannelData "C9 x 13.4LB/FT", "C", 9, 13.4, 0.233, 2.433, 0.413, "CHAN C9X13.4LB/FT"
  ChannelData "C9 x 15LB/FT", "C", 9, 15, 0.285, 2.485, 0.413, "CHAN C9X15LB/FT"
  ChannelData "C9 x 20LB/FT", "C", 9, 20, 0.448, 2.648, 0.413, "CHAN C9X20LB/FT"
  ChannelData "C10 x 15.3LB/FT", "C", 10, 15.3, 0.24, 2.6, 0.436, "CHAN C10X15.3LB/FT"
  ChannelData "C10 x 20LB/FT", "C", 10, 20, 0.379, 2.793, 0.436, "CHAN C10X20LB/FT"
  ChannelData "C10 x 25LB/FT", "C", 10, 25, 0.526, 2.886, 0.436, "CHAN C10X25LB/FT"
  ChannelData "C10 x 30LB/FT", "C", 10, 30, 0.673, 3.033, 0.436, "CHAN C10X30LB/FT"
  ChannelData "C12 x 20.7LB/FT", "C", 12, 20.7, 0.282, 2.942, 0.501, "CHAN C12X20.7LB/FT"
  ChannelData "C12 x 25LB/FT", "C", 12, 25, 0.387, 3.047, 0.501, "CHAN C12X25LB/FT"
  ChannelData "C12 x 30LB/FT", "C", 12, 30, 0.51, 3.17, 0.501, "CHAN C12X30LB/FT"
  ChannelData "C15 x 33.9LB/FT", "C", 15, 33.9, 0.4, 3.4, 0.54, "CHAN C15X33.9LB/FT"
  ChannelData "C15 x 40LB/FT", "C", 15, 40, 0.52, 3.52, 0.54, "CHAN C15X40LB/FT"
  ChannelData "C15 x 50LB/FT", "C", 15, 50, 0.716, 3.716, 0.54, "CHAN C15X50LB/FT"
  ChannelData "MC3 x 7.1LB/FT", "MC", 3, 7.1, 0.312, 1.938, 0.237, "CHAN C3X7.1LB/FT"
  ChannelData "MC6 x 12LB/FT", "MC", 6, 12, 0.31, 2.497, 0.375, "CHAN C6X12LB/FT"
  ChannelData "MC4 x 13.8LB/FT", "MC", 4, 13.8, 0.5, 2.5, 0.296, "CHAN C4X13.8LB/FT"
  ChannelData "MC6 x 15.3LB/FT", "MC", 6, 15.3, 0.34, 3.5, 0.385, "CHAN C6X15.3LB/FT"
  ChannelData "MC6 x 16.3LB/FT", "MC", 6, 16.3, 0.375, 3, 0.475, "CHAN C6X16.3LB/FT"
  ChannelData "MC6 x 18LB/FT", "MC", 6, 18, 0.379, 3.504, 0.475, "CHAN C6X18LB/FT"
  ChannelData "MC8 x 18.7LB/FT", "MC", 8, 18.7, 0.353, 2.978, 0.5, "CHAN C8X18.7LB/FT"
  ChannelData "MC7 x 19.1LB/FT", "MC", 7, 19.1, 0.352, 3.452, 0.5, "CHAN C7X19.1LB/FT"
  ChannelData "MC8 x 20LB/FT", "MC", 8, 20, 0.4, 3.025, 0.5, "CHAN C8X20LB/FT"
  ChannelData "MC8 x 21.4LB/FT", "MC", 8, 21.4, 0.375, 3.45, 0.525, "CHAN C8X21.4LB/FT"
  ChannelData "MC7 x 22.7LB/FT", "MC", 7, 22.7, 0.503, 3.603, 0.5, "CHAN C7X22.7LB/FT"
  ChannelData "MC8 x 22.8LB/FT", "MC", 8, 22.8, 0.427, 3.502, 0.525, "CHAN C8X22.8LB/FT"
  ChannelData "MC9 x 25.4LB/FT", "MC", 9, 25.4, 0.45, 3.5, 0.55, "CHAN C9X25.4LB/FT"
  ChannelData "MC10 x 28.5LB/FT", "MC", 10, 28.5, 0.425, 3.95, 0.575, "CHAN C10X28.5LB/FT"
  ChannelData "MC12 x 31LB/FT", "MC", 12, 31, 0.37, 3.67, 0.7, "CHAN C12X31LB/FT"
  ChannelData "MC10 x 33.6LB/FT", "MC", 10, 33.6, 0.575, 4.1, 0.575, "CHAN C10X33.6LB/FT"
  ChannelData "MC12 x 35LB/FT", "MC", 12, 35, 0.467, 3.767, 0.7, "CHAN C12X35LB/FT"
  ChannelData "MC12 x 40LB/FT", "MC", 12, 40, 0.59, 3.89, 0.7, "CHAN C12X40LB/FT"
  ChannelData "MC10 x 41.1LB/FT", "MC", 10, 41.1, 0.796, 4.321, 0.575, "CHAN C10X41.1LB/FT"
  ChannelData "MC12 x 45LB/FT", "MC", 12, 45, 0.712, 4.012, 0.7, "CHAN C12X45LB/FT"
  ChannelData "MC12 x 50LB/FT", "MC", 12, 50, 0.835, 4.135, 0.7, "CHAN C12X50LB/FT"
  ChannelCnt = ChannelCnt - 1
End Sub

Sub main()
    Dim nRetVal             As Long
    Dim ModelOK             As Boolean

    Set swApp = CreateObject("SldWorks.Application")

    ' Make sure that there is a model to add the
    ' page to.  If there is no model get rid
    ' of references to any previoud pages.
    Set Part = swApp.ActiveDoc            ' Get active document
    Set swPage = Nothing
    
    ' Ensure we have a model
    If Not Part Is Nothing Then
      FileTyp = Part.GetType              ' Get document type
      If FileTyp = swDocPART Then         ' Is it a part model?
        Set ModelDocExt = Part.Extension
        MassValue = ModelDocExt.GetMassProperties(1, MassStatus)
        
        If MassStatus = swMassPropertiesStatus_OK Then
          
          ModelOK = False
          ' See if needed paramaters exixt
          On Error GoTo ParameterError
          Temp = Part.Parameter("Height@Profile").SystemValue
          Temp = Part.Parameter("WebThick@Profile").SystemValue
          Temp = Part.Parameter("Width@Profile").SystemValue
          Temp = Part.Parameter("ToeThick@Profile").SystemValue
          Temp = Part.Parameter("Angle@Profile").SystemValue
          ModelOK = True
ParameterError:
          On Error GoTo 0
          
          If ModelOK = True Then
            BuildChanData
            If swPage Is Nothing Then
                Set swPage = New ChanMgr
                swPage.Show 'display it
            Else
                swPage.Show
            End If
          Else
            MsgBox "Required parameters not found.  This may not be a channel model.", vbExclamation
          End If
        Else
          MsgBox "Part model has no mass.  This is not a channel model.", vbExclamation
        End If
      Else
        MsgBox "Current document is not a part model.  Please start with a part model.", vbExclamation
      End If
    Else
      MsgBox "Could not automatically load part.  Please start with a part model.", vbExclamation
    End If

End Sub
'-----------------------------------------------------------



