How to Write variable value into test.txt file
-
Hello guys my name is Gustavo and iam from Brazil, i would like to know how to how to Write variable value into (Ex:test.txt) file.
Iam using this code inside WebConsole " File::open('c:\foo.txt', 'wb') {|f| f.write $variablename } " it Works!!! create a file and writes variable value but when i try this same code inside Script area give me this msg error
String doesn't compile: Error in Script:
File::open('foo.txt', 'wb') {|f| f.write 'ruby!' }String doesn't compile: Error in Script:
File::open('c:\foo.txt', 'wb') {|f| f.write 'ruby!' }private method `open' called for MSketchyPhysics3::SP3xCommonContext::File:Class#<RuntimeError: Error in Script:
File::open('c:\foo.txt', 'wb') {|f| f.write 'ruby!' }private method
open' called for MSketchyPhysics3::SP3xCommonContext::File:Class> C:/PROGRA~2/Google/GOOGLE~1/Plugins/SketchyPhysics3/ControllerCommands.rb:1314:in
initEvents'
C:/PROGRA~2/Google/GOOGLE~1/Plugins/SketchyPhysics3/ControllerCommands.rb:1342:ininitialize' C:/PROGRA~2/Google/GOOGLE~1/Plugins/SketchyPhysics3/ControllerCommands.rb:729:in
new'
C:/PROGRA~2/Google/GOOGLE~1/Plugins/SketchyPhysics3/ControllerCommands.rb:729:increateBody' C:/PROGRA~2/Google/GOOGLE~1/Plugins/SketchyPhysics3/sketchyphysicstool.rb:387:in
createBodyFromCollision'
C:/PROGRA~2/Google/GOOGLE~1/Plugins/SketchyPhysics3/sketchyphysicstool.rb:254:indumpCollision' C:/PROGRA~2/Google/GOOGLE~1/Plugins/SketchyPhysics3/sketchyphysicstool.rb:238:in
each'
C:/PROGRA~2/Google/GOOGLE~1/Plugins/SketchyPhysics3/sketchyphysicstool.rb:238:indumpCollision' C:/PROGRA~2/Google/GOOGLE~1/Plugins/SketchyPhysics3/sketchyphysicstool.rb:763:in
initialize'
C:/PROGRA~2/Google/GOOGLE~1/Plugins/SketchyPhysics3/sketchyphysicstool.rb:1623:innew' C:/PROGRA~2/Google/GOOGLE~1/Plugins/SketchyPhysics3/sketchyphysicstool.rb:1623:in
startphysics'
C:/PROGRA~2/Google/GOOGLE~1/Plugins/SketchyPhysics3/sketchyphysicstool.rb:1650:inphysicsTogglePlay' C:/PROGRA~2/Google/GOOGLE~1/Plugins/SketchyPhysics3/sketchyphysicstool.rb:1738 (eval):3:in
call'
(eval):3 -
Ruby uses the '' to quote the next character so in the script you either need to double the character '\' or use '/' instead.
'wb' ??? Sketchup uses Ruby 8.? version and this may not be supported. I don't find this context in my Ruby reference book.
-
@sdmitch said:
Ruby uses the '' to quote the next character so in the script you either need to double the character '\' or use '/' instead.
'wb' ??? Sketchup uses Ruby 8.? version and this may not be supported. I don't find this context in my Ruby reference book.
Hello Sdmitch! tnx!
I tried what you told, but same error any ideia?
File::open('c:/foo.txt', 'w+') {|f| f.write $variablename }Works fine on console but not into script box.
-
It could be something as simple as trying to write a file to the root directory. Windows Vista says that I don't have access even from the admistrator account.
Try this
File;;open(File.join(File.dirname(__FILE__),'foo.txt'), 'wb') {|f| f.write $variablename }
which will create the file in the script directory.
-
@sdmitch said:
It could be something as simple as trying to write a file to the root directory. Windows Vista says that I don't have access even from the admistrator account.
Try this
File;;open(File.join(File.dirname(__FILE__),'foo.txt'), 'wb') {|f| f.write $variablename } >
which will create the file in the script directory.
Tnx iam going to test this when i get home, but i think the problem is this (private method `open' called for....
the Class File.open is private needs to be public i think.... where can i change this? where is this class? -
Try
File.open(.....)
works for me... -
I have never had a problem with File.open just the path string for the file regarding the use of "". The code I encluded in my last post was tested and worked in Ruby Web Console, Ruby Console, and a plugin.
-
I got it!!!! file.open works fine in webconsole, but inside script box dont! becouse open method is private.. so this is the code
File.send(:open,'c:\foo.txt', 'wb') {|f| f.write $f }send "force" access to the method open. i think script box try to access File class and has no access.
Sorry for my english i hope you guys understand and tnx for the help.
Advertisement