cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

Is it possible to point Mathcad to a directory and have it read all files?

mepp
1-Newbie

Is it possible to point Mathcad to a directory and have it read all files?

I have a bunch of images I would like analyzed for a specific "shape_feature".  I would prefer not to have to point to each one individually.  I would like to write a little program (in Mathcad) that points to a directory, does the image processing and gets the "shape_feature" I want and then goes to the next image in the directory.  I think I know how to do this except I don't know how to have Mathcad point to a directory and look at all the files in the directory.  Any help would be appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions

Hi Marcus.

With Mathcad 15 you can write a vbscript component. But I guess that is more easy to use a DOS command window with "dir *.jpg > names.txt", read "names.txt" into mathcad and use the string functions inside mathcad to recover the names.

Best regards.

Alvaro.

View solution in original post

7 REPLIES 7

Hi Marcus.

With Mathcad 15 you can write a vbscript component. But I guess that is more easy to use a DOS command window with "dir *.jpg > names.txt", read "names.txt" into mathcad and use the string functions inside mathcad to recover the names.

Best regards.

Alvaro.

Thanks Alvaro for the insight,

I am using Mathcad Prime 3.1 and ideally I was hoping to keep everything in Mathcad but your suggestions may be workable for me.  Thanks for the suggestion.

Does anyone else have a potentially more direct suggestion?  Something that stays in Mathcad?

LucMeekes
23-Emerald III
(To:mepp)

You cannot write VBscript components in Prime, that feature is only available in the real Mathcad (version 15 and earlier)..

Also in the real mathcad is an undocumented function Files(), that allows two parameters, the first is a directory name (string), the second is an optional file type qualifier, directly linked to the 'attributes' of a file, such as R (read-only), H (hidden), D(directory) etc.

I don't know if that works in Prime.

At first sight: no

Also appears like there's a realer Mathcad: version11 knows the Files() function, Mathcad version 15 lost it.

Success!
Luc

LucMeekes
23-Emerald III
(To:LucMeekes)

Then there is the other opion of writing your own function (in C) in a DLL. However so far returning an array of strings from a user defined DLL function is not supported, but you could fill a matrix with ascii values (one file name per column, pad with zero's) and use the vec2str() function to convert each column of the matrix to a file name.

Now hope they've already implemented vec2str() in Prime...Yes, they did!

Luc

mepp
1-Newbie
(To:mepp)

Hey Guys,

So I appreciate both your help and I think I am very close to getting what I need.  I ended up just using the DOS command window as I am not very savvy with C.

Ideally, what I want is to be able to point my Mathcad sheet to a directory full of images, it gives me the area of those images and compiles the different areas into a matrix.  I am very close to having this working but I have a programing error.  My program "Area" (in the worksheet) works as long as it only iterates once.  For example, if you change "while P does not equal NaN" to "while n<2" the program works.  I want the program to go through the list of files, getting the areas until "P equals NaN".  Can you see what is wrong with my program?  It is probably a silly error.  Thanks.

MJG
18-Opal
18-Opal
(To:mepp)

To compare a variable to NaN, you have to use the function IsNaN() -- you cannot compare directly.  In your case, you'll obviously need to use the logical "not" comparison as well.

I did not check your program for any other errors.

mepp
1-Newbie
(To:mepp)

Thanks everyone.  I was able to get the Mathcad sheet working properly.  I appreciate the help.

Top Tags