Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to embed an .h3d (Hyperworks output file) file? #967

Open
avipek10 opened this issue Apr 11, 2024 · 3 comments
Open

How to embed an .h3d (Hyperworks output file) file? #967

avipek10 opened this issue Apr 11, 2024 · 3 comments

Comments

@avipek10
Copy link

I am trying to use the pptx python package to programmatically embed an existing h3d file (Hyperworks output file) into a power point presentation.

I know it can be done manually by drag and drop the file into the power point but I would like to do it programmatically.

@MizsakPeterEcon
Copy link

Hi @avipek10!
To embed files into PowerPoint presentation, you can use the following function:
https://python-pptx.readthedocs.io/en/stable/api/shapes.html#pptx.shapes.shapetree.SlideShapes.add_ole_object

Here is a basic example to do so:

from pptx import Presentation
from pptx.util import Inches

prs = Presentation()
slide_layout = prs.slide_layouts[5]  # Title and Content layout
slide = prs.slides.add_slide(slide_layout)

slide.shapes.title.text = "Adding h3d file"
path_to_h3d = "test.h3d"
slide.shapes.add_ole_object(
    object_file=path_to_h3d, prog_id="Package", left=Inches(2), top=Inches(2)
)
prs.save("add_h3d.pptx")

Further improvement possibilities:

  • When .h3d is inserted by drag-and-drop, the prog_id is set to Package as the application is unknown, but if you know the prog_id for HyperWorks, you can replace that.
  • You can add icon_file as well for better aesthetics.

@avipek10
Copy link
Author

Thank for the response.
It did embed something but when double click inside the power point I get an error message.

Uploading h3d_embed_error.png…

@avipek10
Copy link
Author

sorry it did not upload the picture last time.

h3d_embed_error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants