Create text file from post

Create text file from post

ArjanDijk
Advisor Advisor
2,136 Views
12 Replies
Message 1 of 13

Create text file from post

ArjanDijk
Advisor
Advisor
While posting I need to make a complementary file containing some basic operation details. What is the easiest way to create a text file from the postprocessor?

Inventor HSM and Fusion 360 CAM trainer and postprocessor builder in the Netherlands and Belgium.


0 Likes
Accepted solutions (1)
2,137 Views
12 Replies
Replies (12)
Message 2 of 13

ArjanDijk
Advisor
Advisor
Found it:
var file = new TextFile("test.txt", true, "utf-8");
    file.writeln("Line1");


    file.write("Line1");
    file.close();

Inventor HSM and Fusion 360 CAM trainer and postprocessor builder in the Netherlands and Belgium.


0 Likes
Message 3 of 13

Laurens-3DTechDraw
Mentor
Mentor
Arjan wrote:

Found it:
var file = new TextFile("test.txt", true, "utf-8");
    file.writeln("Line1");


    file.write("Line1");
    file.close();


Not sure where it saves it though.

Laurens Wijnschenk
3DTechDraw

AutoDesk CAM user & Post editor.
René for Legend.


0 Likes
Message 4 of 13

ArjanDijk
Advisor
Advisor
In my case it save in the same folder as the NC file

Inventor HSM and Fusion 360 CAM trainer and postprocessor builder in the Netherlands and Belgium.


0 Likes
Message 5 of 13

Laurens-3DTechDraw
Mentor
Mentor
Arjan wrote:

In my case it save in the same folder as the NC file

Also if you change the folder in the explorer dialog?

Laurens Wijnschenk
3DTechDraw

AutoDesk CAM user & Post editor.
René for Legend.


0 Likes
Message 6 of 13

ArjanDijk
Advisor
Advisor
Edit: Yes thats possible:

  var outputPath = getOutputPath();
  var programFilename = FileSystem.getFilename(outputPath);
  var outputP = FileSystem.getFolderPath(outputPath);
op=outputP+ "\\" + programFilename.substr(0,programFilename.length-4) +".ini";

var file = new TextFile(op, true, "utf-8");
    file.writeln("Line1");
    file.write("Line2");
    file.close();


Only problem now is that is leaves a .CNC file and a .log file. (intermediate files)

How can I make sure they don't exist after postprocessing?

Inventor HSM and Fusion 360 CAM trainer and postprocessor builder in the Netherlands and Belgium.


0 Likes
Message 7 of 13

AchimN
Community Manager
Community Manager
go to the options/preferences to the postprocessor tab, there you can set this.


Achim.N
Principal Technology Consultant
0 Likes
Message 8 of 13

Anonymous
Not applicable

any idea how to append to existing file?

 

0 Likes
Message 9 of 13

ballsopECAM
Enthusiast
Enthusiast

Yes ....

 

I am able to write out to an external text file with this setup but how can I append to this file as the information changes before i close the file out ..... This method looks like it is giving you the very last instance of the data as output into the file ....

 

I have a rotary indexer that i want to create a second file called "O4105.txt" and take the (abc.x) value that  get when i set up my program with a different "Tool Orientation"  The output is good from this portion of the post and give me the correct "A" Axis rotation output per my CAM programs ....

 

Below is the area pulled from my .cps file where I create the TextFile and write out the ".abc.x" value into it ..... It creates the file OK but i need a way to keep the file open and append the values as they change when i post out and then close the file at the end of the post....

 

I think i'm looking for a way to "Append" to the file and not just repeatedly opening up the file and "overwrite" the first line with last variable captured when posting...

 

writeBlock(
// gMotionModal.format(0),
conditional(machineConfiguration.isMachineCoordinate(0), "M92 ( INDEXER WILL ROTATE TO A" + abcFormat.format(abc.x)) + ")",

// conditional(machineConfiguration.isMachineCoordinate(0), aOutput.format(abc.x)),
conditional(machineConfiguration.isMachineCoordinate(1), bOutput.format(abc.y)),
conditional(machineConfiguration.isMachineCoordinate(2),
cOutput.format(getDirectionalABC(previousABC.z, abc.z, cOutput)))
);

var outputPath = getOutputPath();
var programFilename = FileSystem.getFilename(outputPath);
var outputP = FileSystem.getFolderPath(outputPath);
op=outputP+ "\\"+ programFilename + ".txt";

 

var file = new TextFile(op, true, "utf-8");
file.writeln("G0 A" + (abcFormat.format(abc.x)));
file.close();
}

 

Thanks in advance.

 

Brian.

 

 

0 Likes
Message 10 of 13

Laurens-3DTechDraw
Mentor
Mentor

Have you tried removing this line:

file.close();

And putting that in the onClose() function?

 

Laurens Wijnschenk
3DTechDraw

AutoDesk CAM user & Post editor.
René for Legend.


0 Likes
Message 11 of 13

ballsopECAM
Enthusiast
Enthusiast

Thanks for the reply Laurens ....

 

ballsopECAM_0-1589835828025.png

 

 

The post is outputting correctly for what i want to see in the second file .... However I am only getting the "last instance" value from the posted file which in this case is the rotary axis back to "A0." or the initial start point of the program ..... I am looking for a way to keep "appending" to the file with each instance I get from my posted file .... in this case I am getting "A0. , A-90., A-180., A-270., and ends back at A0."   See attached posted output file that i will send to the mill..... The second posted text "Sub File" if you will i will load to my separate indexer controller PC .... They talk to each other via m-codes and custom I/O relay circuits to handshake between each of the controllers.... That part works fine .... I am at the point where i will have to "manually" create the small text fie for the indexer  PC to use.... Trying to get this post to "spit out" the smaller A-Axis rotational values into this second file .... Almost there .... Just need to "Append  vs. Overwrite" the file.... Perhaps JavaScript commands inside the .cps file would work ?  .... I have read about this "fs.append" functions in Java Script but I am not that advanced in coding to implement this functionality..... I know this would probably be a solution to my issue with appending....

 

I did "Comment Out" the "file.close()" and move it to the "OnClose" section but the post wouldn't work and gave me this error.....

 

###############################################################################
Error: Error: Failed to construct 'TextFile' object.
Error at line: 871
Error in operation: '.500 EMILL TO FACE SIDE 2 A-90.0'

Stack dump:
setWorkPlane([object Vector])@C:\Users\Brian\AppData\Roaming\Autodesk\Fusion 360 CAM\Posts\Doosan VMC Fanuc.cps:870
defineWorkPlane([object Section],true)@C:\Users\Brian\AppData\Roaming\Autodesk\Fusion 360 CAM\Posts\Doosan VMC Fanuc.cps:782
onSection()@C:\Users\Brian\AppData\Roaming\Autodesk\Fusion 360 CAM\Posts\Doosan VMC Fanuc.cps:1413
Failed while processing onSection() for record 658.
###############################################################################

Error: Failed to invoke function 'onSection'.
Error: Failed to invoke 'onSection' in the post configuration.

###############################################################################
Error: ReferenceError: file is not defined
Error at line: 2663

Stack dump:
onClose()@C:\Users\Brian\AppData\Roaming\Autodesk\Fusion 360 CAM\Posts\Doosan VMC Fanuc.cps:2662
Failed while processing onSection() for record 658.
###############################################################################

Error: Failed to invoke function 'onClose'.
Error: Failed to invoke 'onClose' in the post configuration.
Error: Failed to execute configuration.
Stop time: Monday, May 18, 2020 8:59:23 PM
Post processing failed.

 

Laurens.... i have attached my .cps post for you to review...

 

Thanks in advance.

 

Brian

0 Likes
Message 12 of 13

Laurens-3DTechDraw
Mentor
Mentor
Accepted solution

I see now.

You constantly keep creating a new text file in the setWorkPlane.

See the attached post.

We just push everything into an array, and then write it out in the onClose.

 

 

 

Laurens Wijnschenk
3DTechDraw

AutoDesk CAM user & Post editor.
René for Legend.


0 Likes
Message 13 of 13

ballsopECAM
Enthusiast
Enthusiast

Laurens ....

 

That's it .... Works like a charm .... Adding to the array function and pushing it out at the end is the way to do it ..... Thanks for all the help and now i will run the files to produce my parts..... You did a great job for me.... Best regards,