Powerpoint interaction

Beta
Beta New Altair Community Member
edited October 2020 in Community Q&A

Hi,

 

I know that it is possible to publish to PPTs in Hyperview. 

 

I want to do a similar thing in HyperMesh. 

 

My process is:

 

- Take a screenshot in Hypermesh.

- Open a new Powerpoint presentation and put the picture from screenshot into it by using TCl.

 

I got some trouble in using TCL to start PowerPoint and modify an existed ppt file.

 

Below is the code I have tried but it doesn't work.  It kept telling me that the path could not be found.

 

Could anyone please help me with this

 package require twapi set ppt [::twapi::comobj PowerPoint.Application] $ppt DisplayAlerts [expr 0] set present [$ppt Presentations] $present Open 'D:/Presentation2.pptx'

 

Answers

  • Q.Nguyen-Dai
    Q.Nguyen-Dai Altair Community Member
    edited November 2018

    Maybe try in your TCL script: after taking the images, create a VBScript to insert them into PPT? You can execute a VBScript from TCL.

  • tinh
    tinh Altair Community Member
    edited November 2018

    Hi,

    Hi,

     

    I know that it is possible to publish to PPTs in Hyperview. 

     

    I want to do a similar thing in HyperMesh. 

     

    My process is:

     

    - Take a screenshot in Hypermesh.

    - Open a new Powerpoint presentation and put the picture from screenshot into it by using TCl.

     

    I got some trouble in using TCL to start PowerPoint and modify an existed ppt file.

     

    Below is the code I have tried but it doesn't work.  It kept telling me that the path could not be found.

     

    Could anyone please help me with this

      package require twapi set ppt [::twapi::comobj PowerPoint.Application] $ppt DisplayAlerts [expr 0] set present [$ppt Presentations] $present Open 'D:/Presentation2.pptx'

     

     

     

    Are you sure it reported 'path not found'?

     

    I see error 'PowerPoint Frame Window doest not exist'

    before open a file, you must show the window:

    https://docs.microsoft.com/en-us/office/vba/api/powerpoint.application

  • Beta
    Beta New Altair Community Member
    edited November 2018

    @Q.Nguyen-Dai Thank you for your suggestion, That means I have to learn more about VBA to write this scripts. not gonna be easy :).

     

    @tinh  on my HM, they said that 'path not found'. I will try your method. Thanks for the advice

  • tinh
    tinh Altair Community Member
    edited November 2018

    I tested, and it worked on my file

    In your case, check file path first (I think not existing or wrong name)

  • Beta
    Beta New Altair Community Member
    edited November 2018

    The problem I got is kind of weird.

     

    5 minutes ago, the code worked well. and then, few later, the error showed up again

    image.png.1627d9c41e46c83b0cc5881bf303d282.png

     

    I cannot understand at all

  • tinh
    tinh Altair Community Member
    edited November 2018

    I am not sure. my tests are no problem.

    Try again after close all POWERPOINT.EXE processes (some of them may be hidden, you can see them in task manager)

     

    https://docs.microsoft.com/en-us/office/vba/api/powerpoint.application

    Capture.PNG.6951704f971aa62786620e9400ea2ed5.PNG

     

    Tcl:

     package require twapi set ppt [::twapi::comobj PowerPoint.Application] $ppt DisplayAlerts 0 $ppt Visible 1 set present [$ppt Presentations] $present Open 'D:/Presentation2.pptx'
  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited November 2018

    Hi,

     

    PowerPoint can't identify the file path includeing slashes as separators.

    Try:

     $present Open [file nativename 'D:/Presentation2.pptx']

     

  • tinh
    tinh Altair Community Member
    edited November 2018

    Hi,

     

    PowerPoint can't identify the file path includeing slashes as separators.

    Try:

      $present Open [file nativename 'D:/Presentation2.pptx']

     

     

    I thought so, but in my case it worked.

  • Beta
    Beta New Altair Community Member
    edited November 2018

    @akitoguc Thanks you so much for your suggestion. Actually, I found that it worked with slashes when open files but not for some other functions. I have been stuck for a long time with the code to insert pictures to PPTs. Thanks for your advice, it works now. 

     

    For the problem 'The system cannot find the file specified',  I believe that is due to some issue with twapi package when the script could not successfully run. It backs to normal when I restart the machine.

     

    Below is my code for anyone interested in. For now, I am aiming to control the size and position of the picture and possibly add some captions with it.

     #get the directory# set dirname [file dirname [info script]] set template_dirname '$dirname/template.pptx' set	ppts_dirname '$dirname/component_list_PPts.pptx'  #handle the files# catch {file delete -force '$ppts_dirname'} file mkdir 'D:/temp_folder' file copy -force '$template_dirname' 'D:/temp_folder' file rename -force 'D:/temp_folder/template.pptx' 'D:/temp_folder/component_list_PPts.pptx' file copy -force '$template_dirname' 'D:/temp_folder'  #modify the PPts# package require twapi set ppt [::twapi::comobj PowerPoint.Application] $ppt DisplayAlerts [expr 0] set presents [$ppt Presentations] $presents Open 'D:/temp_folder/component_list_PPts.pptx'; #Open the Presnetation set active_presentation [$ppt ActivePresentation]; #get the cureently active presentaatin set slides [$active_presentation Slides]; #gte the slide list set slide_1 [$slides Item 1]; #get control on slide index 1 set slide_2 [$slides InsertFromFile 'D:/temp_folder/template.pptx' 1]; #add one more slide into the presentation set slide_3 [$slides InsertFromFile 'D:/temp_folder/template.pptx' 1]; #add one more slide into the presentation set slide_1_shapes [$slide_1 Shapes] return set slide_1_picture [$slide_1_shapes AddPicture [file nativename 'D:/2.bmp'] -1 -1 5 4] 

     

  • Pandurang
    Pandurang Altair Community Member
    edited November 2018

    Does this package works on Linux?

  • llyle_20499
    llyle_20499 New Altair Community Member
    edited November 2018

    Hi,

     

    twapi is for windows and will not work in Linux

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited April 2019

    @akitoguc Thanks you so much for your suggestion. Actually, I found that it worked with slashes when open files but not for some other functions. I have been stuck for a long time with the code to insert pictures to PPTs. Thanks for your advice, it works now. 

     

    For the problem 'The system cannot find the file specified',  I believe that is due to some issue with twapi package when the script could not successfully run. It backs to normal when I restart the machine.

     

    Below is my code for anyone interested in. For now, I am aiming to control the size and position of the picture and possibly add some captions with it.

      #get the directory# set dirname [file dirname [info script]] set template_dirname '$dirname/template.pptx' set	ppts_dirname '$dirname/component_list_PPts.pptx'  #handle the files# catch {file delete -force '$ppts_dirname'} file mkdir 'D:/temp_folder' file copy -force '$template_dirname' 'D:/temp_folder' file rename -force 'D:/temp_folder/template.pptx' 'D:/temp_folder/component_list_PPts.pptx' file copy -force '$template_dirname' 'D:/temp_folder'  #modify the PPts# package require twapi set ppt [::twapi::comobj PowerPoint.Application] $ppt DisplayAlerts [expr 0] set presents [$ppt Presentations] $presents Open 'D:/temp_folder/component_list_PPts.pptx'; #Open the Presnetation set active_presentation [$ppt ActivePresentation]; #get the cureently active presentaatin set slides [$active_presentation Slides]; #gte the slide list set slide_1 [$slides Item 1]; #get control on slide index 1 set slide_2 [$slides InsertFromFile 'D:/temp_folder/template.pptx' 1]; #add one more slide into the presentation set slide_3 [$slides InsertFromFile 'D:/temp_folder/template.pptx' 1]; #add one more slide into the presentation set slide_1_shapes [$slide_1 Shapes] return set slide_1_picture [$slide_1_shapes AddPicture [file nativename 'D:/2.bmp'] -1 -1 5 4] 

    Hello @Toan Nguyen , Did you find a way to control the position ans size of picture, you imported to Powerpoint. I'm also working in the same thing, wherein I need to import screen captures from Hypermesh to PowerPoint. Any help is appreciated. TIA.

     

  • Beta
    Beta New Altair Community Member
    edited May 2019

    Hi @rrishav

     

    Yes, I found the way to control the size and the position of the picture.

     

    You can do that directly when you import the picture with 'AddPicture' command. below is what I have done in my code 

     

     set slide_picture [$slide_shapes AddPicture [file nativename '$picture_folder/comp_$comp.bmp'] -1 -1 80 40 800 400]

    The last four numbers are used to control position (the distance to left and top of the slide) and the size (width and height) of the picture.

     

    Give it a try and you will see