Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X
Hi everyone
I've got an excel file : the first column is the names of the variables, the seconde is the values of these variables.
Example :
Parameter1 3
Parameter2 7
Parameter3 11
Parameter4 13
I need to import these datas in the following way :
1)- import the names, and declare them as variables (example : thanks to the program, the name of the first variable declared in MathCad has to be Parameter1) ; (this step gives me some problems)
2)- import the value of the variable in the variable declared (this step is done)
I mean, how to automatically declare a variable, with a name importated ?
Sorry for my english and many thanks to anyone could help me !
CCilairo
There may be an easier way to do what you want, but if you really need to do this you might look at this thread
http://communities.ptc.com/message/160286#160286
But after you look at that, and you still want to do, there is actually a way. Richard had it all along, just forgot. The attached is a scrip written by Tom Gutman, modifed by Stuart Bruff (looks like he forgot too) and sent to me vie Richard (Thanks by the way).
Well remembered Wayne. I cannot see another way of achieving this.
Mike
Hi and many thanks for your help.
I read the thread, really helpful for the rigth use of variables ;
I also got a look at your script but I'm not sure I really understand the way I can use it : I'm not sure I can declare a variable with the function str2val ? I mean, with your .zip, if I call the variable "C=" (cf. funtag2), it can't say "C=23000".
In my case, I need to call the variable by its name.
I'm not sure that I'm clear, I try again ^^ :
with the exemple from my first post, the str2val will return the matrix below :
(Parameter1 = 3
Parameter2 = 7
Parameter3 = 11
Parameter4 = 13)
but "Parameter1" is not a variable : I couldn't call it in the rest of the worksheet, to do something like :
Parameter1 + Parameter2 =
To be clear, I have almost one hundred of variables, in an Excel file ; the first column are the names of the variables and the second are their values ; I have to import the names and the values in MathCAD, and then to do some calculations with them (integrals, etc). So, I can't declare "manually" all the variables, you see?
Unless I misunderstood the use of your str2val function ? ...
CCilairo
To be clear, I have almost one hundred of variables, in an Excel file [...] I have to import the names and the values in MathCAD, and then to do some calculations with them (integrals, etc).
Another way to do that is :
in my MathCAD file, I need to use the value of "Parameter1" ; Parameter1 isn't declared in this MathCAD worksheet, but a tiny routine could read the excel file and search for the "Parameter1" string in the ActiveSheet, and then return the value of it in MathCAD.
1) To do this, I create a Sheet in Excel, including :
Column A : values of variables ;
For each cell of Column A, I define a cell name corresponding to the name of the variable (So, here, the name of the cell A1 is Parameter1 and the value of the cell A1 is 3)
2) Then I try to call it in the MathCAD sheet :
TEST := READEXCEL(".\test_name.xls","Feuil1!Parameter1")
But two problems :
1) : MathCAD can't import an excel data with the cell name, only with its location :
READEXCEL(".\test_name.xls","Feuil1!A1") in this exemple
2) it would be really heavy, but I don't mind ^^
What do you think about this 'not a solution' ?
Can you upload an Excel sheet with the data and I'll see if I can use the worksheet posted by Wayne to get to to work for you.
Mike
I finally did it, in a rougher way...
Many thanks for your concern and the threads and examples, which brought a lot to me !
CCilairo
Any chance of the solution?
Mike
+1.
The str2var will work.
But it is only necessary when the variable name is not preset. For example, in my case, the user may want to make a new load combination and give it a unique name. This is done in a matrix of load combinations that is referenced into a worksheet that is based on that matrix, and for which the unique variable name must be used as a variable
If you know the names, or can assign the names, like Parameter1 thru 100, this is a much easier problem. I suspect that is more less what you did?
(Vladimir, could you be a little more concise, by the time I got to the period I forgot what you were talking about.?)
Yes, sorry I said that the str2var won't work, but finally it did :-s
In fact, the list of parameters is not as simple as I said, so I tried to use str2var for some of them, and for the others a simple function which I predefined with a "recherchev" (well I don't now the correspondance in english, maybe "researchv" ??) in a matrix which I use like a listing.
In this way, the user will have to specify the caracteristics of the parameters at the first beginning of the worksheet ; I thought it will be a constraint but looking back, it's just as well.
Thank you very much to all of you!