Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SaveAsImageFile No Longer Functioning

1 REPLY 1
Reply
Message 1 of 2
agoMJ99C
242 Views, 1 Reply

SaveAsImageFile No Longer Functioning

I have created a code to incrementally increase specific parameters in a model, then save an image file of each. It worked perfectly once I created the code, however, I attempted to run the code the day after, and it ceased to save the image files. It is throwing no errors and is otherwise functioning perfectly. I hope someone on here is able to see something that I cannot.

 

Here's the code:

 

function run(context) {

"use strict";
if (adsk.debug === true) {
/*jslint debug: true*/
debugger;
/*jslint debug: false*/
}

var ui;
try {
var app = adsk.core.Application.get();
ui = app.userInterface;

var des = adsk.fusion.Design.cast(app.activeProduct);

var resultFolder = 'C:/Temp/';

var param1 = des.allParameters.itemByName("Length");
var param2 = des.allParameters.itemByName("Depth");
var param3 = des.allParameters.itemByName("Height");

for (var i = 66.0; i < 78.0; i++)
{
param1.expression = i + " in";
for (var j = 21; j < 34.0; j++){
param2.expression = j + " in";
for (var k = 25; k < 25.0; k++){
param3.expression = k + " in";
var filename = resultFolder + param1.expression + "x" + param2.expression + "x" + param3.expression + ".jpg";
app.activeViewport.saveAsImageFile(filename, 0, 0);
}
}
}
ui.messageBox('Finished.');
}
catch (e) {
if (ui) {
ui.messageBox('Failed : ' + (e.description ? e.description : e));
}
}

adsk.terminate();
}

function pad(num, size)
{
var s = num + "";
while (s.length < size)
{
s = "0" + s;
}
return s;
}

1 REPLY 1
Message 2 of 2
liujac
in reply to: agoMJ99C

Hi,

 

There is a mistake in your code "for (var k = 25; k < 25.0; k++)" that causes the saveAsImageFile method is never called. Change the code to "for (var k = 25; k < 26; k++)", it will work.

 

Jack

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report