javascript list item add

javascript list item add

Anonymous
Not applicable
896 Views
3 Replies
Message 1 of 4

javascript list item add

Anonymous
Not applicable

I am new to creating scripts in Fusion, but am having an issue with creating list items for a dropdown menu.

I know this is a basic item, but if someone could help give me a nudge in the right direction that would be awesome.

 

Thank you,

Matt

0 Likes
897 Views
3 Replies
Replies (3)
Message 2 of 4

ekinsb
Alumni
Alumni

The add-in sample named "AddInSample" that's delivered with Fusion demonstrates creating a command with several different types of command inputs, including two drop-downs.  You can see it in the "Scripts and Add-Ins" dialog and can run it from there.  I would suggest first looking at this sample.  If this sample doesn't demonstrate what you need please provide a more complete description of what you're trying to accomplish and I'll see if I can help.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 3 of 4

Anonymous
Not applicable

hey Brian, 

 

Thank you, that did have in it what i was wanting for the drop down list.  Now, What i am trying to do is drive values in some valueinputs when i select different items in that drop down.  I created an oninputchange function, and this is what i have in there.

var onInputChanged = function(args) {
try {
var DoveLengthInput;
var DoveWidthInput;
var BoxLengthInput;
var BoxWidthInput;
var BoxHeightInput;
var CylDiaInput;
var CylLengthInput;

var command = adsk.core.Command(args.firingEvent.sender);
var inputs = command.commandInputs;
var materialListInput;
//Values for d1151s fixture
var initialVal10 = adsk.core.ValueInput.createByReal(1.475);
var initialVal11 = adsk.core.ValueInput.createByReal(0.7);
//Values for d1151p fixture
var initialVal12 = adsk.core.ValueInput.createByReal(1.475);
var initialVal13 = adsk.core.ValueInput.createByReal(0.994);
//Values for d221m fixture
var initialVal14 = adsk.core.ValueInput.createByReal(4.5);
var initialVal15 = adsk.core.ValueInput.createByReal(2);
//Values for d362m fixture
var initialVal16 = adsk.core.ValueInput.createByReal(6);
var initialVal17 = adsk.core.ValueInput.createByReal(3);
//Values for D051251WM fixture
var initialVal18 = adsk.core.ValueInput.createByReal(1.23);
var initialVal19 = adsk.core.ValueInput.createByReal(0.4);
for (var x = 0; x < inputs.count; ++x) {
var input = inputs.item(x);
if (input.id === 'fixtureselectiondrop') {
materialListInput = input;
}
}

var changedInput = args.input;
if (changedInput.id === 'fixtureselectiondrop') {
var getFixture = materialListInput.selecteditem.name;
if(getFixture == 'D051251WM'){
DoveLengthInput = initialVal10;
DoveWidthInput = initialVal11;
}
else if (getFixture == 'D1151P'){
DoveLengthInput = initialVal12;
DoveWidthInput = initialVal13;
}
else if (getFixture == 'D221M'){
DoveLengthInput = initialVal14;
DoveWidthInput = initialVal15;
}
else if (getFixture == 'D362M'){
DoveLengthInput = initialVal16;
DoveWidthInput = initialVal17;
}
else if (getFixture == 'D051251WM'){
DoveLengthInput = initialVal18;
DoveWidthInput = initialVal19;
}
}
} catch(e) {
ui.messageBox('input change failed: ' + errorDescription(e));
}
};

It still isn't changing the values in the input.  Is this the correct way to go about it?

 

Thank you!

0 Likes
Message 4 of 4

ekinsb
Alumni
Alumni

I didn't try putting a sample together to test that everything is working as it should but I do see a problem with your code.  A ValueInput object is used when you first create a ValueInput object but after that you access the value of the input using either the expression or value properties.  Using a ValueInput lets you use either a string or a double to set the initial value of the input.  If a string is used it is evaluated using the current document units and any units within the string.  If a double is used then it is treated as database units.  For example, for lengths it will always be centimeters.  However the result in the dialog will be displayed in the current document units.

 

One the command input has been created you can get and set it's value using the expression property (which requires a string and is evaluated using document units) or the value property (which is a double and will be in database units).  Which one to use depends on which is the most convenient for you and typically depends on where the data comes from.  For example, if you're reading if from a file or from some user entered data then it a string is typically more convenient.  If it's a value you've calculate then a double is better.

 

Here's a small section of your code:

 

 if(getFixture == 'D051251WM') {
     DoveLengthInput = initialVal10;
     DoveWidthInput = initialVal11;
}

 

Try changing it to this and see if it solves the problem:

 

 if(getFixture == 'D051251WM') {
     DoveLengthInput.value = 1.475;
     DoveWidthInput.value = 0.7;
}

 

I also don't see in your code where you're setting DoveLengthInput and DoveWidthInput.  You can get them doing something like the following:

 

DoveLengthInput = inputs.itemById('WhateverIDYouUsedWhenCreatingIt');

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes