Set application = WScript.CreateObject("PowerPoint.Application")

msoLineSolid = 1
' In Microsoft document SquareDot value is 2
msoLineSquareDot = 10
' In Microsoft document SquareDot value is 3
msoLineRoundDot = 11
msoLineDash = 4
msoLineDashDot = 5
msoLineLongDash = 7
msoLineLongDashDot = 8
msoLineDashDotDot = 6
msoLineLongDashDotDot = 9

msoLineSingle = 1
msoLineThinThin = 2
msoLineThinThick = 3
msoLineThickThin = 4
msoLineThickBetweenThin = 5

' Get arguments
If WScript.Arguments.Length > 0 Then
    isNoLine = WScript.Arguments(0)
    lineWeight = WScript.Arguments(1)
    compoundFormat = WScript.Arguments(2)
    dashFormat = WScript.Arguments(3)
    lineColor = Split(WScript.Arguments(4), ",")
    isNoFill = WScript.Arguments(5)
    isSolidFill = WScript.Arguments(6)
    isGradientFill = WScript.Arguments(7)
    solidColor = Split(WScript.Arguments(8), ",")
	' Convert transparency to 0-1 scale
    solidTransparency = WScript.Arguments(9) / 100 
    gradientType = WScript.Arguments(10)
    gradientDirection = WScript.Arguments(11)
    gradientAngle = WScript.Arguments(12)
    stopData = Split(WScript.Arguments(13), "*")
Else
    Call Err.Raise(60003, , "Shape properties are not provided")
End If

If application.SlideShowWindows.Count > 0 Then
    ' Run when in presentation mode
    Call Err.Raise(60002, , "PowerPoint is in presentation mode. Cannot perform operation.")
Else
    ' Run when not in presentation mode
    With application.ActiveWindow.Selection.ShapeRange.Line
        
        If isNoLine = "true" Then
            .Visible = 0
        Else
            ' Case solid line 
            .Visible = 1
            ' Set line weight
            If lineWeight = "" Then
            Else
                .Weight = lineWeight
            End If
            
            ' Set dash line format
            If dashFormat = "solid" Then
                .DashStyle = msoLineSolid
            ElseIf dashFormat = "square_dot" Then
                .DashStyle = msoLineSquareDot
            ElseIf dashFormat = "round_dot" Then
                .DashStyle = msoLineRoundDot
            ElseIf dashFormat = "dash" Then
                .DashStyle = msoLineDash
            ElseIf dashFormat = "dash_dot" Then
                .DashStyle = msoLineDashDot
            ElseIf dashFormat = "long_dash" Then
                .DashStyle = msoLineLongDash
            ElseIf dashFormat = "long_dash_dot" Then
                .DashStyle = msoLineLongDashDot
            ElseIf dashFormat = "long_dash_dot_dot" Then
                .DashStyle = msoLineLongDashDotDot
            End If

            ' Set compound line format
            If compoundFormat = "single" Then
                .Style = msoLineSingle
            ElseIf compoundFormat = "thin_thin" Then
                .Style = msoLineThinThin
            ElseIf compoundFormat = "thin_thick" Then
                .Style = msoLineThinThick
            ElseIf compoundFormat = "thick_thin" Then
                .Style = msoLineThickThin
            ElseIf compoundFormat = "thick_between_thin" Then
                .Style = msoLineThickBetweenThin
            End If
            
        End If

        ' Set line color
        .ForeColor.RGB = RGB(lineColor(0), lineColor(1), lineColor(2))
    End With

    ' Set fill color
    With application.ActiveWindow.Selection.ShapeRange.Fill
        If isNoFill = "true" Then
            .Visible = False
        ElseIf isSolidFill = "true" Then
            .Solid
            .ForeColor.RGB = RGB(solidColor(0), solidColor(1), solidColor(2))
            .Transparency = solidTransparency
        ElseIf isGradientFill = "true" Then

            If (gradientType = "LINEAR") Then
                If (gradientDirection = "tlbr") Then
                    .OneColorGradient 3, 1, 1
                ElseIf (gradientDirection = "bltr") Then
                    .OneColorGradient 4, 2, 1
                ElseIf (gradientDirection = "trbl") Then
                    .OneColorGradient 4, 1, 1
                ElseIf (gradientDirection = "brtl") Then
                    .OneColorGradient 3, 2, 1
                ElseIf (gradientDirection = "ld") Then
                    .OneColorGradient 1, 1, 1
                ElseIf (gradientDirection = "lu") Then
                    .OneColorGradient 1, 2, 1
                ElseIf (gradientDirection = "lr") Then
                    .OneColorGradient 2, 1, 1
                ElseIf (gradientDirection = "ll") Then
                    .OneColorGradient 2, 2, 1
                ElseIf (gradientDirection = "custom") Then
                    .OneColorGradient 1, 1, 1
                    .GradientAngle = gradientAngle
                End If
                
            ElseIf (gradientType = "RETANGULAR") Then
                If (gradientDirection = "fbr") Then
                    .OneColorGradient 5, 4, 1
                ElseIf (gradientDirection = "fbl") Then
                    .OneColorGradient 5, 3, 1
                ElseIf (gradientDirection = "fc") Then
                    .OneColorGradient 7, 1, 1
                ElseIf (gradientDirection = "ftr") Then
                    .OneColorGradient 5, 2, 1
                ElseIf (gradientDirection = "ftl") Then
                    .OneColorGradient 5, 1, 1
                End If
                
            ElseIf (gradientType = "PATH") Then
                .OneColorGradient 7, 1, 1
            End If
            
            index = 0
            For Each stopValue In stopData
                index = index + 1
                properties = Split(stopValue, "-")
                
                If UBound(properties) > 0 Then
                    stopColor = Split(properties(0), ",")
                    stopPosition = properties(1) / 100
                    stopTransparency = properties(2) / 100
                    ' If exceed 2 stops, we need to insert new stop
                    If index > 2 Then
                        .GradientStops.Insert RGB(stopColor(0), stopColor(1), stopColor(2)), stopPosition, stopTransparency
                    End If
                    ' Insert stop 1 and stop 2
                    .GradientStops(index).Color.RGB = RGB(stopColor(0), stopColor(1), stopColor(2))
                    .GradientStops(index).Position = stopPosition
                    .GradientStops(index).Transparency = stopTransparency
                End If
            Next
            
        End If
    End With
    
End If