Search code examples
google-apps-scriptgoogle-slides-apigoogle-slides

Put dotted/dashed lines on layout in Google Slides


Updated : with the help of The Master solution .setDashStyle(SlidesApp.DashStyle.DOT);

Trying to insert dotted/dashed lines on the layout in Google Slide. But my solution gives me straight lines and the height of the lines are limited to the slide.

This method shows how to use the insert line. https://developers.google.com/apps-script/reference/slides/page#insertlinelinecategory,-startleft,-starttop,-endleft,-endtop

Enum LineCategory - No any dashed/dotted type of line : https://developers.google.com/apps-script/reference/slides/line-category

Above 2 articles not supporting the dotted/dashed line with full layout(outside the slide).

function dottedLines() {
         var slide = SlidesApp.getActivePresentation();
         var slideHt = slide.getPageHeight();
         var slideWd = slide.getPageWidth();
         var prevLeft = 0;
         var prevTop = 0;
        
         for (var i = 0; i < 3; i++) {
             //Vertical lines
             prevLeft = prevLeft + (slideWd / 3); 
             var startPoint = {
                 left: prevLeft,
                 top: 0
             };
             var endPoint = {
                 left: prevLeft,
                 top: slideHt
             };
             slide.getSlides()[0].insertLine(
                 SlidesApp.LineCategory.STRAIGHT,
                 startPoint.left,
                 startPoint.top,
                 endPoint.left,
                 endPoint.top
             ).setDashStyle(SlidesApp.DashStyle.DOT);
         }

------------more script --------
------------more script --------
------------more script --------
------------more script --------
     }

Please see attached image here for more requirement


Solution

  • LineCategory only refers to "curve" of the line- whether it is STRAIGHT or BENT.

    To create dashed/dotted line, .setDashStyle() on the line created, which can be SOLID or DOT or DASH