<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Python error in automated powerpoint creation in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Python-error-in-automated-powerpoint-creation/m-p/681865#M86753</link>
    <description>&lt;P&gt;Hi Jarmo, Your suggestion that the path was wrong was indeed one of the two things wrong with the code above. I didn't realize that the \" in the end of the file path was actually preventing the code to properly saving the file in the right location. Thanks for the help!&lt;/P&gt;</description>
    <pubDate>Thu, 28 Sep 2023 04:09:38 GMT</pubDate>
    <dc:creator>neelsrejan</dc:creator>
    <dc:date>2023-09-28T04:09:38Z</dc:date>
    <item>
      <title>Python error in automated powerpoint creation</title>
      <link>https://community.jmp.com/t5/Discussions/Python-error-in-automated-powerpoint-creation/m-p/681447#M86703</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a JSL script that outputs about 10 graphs in individual windows. I am working on a way to input each graph into its own slide in a powerpoint. Due to the complexities of the pictures I saw there was a way to use python's python-pptx package to accomplish this and I am able to create all the slides with a title but am unable to get the picture into the powerpoint at all. Below is the code snippet I am working with and the line that is commented out is the line that it's breaking at. I know this since the commented out line puts the picture and powerpoint in the right folder and opens seamlessly. But when uncommented the picture is saved but the following line where the ppt gets saved to the file folder never happens and likewise Jmp says it can't open the non-existant file. I have tried everything from using f strings to concatenations of the string to get the picture in the ppt but am unable. Any help would be much appreciated. Thanks!&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Open("$SAMPLE_DATA/Big Class.jmp");
biv = dt &amp;lt;&amp;lt; Bivariate( Y( :height ), X( :weight ) );

ppt_dir = "C:\Users\neel\Documents\new jmp\";
number = "12345678";

graph holding = H List Box();
graph holding &amp;lt;&amp;lt; append(Report(biv));
pic holding = H List Box();
pic holding &amp;lt;&amp;lt; append(graph holding &amp;lt;&amp;lt; get picture);
pic_file = "example.png";
pic holding &amp;lt;&amp;lt; Save Picture(ppt_dir || pic_file);

Python Init();
plog = Python Execute({ppt_dir, number, pic_file}, {img_path, left, top, height},
"\[
from pptx import Presentation
from pptx.util import Inches

img_path = ppt_dir + pic_file

prs = Presentation()

slide_1 = prs.slides.add_slide(prs.slide_layouts[0])
slide_1.shapes.title.text = "Review of " + number

slide_2 = prs.slides.add_slide(prs.slide_layouts[5])
slide_2.shapes.title.text = "Results"

slide_3 = prs.slides.add_slide(prs.slide_layouts[5])
slide_3.shapes.title.text = "Summary"

left = top = Inches(2)
#pad_summary_pic = slide_3.shapes.add_picture(img_path, left, top, height=height)

prs.save(rf"{ppt_dir}{number} Review.pptx")
]\"
);
Python Term();

//Open PPT
ppt = ppt_dir || number || " Review.pptx";
Open(ppt);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Above works without the picture being added.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Open("$SAMPLE_DATA/Big Class.jmp");
biv = dt &amp;lt;&amp;lt; Bivariate( Y( :height ), X( :weight ) );

ppt_dir = "C:\Users\neel\Documents\new jmp\";
number = "12345678";

graph holding = H List Box();
graph holding &amp;lt;&amp;lt; append(Report(biv));
pic holding = H List Box();
pic holding &amp;lt;&amp;lt; append(graph holding &amp;lt;&amp;lt; get picture);
pic_file = "example.png";
pic holding &amp;lt;&amp;lt; Save Picture(ppt_dir || pic_file);

