Change image on Inventor Setup Sheet

Change image on Inventor Setup Sheet

robert.hempelFQCMR
Contributor Contributor
1,315 Views
12 Replies
Message 1 of 13

Change image on Inventor Setup Sheet

robert.hempelFQCMR
Contributor
Contributor

Hello 🙂

 

I was wondering if there is a way to change the image displayed on the setup sheet.

By default the current view of the model will be displayed. Ideally I would like to

display an idw page. Alternatively I would like to change the path to a screenshot of an idw.

Is this possible by editing something in this code snippet of the .cps file?

 

 

  if (getProperty("showPreviewImage")) {
    var patternId = currentSection.getPatternId();
    var show = false;
    if (getProperty("forcePreview") || !seenPatternIds[patternId]) {
      show = true;
      seenPatternIds[patternId] = true;
    }
    if (show && currentSection.hasParameter("autodeskcam:preview-name")) {
      var path = currentSection.getParameter("autodeskcam:preview-name");
      var absPath = FileSystem.getCombinedPath(FileSystem.getFolderPath(getOutputPath()), path);
      if (FileSystem.isFile(absPath)) {

        if (getProperty("embedImages") && (revision >= 41366)) {
          src=getImageAsImgSrc(absPath);
          FileSystem.remove(absPath);
        } else {
          src=encodeURIComponent(path);
        }

        var r2 = "<table class=\"info\" cellspacing=\"0\">" +
          makeRow("<td class=\"preview\"><img src=\"" + src + "\"/></td>") +
          "</table>";
        write(
          "<tr class=\"info\">" +
          "<td colspan=\"4\" valign=\"top\" align=\"center\">" + r2 + "</td>" +
          "</tr>"
        );
      }
    }
  }

 

Accepted solutions (1)
1,316 Views
12 Replies
Replies (12)
Message 2 of 13

serge.quiblier
Autodesk
Autodesk

Hi @robert.hempelFQCMR 

 

when you are "posting" the setup sheet, the system is using this keyword from the top of the post,  to grab the picture:

keywords = "MODEL_IMAGE";

 

See the API help file for further reference:

https://cam.autodesk.com/posts/reference/keywords.html

 

But that means we can't select which picture will be generated.

If you want to use your own picture, you must find a way to create it before posting, the add a property to select your picture and use this one instead of the one generated automatically in the output folder.

 

Regards.


______________________________________________________________

If my post answers your question, please click the "Accept Solution" button. This helps everyone find answers more quickly!



Serge.Q
Technical Consultant
cam.autodesk.com
0 Likes
Message 3 of 13

robert.hempelFQCMR
Contributor
Contributor

Hi @serge.quiblier,

 

thanks for your answer. Unfortunately I don't quite understand what you mean by "using this keyword from the top of the post".

At what point do I use this keyword? Could you please give me an example?

 

Greetings!

0 Likes
Message 4 of 13

serge.quiblier
Autodesk
Autodesk

Hi @robert.hempelFQCMR 

 

You didn't really use it yourself, but the post you are using, is declaring this variable at the top of it's script.

Extracting the first lines of the setup sheet post processor we can see this :

/**
  Copyright (C) 2012-2021 by Autodesk, Inc.
  All rights reserved.

  Setup sheet configuration.

  $Revision$
  $Date$

  FORKID {BC98C807-412C-4ffc-BD2B-ABB3F0A59DB8}
*/

description = "Setup Sheet (HTML)";
vendor = "Autodesk";
vendorUrl = "http://www.autodesk.com";
legal = "Copyright (C) 2012-2021 by Autodesk, Inc.";
certificationLevel = 2;

longDescription = "Setup sheet for generating an HTML document with the relevant details for the setup, tools, and individual operations. You can print the document directly or alternatively convert it to a PDF file for later reference.";

capabilities = CAPABILITY_SETUP_SHEET;
extension = "html";
mimetype = "text/html";
keywords = "MODEL_IMAGE PREVIEW_IMAGE";
setCodePage("utf-8");
dependencies = "setup-sheet.css";

 

Please notice the line beginning by keywords, in the last extracted lines.

MODEL_IMAGE is telling Fusion that before posting the file, it need to create a picture representing the model and save it to the folder where the outputted will be generated. Then it add the name of this picture in the intermediate file providing the information to the post engine for the output generation (gcode, or setup sheet).

 

You don't have the choice of what will be generated. It's the model... and the model only.

