Set application = WScript.CreateObject("PowerPoint.Application")

msoShapeOval = 9
msoShapeRectangle = 1
msoShapeRoundedRectangle = 5
msoShapeCurvedDownRibbon = 100

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

If WScript.Arguments.Length > 0 Then
    shapeType = WScript.Arguments(0)
    textSize = WScript.Arguments(1)
    textStyle = WScript.Arguments(2)
    textColor = Split(WScript.Arguments(3), ",")
    arrowColor = Split(WScript.Arguments(4), ",")
    lineWeight = WScript.Arguments(5)
    compoundFormat = WScript.Arguments(6)
    dashFormat = WScript.Arguments(7)
    lineColor = Split(WScript.Arguments(8), ",")
    isNoFill = WScript.Arguments(9)
    isSolidFill = WScript.Arguments(10)
    isGradientFill = WScript.Arguments(11)
    solidColor = Split(WScript.Arguments(12), ",")
    solidTransparency = WScript.Arguments(13)
    gradientType = WScript.Arguments(14)
    gradientDirection = WScript.Arguments(15)
    gradientAngle = WScript.Arguments(16)
    stopData = Split(WScript.Arguments(17), "*")
    currentPosition = Split(WScript.Arguments(18), ",")
    fontName = WScript.Arguments(19)
    isNoLine = WScript.Arguments(20)
Else
    Call Err.Raise(60003, , "Shape properties are not provided")
End If

If application.SlideShowWindows.Count > 0 Then
    ' Run when in presentation mode
    currentSlide = application.SlideShowWindows.Item(1).View.CurrentShowPosition
Else
    ' Run when not in presentation mode
    currentSlide = application.ActiveWindow.Selection.SlideRange.SlideNumber
End If

' Call AddShape function
Call AddShape()

Public Sub AddShape()
    Set myDocument = application.ActivePresentation.Slides(currentSlide)
    Dim shape
    If shapeType = "CIRCLE" Then
        Set shape = myDocument.Shapes.AddShape(msoShapeOval, currentPosition(0), currentPosition(1), 100, 100)
        Call AddShapeProperties(shape)
    ElseIf shapeType = "RECTANGLE_ROUNDED" Then
        Set shape = myDocument.Shapes.AddShape(msoShapeRoundedRectangle, currentPosition(0), currentPosition(1), 100, 100)
        Call AddShapeProperties(shape)
    ElseIf shapeType = "RECTANGLE" Then
        Set shape = myDocument.Shapes.AddShape(msoShapeRectangle, currentPosition(0), currentPosition(1), 100, 100)
        Call AddShapeProperties(shape)
    ElseIf shapeType = "ARROW" Then
        ' Add arrow
        Set shape = myDocument.Shapes.AddLine(msoShapeCurvedDownRibbon, currentPosition(0), 200, currentPosition(0))
        shape.Line.EndArrowheadStyle = 3
        shape.Line.ForeColor.RGB = RGB(arrowColor(0), arrowColor(1), arrowColor(2))
    Else
        ' Add text box
        Set shape = myDocument.Shapes.AddTextbox(1, currentPosition(0), currentPosition(1), 200, 50)
        shape.TextFrame.TextRange.Text = "Text Box"
        
        With shape.TextFrame.TextRange.Font
            .Name = fontName
            .Size = textSize
            .Color = RGB(textColor(0), textColor(1), textColor(2))
            ' Set text styles
            If InStr(textStyle, "BOLD") > 0 Then
                .Bold = True
            End If
            
            If InStr(textStyle, "ITALIC") > 0 Then
                .Italic = True
            End If
            
            If InStr(textStyle, "UNDERLINE") > 0 Then
                .Underline = True
            End If
            
        End With
    End If
    
End Sub

Public Sub AddShapeProperties(shape)
    With shape.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
            
            ' Set line color
            With shape
                With .Line
                    .ForeColor.RGB = RGB(lineColor(0), lineColor(1), lineColor(2))
                End With
            End With
        End If
    End With

    ' Set fill color
    With shape.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 Sub