Python Init();
plog = Python Execute({ppt_dir, number, pic_file}, {img_path, left, top, height},
"\[
from pptx import Presentation
from pptx.util import Inches

img_path = ppt_dir + pic_file

prs = Presentation()

slide_1 = prs.slides.add_slide(prs.slide_layouts[0])
slide_1.shapes.title.text = "Review of " + number

slide_2 = prs.slides.add_slide(prs.slide_layouts[5])
slide_2.shapes.title.text = "Results"

slide_3 = prs.slides.add_slide(prs.slide_layouts[5])
slide_3.shapes.title.text = "Summary"

left = top = Inches(2)
pad_summary_pic = slide_3.shapes.add_picture(img_path, left, top, height=height)

prs.save(rf"{ppt_dir}{number} Review.pptx")
]\"
);
Python Term();

//Open PPT
ppt = ppt_dir || number || " Review.pptx";
Open(ppt);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This one with the add_picture uncommented doesn't.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Neel&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2023 02:50:06 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Python-error-in-automated-powerpoint-creation/m-p/681447#M86703</guid>
      <dc:creator>neelsrejan</dc:creator>
      <dc:date>2023-09-27T02:50:06Z</dc:date>
    </item>
    <item>
      <title>Re: Python error in automated powerpoint creation</title>
      <link>https://community.jmp.com/t5/Discussions/Python-error-in-automated-powerpoint-creation/m-p/681478#M86705</link>
      <description>&lt;P&gt;Have you tried running it just as python code with no JMP at all (is this Python or JMP problem)? Any error messages? My initial guess would be that the path could be built wrong. To my knowledge, in Python it is usually good idea to use&amp;nbsp;&lt;A href="https://docs.python.org/3/library/os.path.html" target="_blank"&gt;os.path — Common pathname manipulations — Python 3.11.5 documentation&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2023 05:15:54 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Python-error-in-automated-powerpoint-creation/m-p/681478#M86705</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-09-27T05:15:54Z</dc:date>
    </item>
    <item>
      <title>Re: Python error in automated powerpoint creation</title>
      <link>https://community.jmp.com/t5/Discussions/Python-error-in-automated-powerpoint-creation/m-p/681606#M86717</link>
      <description>&lt;P&gt;In addition to &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;&amp;nbsp; comments: put the python code into a python try block and catch and handle any exception. JMP's handling of the exception is hiding it from you. Running the python code outside of JMP will also work.&lt;/P&gt;