When you add PREVIEW_IMAGE
The post configuration can use preview images for each operation.

PREVIEW_IMAGE_ALWAYS

The post configuration expects a preview image for every operation.

 

Regards.


______________________________________________________________

If my post answers your question, please click the "Accept Solution" button. This helps everyone find answers more quickly!



Serge.Q
Technical Consultant
cam.autodesk.com
0 Likes
Message 5 of 13

AchimN
Community Manager
Community Manager
Accepted solution

You can do the following to get a custom image into your setup sheet:

 

1. Add this property to the properties of your setup sheet post:

 

 

customImage: {
  title : "Custom image",
  description: "Select a custom image file to be displayed in the setup sheet",
  type : "file",
  value : "",
  scope : "post"
}

 

 

 

2. Search for this code in the setup sheet post:

 

 

        var path = FileSystem.getCombinedPath(FileSystem.getFolderPath(getOutputPath()), modelImagePath);
        var src="";
        if (!FileSystem.isFile(path)) {
          warning(subst(localize("Model image doesn't exist '%1'."), path));
        } else {
          if (getProperty("embedImages") && (revision >= 41366)) {
            // add support for image from database instead
            src=getImageAsImgSrc(path);
            FileSystem.remove(path);
          } else {
            src=encodeURIComponent(modelImagePath);
          }
        }

 

 

 and replace it with this:

 

 

        if (getProperty("customImage") == "") {
          var path = FileSystem.getCombinedPath(FileSystem.getFolderPath(getOutputPath()), modelImagePath);
        } else {
          var path = getProperty("customImage");
        }
        var src="";
        if (!FileSystem.isFile(path)) {
          warning(subst(localize("Model image doesn't exist '%1'."), path));
        } else {
          if (getProperty("embedImages") && (revision >= 41366)) {
            // add support for image from database instead
            src=getImageAsImgSrc(path);
            if (getProperty("customImage") == "") {
              FileSystem.remove(path);
            }
          } else {
            src=encodeURIComponent(modelImagePath);
          }
        }

 

 

 

When this is done, the following property will show up in your post process dialog and by right click you are able to select your desired image file:

AchimN_1-1669973147353.png


Result:

AchimN_2-1669973296922.png

 



Achim.N
Principal Technology Consultant
Message 6 of 13

robert.hempelFQCMR
Contributor
Contributor

Hi @AchimN ,

 

thanks for your answer, that's just the way we intented! Unfortunately the code doesn't work for me.

That's my properties:

properties = {
  embedStylesheet: {
    title      : "Embed stylesheet",
    description: "Embeds the stylesheet in the HTML code.",
    type       : "boolean",
    value      : true,
    scope      : "post"
  },
  useUnitSymbol: {
    title      : "Use unit symbol",
    description: "Specifies that symbols should be used for units (some printers may not support this).",
    type       : "boolean",
    value      : false,
    scope      : "post"
  },
  showDocumentPath: {
    title      : "Show document path",
    description: "Specifies that the document path should be output.",
    type       : "boolean",
    value      : true,
    scope      : "post"
  },
  showModelImage: {
    title      : "Show model image",
    description: "If enabled, a model image will be included in the setup sheet.",
    type       : "boolean",
    value      : true,
    scope      : "post"
  },
  showToolImage: {
    title      : "Show tool images",
    description: "If enabled, tool images will be included in the setup sheet.",
    type       : "boolean",
    value      : true,
    scope      : "post"
  },
  showPreviewImage: {
    title      : "Show preview image",
    description: "If enabled, a preview image will be included in the setup sheet.",
    type       : "boolean",
    value      : true,
    scope      : "post"
  },
  previewWidth: {
    title      : "Preview width",
    description: "Specifies the width of the preview image.",
    type       : "string",
    value      : "8cm",
    scope      : "post"
  },
  showPercentages: {
    title      : "Show percentages",
    description: "Specifies that the percentage of the total cycle time should be shown for each operation cycle time.",
    type       : "boolean",
    value      : true,
    scope      : "post"
  },
  showFooter: {
    title      : "Show footer",
    description: "Specifies whether a footer should be included in the HTML setup sheet.",
    type       : "boolean",
    value      : true,
    scope      : "post"
  },
  showRapidDistance: {
    title      : "Show rapid distance",
    description: "Specifies whether the rapid distance should be output.",
    type       : "boolean",
    value      : true,
    scope      : "post"
  },
  rapidFeed: {
    title      : "Rapid feed",
    description: "Sets the rapid traversal feedrate. Set this to get more accurate cycle times.",
    type       : "number",
    value      : 5000,
    scope      : "post"
  },
  toolChangeTime: {
    title      : "Tool change time",
    description: "Sets the tool change time in seconds. Set this to get more accurate cycle times.",
    type       : "number",
    value      : 15,
    scope      : "post"
  },
  showNotes: {
    title      : "Show notes",
    description: "Writes operation notes as comments in the outputted code.",
    type       : "boolean",
    value      : true,
    scope      : "post"
  },
  forcePreview: {
    title      : "Force preview",
    description: "Enable to force a preview picture for all instances of a pattern.",
    type       : "boolean",
    value      : false,
    scope      : "post"
  },
  showOperations: {
    title      : "Show operations",
    description: "Enable to output information for each operation.",
    type       : "boolean",
    value      : true,
    scope      : "post"
  },
  showTools: {
    title      : "Show tools",
    description: "Enable to see information for each tool.",
    type       : "boolean",
    value      : true,
    scope      : "post"
  },
  showTotals: {
    title      : "Show totals",
    description: "Enable to see total information.",
    type       : "boolean",
    value      : true,
    scope      : "post"
  },
  embedImages: {
    title      : "Embed images",
    description: "If enabled, images are embedded into the HTML file.",
    type       : "boolean",
    value      : true,
    scope      : "post"
  },
  customImage: {
    title : "Custom image",
    description: "Select a custom image file to be displayed in the setup sheet",
    type : "file",
    value : "",
    scope : "post"
  }​
};

 

That's the other part of the code:

 if (modelImagePath && getProperty("showModelImage")) {
        if (getProperty("customImage") == "") {
          var path = FileSystem.getCombinedPath(FileSystem.getFolderPath(getOutputPath()), modelImagePath);
        } else {
          var path = getProperty("customImage");
        }
        var src="";
        if (!FileSystem.isFile(path)) {
          warning(subst(localize("Model image doesn't exist '%1'."), path));
        } else {
          if (getProperty("embedImages") && (revision >= 41366)) {
            // add support for image from database instead
            src=getImageAsImgSrc(path);
            if (getProperty("customImage") == "") {
              FileSystem.remove(path);
            }
          } else {
            src=encodeURIComponent(modelImagePath);
          }
        }

        ++numberOfColumns;
        var alignment = (numberOfColumns <= 1) ? "center" : "right";
        write("<td class=\"model\" align=\"" + alignment + "\"><img src=\"" + src + "\"/></td>");
      }

 

Have I done something wrong?

0 Likes
Message 7 of 13

AchimN
Community Manager
Community Manager

Can you please share your setup sheet post? I´ll have a look into it then.



Achim.N
Principal Technology Consultant
0 Likes
Message 8 of 13

robert.hempelFQCMR
Contributor
Contributor

Of course. Thank you!

0 Likes
Message 9 of 13

AchimN
Community Manager
Community Manager

Seems that there is an illegal character at the end of your property:

AchimN_1-1673250010484.png



Achim.N
Principal Technology Consultant
0 Likes
Message 10 of 13

robert.hempelFQCMR
Contributor
Contributor

But the } needs to be there, doesn't it?

When I remove it still doesn't work.

What program are you using to view the file? I am using Notepad++, so I can't see any possible errors.

0 Likes
Message 11 of 13

serge.quiblier
Autodesk
Autodesk

Hello @robert.hempelFQCMR 

 

when using VSCode we have this warning message:

sergequiblier_0-1673254234643.png

 

Try to deleted the line 164 and 163, and the rewrite them in order to suppress this invisible character.

 

Regards.

 


______________________________________________________________

If my post answers your question, please click the "Accept Solution" button. This helps everyone find answers more quickly!



Serge.Q
Technical Consultant
cam.autodesk.com
0 Likes
Message 12 of 13

AchimN
Community Manager
Community Manager

Yes it needs to be there, but the illegal character is after the ' } '.
Its probably the easiest when you delete that property from your post, copy my suggested code from this thread and paste that code again into your post. Works fine here.

I am using Visual Studio Code (for which we do have an addin which allows you to postprocess directly within VS Code during post editing)



Achim.N
Principal Technology Consultant
0 Likes
Message 13 of 13

robert.hempelFQCMR
Contributor
Contributor

Now it works! Thank you very much! 🙂

0 Likes