19 Replies Latest reply: Jun 5, 2011 9:46 PM by AshishSharma RSS

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

    AshishSharma Bronze

      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

        • Re: using SetValue method on Scriptable Objects like TextBox , table..
          A.Non PTC Community Champion

          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

            • Re: using SetValue method on Scriptable Objects like TextBox , table..
              AshishSharma Bronze

              Hello,

              sorry Richard but this time I could not get what you wanted to explain by

              You can't set the value of the output variable(s) of a scriptable object unless you get rid of the object,....

              well let me explain you what exactly I want,

              lets consider a simple example,

              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.

               

               

              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?

               

              Regards,

              Ashish Sharma

                • Re: using SetValue method on Scriptable Objects like TextBox , table..
                  A.Non PTC Community Champion
                  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.

                    • Re: using SetValue method on Scriptable Objects like TextBox , table..
                      AshishSharma Bronze

                      Great!

                      while studying the structure of .xmcd file, I had noticed this "disable-calc" tag and was having strong feeling that this is helpful for me,but somehow I didnt noted it on paper and forgot about it as I lost in thinking other problems. Thank you so much for reminding it.. I think everything is workable now and I can surely start taking steps with this approach..

                      Thanks again!

                       

                      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??

                       

                      Regards,

                      Ashish Sharma

                        • Re: using SetValue method on Scriptable Objects like TextBox , table..
                          A.Non PTC Community Champion
                          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.

                            • Re: using SetValue method on Scriptable Objects like TextBox , table..
                              AshishSharma Bronze

                              Done sir!

                               

                              bStr = objMC.Type

                               

                               

                               

                              I think you are online.. 

                               

                              Thanks & Regards,

                              Ashish Sharma

                              • Re: using SetValue method on Scriptable Objects like TextBox , table..
                                AshishSharma Bronze

                                Richard,

                                can you tell me if it is possible to save the worksheet with the values of variables set programatically?

                                I know setValue does only binding, but still I am asking if there is anything??

                                I can achieve persistence of new values if I direclty modified the xml but this is possible only for normal variables, I want to persist the same for scripatable objects..

                                 

                                Regards,

                                Ashish Sharma

                                  • Re: using SetValue method on Scriptable Objects like TextBox , table..
                                    A.Non PTC Community Champion

                                    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).

                                      • Re: using SetValue method on Scriptable Objects like TextBox , table..
                                        AshishSharma Bronze

                                        Yes, I want the same. To change the text value from outside as we use SetValue and to save the worksheet with new value.

                                        No, i dont have access to change the script of the textbox. I had saw the TextBox.Text property which is used inside the script to set and get its Text with the values of i/p and o/p vars,and this Text does persist in the xmcd.

                                        hmmm.. it means I can't save a worksheet with new values which are set programmatically (outside Mathcad). - a generic statement

                                        Okay thanks for the confirmation..

                                         

                                         

                                        Regards,

                                        Ashish Sharma

                                        • Re: using SetValue method on Scriptable Objects like TextBox , table..
                                          AshishSharma Bronze

                                          Hello Richard,

                                          I am back with a query I hope you are doing super as always and enjoying life..

                                          Just FYI I completed the tasks I was supposed to do, but in that I am now facing 2 problems, can you please suggest anything?

                                           

                                          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)

                                           

                                          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??

                                           

                                          Thanks & regards,

                                          Ashish Sharma

                                            • Re: using SetValue method on Scriptable Objects like TextBox , table..
                                              A.Non PTC Community Champion

                                              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.