&lt;P&gt;&lt;LI-MESSAGE title="Browser Scripting with Python Selenium" uid="485000" url="https://community.jmp.com/t5/Uncharted/Browser-Scripting-with-Python-Selenium/m-p/485000#U485000" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-blog-thread lia-fa-icon lia-fa-blog lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp; shows a usage pattern for the try/except that I found helpful; it returns &lt;EM&gt;rc&lt;/EM&gt; as either &lt;STRONG&gt;ok&lt;/STRONG&gt; or the exception message text. Putting the &lt;EM&gt;import&lt;/EM&gt; statements inside the try was really useful.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2023 11:11:41 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Python-error-in-automated-powerpoint-creation/m-p/681606#M86717</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2023-09-27T11:11:41Z</dc:date>
    </item>
    <item>
      <title>Re: Python error in automated powerpoint creation</title>
      <link>https://community.jmp.com/t5/Discussions/Python-error-in-automated-powerpoint-creation/m-p/681614#M86718</link>
      <description>&lt;P&gt;This (highlighted) looks like it could be the issue to me.&amp;nbsp; Perhaps rename the variable "height" to avoid the conflict with the parameter "height"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mmarchandTSI_0-1695813760139.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/57017iA17FBEAAFFCD8C9A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="mmarchandTSI_0-1695813760139.png" alt="mmarchandTSI_0-1695813760139.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2023 11:25:31 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Python-error-in-automated-powerpoint-creation/m-p/681614#M86718</guid>
      <dc:creator>mmarchandTSI</dc:creator>
      <dc:date>2023-09-27T11:25:31Z</dc:date>
    </item>
    <item>
      <title>Re: Python error in automated powerpoint creation</title>
      <link>https://community.jmp.com/t5/Discussions/Python-error-in-automated-powerpoint-creation/m-p/681863#M86751</link>
      <description>&lt;P&gt;Hi, I appreciate the response. Your solution to remove height was one of the two things I realized was wrong with the script. Thank you for the suggestion to my oversight!&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2023 04:06:46 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Python-error-in-automated-powerpoint-creation/m-p/681863#M86751</guid>
      <dc:creator>neelsrejan</dc:creator>
      <dc:date>2023-09-28T04:06:46Z</dc:date>
    </item>
    <item>
      <title>Re: Python error in automated powerpoint creation</title>
      <link>https://community.jmp.com/t5/Discussions/Python-error-in-automated-powerpoint-creation/m-p/681864#M86752</link>
      <description>&lt;P&gt;Thank you for the suggestion. I will look into more ways to catch exceptions/errors thrown by python through jmp. I appreciate the help!&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2023 04:08:01 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Python-error-in-automated-powerpoint-creation/m-p/681864#M86752</guid>
      <dc:creator>neelsrejan</dc:creator>
      <dc:date>2023-09-28T04:08:01Z</dc:date>
    </item>
    <item>
      <title>Re: Python error in automated powerpoint creation</title>
      <link>https://community.jmp.com/t5/Discussions/Python-error-in-automated-powerpoint-creation/m-p/681865#M86753</link>
      <description>&lt;P&gt;Hi Jarmo, Your suggestion that the path was wrong was indeed one of the two things wrong with the code above. I didn't realize that the \" in the end of the file path was actually preventing the code to properly saving the file in the right location. Thanks for the help!&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2023 04:09:38 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Python-error-in-automated-powerpoint-creation/m-p/681865#M86753</guid>
      <dc:creator>neelsrejan</dc:creator>
      <dc:date>2023-09-28T04:09:38Z</dc:date>
    </item>
    <item>
      <title>Re: Python error in automated powerpoint creation</title>
      <link>https://community.jmp.com/t5/Discussions/Python-error-in-automated-powerpoint-creation/m-p/681866#M86754</link>
      <description>&lt;P&gt;Thank you all for the suggestions and help! Through troubleshooting using just python I realized that both the file path and height variable were preventing the file getting saved and importing the picture into the ppt. Below is the working code in case anyone ever needs to reference this!&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Open("$SAMPLE_DATA/Big Class.jmp");
biv = dt &amp;lt;&amp;lt; Bivariate( Y( :height ), X( :weight ) );

ppt_dir = "C:\Users\srejann\Documents";
number = "12345678";

graph holding = H List Box();
graph holding &amp;lt;&amp;lt; append(Report(biv));
pic holding = H List Box();
pic holding &amp;lt;&amp;lt; append(graph holding &amp;lt;&amp;lt; get picture);
pic_file = "example.png";
pic holding &amp;lt;&amp;lt; Save Picture(ppt_dir || "\" || pic_file);

Python Init();
plog = Python Execute({ppt_dir, number, pic_file}, {img_path, left, top},
"\[
from pptx import Presentation
from pptx.util import Inches

img_path = ppt_dir + f"\{pic_file}"

prs = Presentation()

slide_1 = prs.slides.add_slide(prs.slide_layouts[0])
slide_1.shapes.title.text = "Review of " + number

slide_2 = prs.slides.add_slide(prs.slide_layouts[5])
slide_2.shapes.title.text = "Results"

slide_3 = prs.slides.add_slide(prs.slide_layouts[5])
slide_3.shapes.title.text = "Summary"

left = top = Inches(2)
pic = slide_3.shapes.add_picture(img_path, left, top)

prs.save(rf"{ppt_dir}\{number} Review.pptx")
]\"
);
Python Term();

//Open PPT
ppt = ppt_dir || "\" || number || " Review.pptx";
Open(ppt);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Sep 2023 04:15:07 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Python-error-in-automated-powerpoint-creation/m-p/681866#M86754</guid>
      <dc:creator>neelsrejan</dc:creator>
      <dc:date>2023-09-28T04:15:07Z</dc:date>
    </item>
  </channel>
</rss>

