Skip navigation
5768 Views 19 Replies Latest reply: Jun 5, 2011 9:46 PM by AshishSharma RSS
AshishSharma Bronze 50 posts since
Jan 10, 2011
Currently Being Moderated

Feb 22, 2011 6:29 AM

using SetValue method on Scriptable Objects like TextBox , table..

Hello All,

As far as I could get, to make our setValue work for a particular variable, our worksheet needs to have placeholders instead of values of those variables (to avoid redefinition). This is possible for variables of types like String, Real etc.. But I want to know how to use setValue method for Scriptable Objects like TextBox , table etc..?

The programmer's reference says "The inputs and outputs for any Mathcad scripted  component form a DataValue collection. Each item in the collection is of  type DataValue" .

Can anybody please try to explain?

 

Regards,

Ashish Sharma

  • A.Non Diamond 10,321 posts since
    May 11, 2010

    But I want to know how to use setValue method for Scriptable Objects like TextBox , table etc..?

    The only thing you can set with SetValue is the value of variables. A scriptable object can have variables as inputs, so you can set those. You can't set the value of the output variable(s) of a scriptable object unless you get rid of the object, because the assignment from the object will override the SetValue assignment (just like any other variable). The same is true for tables.

     

    The programmer's reference says "The inputs and outputs for any Mathcad scripted  component form a DataValue collection. Each item in the collection is of  type DataValue" .

    Can anybody please try to explain?

    It's described in the help. The DataValue collection is used inside a scripted component to get the inputs (e.g. MyVariable = Inputs(0).Value) and set the outputs (e.g. Outputs(0).Value = MyVariable). I posted a worksheet with many examples of scripted components here:

    http://communities.ptc.com/docs/DOC-1071

      • A.Non Diamond 10,321 posts since
        May 11, 2010
        if my workheet has

         

        a text box (variable name => number )    and

        a matrix of 10*1(variable name=>myTable)

         

        a user puts value of the number in the textbox and gets its table(1*number, 2*number, ...., 10*number) in the matrix named myTable.

         

        I want to set the value of number externally, recalculate the sheet and read the value of myTable, all through a java program.

         

        I could understand the steps to take for normal variables but unable so solve this for textbox,table stuff.

        The output of the textbox goes to a variable, which behaves the same as any other variable. So you need to disable the textbox. The textbox is binary, but the variable name is not. Find the textbox using the variable name, locate disable-calc="false" for that region, and change it to disable-calc="true". Then SetValue should work. This approach should in fact work for any region that assigns values to variables.

         

        Does disabling worksheet assignments affects all my formulae?

        num1:=1

        num2:=5

        sum:=num1+num2

        which of the above will affect? just first two or all three?

        I'm not sure what you mean. If you disable the assignment of num1 then anything that depends on it, such as sum, cannot be calculated. Unless you assign a value to num1 using SetValue of course.

          • A.Non Diamond 10,321 posts since
            May 11, 2010
            MMmmm.... one more quick question, before getValue can we know the datatype of a variable using Mathcad API? Is there any function like getDataType, which will return either Strings like "real","boolean","matrix","string" etc.. or their corresponding classes? Thinking to give support for variables which have functions on RHS of their definition eg.

            colNum:=cols(matrix1)

            cols() returns number of columns in the matrix,

            can we know if the type of colNum , if its a number or array or string? In this case the function getDataType(colNum) should return "real" or something like??

            The NumericValue, StringValue, and MatrixValue classes all have a type property that will tell you if it's a number, a string, or a matrix.

              • A.Non Diamond 10,321 posts since
                May 11, 2010

                Just to make sure I understand what you are asking, you want, say, a textbox, which has it's output assigned to a variable. You want to be able to programmatically change the text in the textbox and then save it so the new text is persistent. Right? If so, making the text persistent is not a problem. It's an intrinsic proerty of the textbox. But you can't modify the text programmatically from outside the textbox. You would have to change a variable outside the textbox and then change the textbox script to use that variable (either as an input or using getValue).

                  • A.Non Diamond 10,321 posts since
                    May 11, 2010

                    1. I can get and set the values of scriptable components like TextBox using the same getValue and setValue methods, but getValue method is failing when the table is created by importing some data from any external file like .text file or excel file. Yes I saw the imported table has fixed size, we cant add any value once its created.So I believe for an external program it should be read only, but still I am unable to read such tables, getting strange error, (non-human readable,some square boxes in the msg. i hope u remember I am doing this from Java using jacob.dll)

                    Are you talking about an input table, and if you type values into the table in Mathcad it works, but if you paste them in from Excel it doesn't? If so please post a worksheet with two tables in it: one you can read, and one you can't.

                     

                    2. As you know I am changing the values of some directly initialized variables externally and collecting the updated values of other dependent varibale from Matchad. My program doing this ideally in all cases if I do the steps for say 40-50times. But if I make 100iterations means, same instance of Mathcad is needed to open 100 different sheets (1 at a time) and recalculate and give the results, Mathcad fails to open the sheet between a run 85-90. The sheet is perfect. My observation taking me to think if there is any limitation with Mathcad application to calculate at max. of 85 or like sheets in single session(1 at a time)?? Am I needed to close and re-open Mathcad around 50th run or like??

                    There's no real reason it should do that. It sounds like a memory leak of some sort. I think the best solution is the one you propose: close and restart Mathcad at set intervals.

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • Correct Answers - 3 points
  • Helpful Answers - 1 points