Jump to content

Welcome to eMastercam

Register now to participate in the forums, access the download area, buy Mastercam training materials, post processors and more. This message will be removed once you have signed in.

Use your display name or email address to sign in:

Creating text file in MP


Recommended Posts

I am using an ASCII text file to store buffer information generated or accessed during posting and as long as the file exists prior to program launch everything is hunky-dory. If the file does not exist then my approach fails miserably. Is there a way within the MP to check to see if a separate file exists and if not, create that file?

Link to comment
Share on other sites

Randy,

 

From what I've been able to figure out, the MP language doesn't have any functions to create an external .txt file. There are a couple functions that might let you though,

 

The commands:

 

launch - launch lets you run an executable program. I'm not sure if this includes batch files or not.

 

runvbs - would let you run a VB script from within the post. You might be able to use this with an If/Else case to continue if the text file exists, or run a VB or .EXE to create the file if it isn't found, or just warn the user and exit the posting process.

 

I sent you an email with everything I could dig up.

 

HTH,

Link to comment
Share on other sites

Thanks Colin, I got your email

 

Roger

I am putting fixture and drawing information into the first few lines of the program. Some of the information I can take directly from Mastercam but not all of it. What I can not get from Mastercam is what is going into the buffer file.

So then would a valid strategy be to check to see if my buffer file exists using the "fexist" command. If it does then proceed normally. If not then create the buffer (fbuf) with the second variable set to "1" (Keep flag)? Do you know if I can use a variable to define the file path for both the fexist and sbufname1$ commands? How do I get the quotes (") into the path variable?

Thank you for your time

Link to comment
Share on other sites

John,

 

My example of fexist() about uses a (string) variable name.

 

You can certainly "build" up the pathfilename.ext to be used for the filename of an sbufname#.

 

This sample is from the std. Generic Fadal Format_1 4X.pst ->

 

sbufname2$ = spathnc$ + snamenc$ + sextnc$

 

Here they are using pre-defined strings to build up the path/name, but of course you can use your own 'user-defined' strings.

 

 

"How do I get the quotes (") into the path variable?"

 

Why you you need the quote char in the filename?

 

Could you give an example of the full path/filename.ext you are trying to create?

Link to comment
Share on other sites

Roger

It's always the little things that mess you up. Silly me, I was using the V9.1 MP Post Processor Guide which says you have to have the "drivepathfilename in Quotes" (V2 Ch3 "How Buffer Files Work). I tried it without the quotes but did not put in that neat little equals (=) sign. Once I did that my built path worked without the quotes.

Thank you for your help

Link to comment
Share on other sites

You only need quotes for explicit strings containing spaces or other special characters ie string1 = "hello world". The " " are needed because of the space.

 

No " " are needed when using variables to build a path as in Rogers example.

 

The use of " " is a fundamental syntax issue that is described in the manual and even when we don't need them we usually use them for consistency and safety. If we had something like

code:

 string = hello 

although valid if a user not familiar with posts wanted to make it hello world and does the following

code:

 string1 = hello world

then the output would just be Hello.

 

But if we have

code:

string1 = "Hello"

then chances are the user will modify correctly and maybe even learn something. Kind of a better safe than sorry issue.

 

An updated post manual would have made no difference especially if he forgot an = sign.

Link to comment
Share on other sites
  • 1 month later...

Hi all

I'm back on the buffer files again

I am using a couple buffer files in my post and they work great as long as I hard code the path for the file location. As soon as I use a variable in the path it no longer works.

 

Here is the section of the post where I call the buffer files. I am trying to use "snamenci$" in the path so I can save the buffer files as a unique file name but I just can not make it work. The strange thing is when I print out the string variable "str_pgrm_name" in the pheader$ block it shows the right path.

 

str_pgrm_name = "C:tempPart Data" + snamenci$ + ".txt" #this line does not work

 

#str_pgrm_name = "C:tempPart Data" + "jrptest-51_1-1" + ".txt" #this line works

 

 

sbufname9$ = str_pgrm_name

fbuf 9 1 80 1 1

 

Any suggestions? banghead.gif

Link to comment
Share on other sites

Roger

ok, the more specific scoopage:

 

I am trying to save the file as:

"C:tempPart Datajrptest-51_1-1.txt" with the "jrptest-51_1-1" as the program unique part of the path. What I am getting is:

"C:tempPart Data.txt" (Drops the snamenci$ part of the path).

I know it is finding the nci file name because I can output the path in the pheader$ section of the post

 

Thanks for your help

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.

Join us!

eMastercam - your online source for all things Mastercam.

Together, we are the strongest Mastercam community on the web with over 56,000 members, and our online store offers a wide selection of training materials for all applications and skill levels.

Follow us

×
×
  • Create New...