News:

All posts discussing pricing or where to buy TurboCAD will be deleted.

Main Menu
TurboCAD 2026 Platinum box
Now available

TurboCAD 2026.2

The latest update for TurboCAD 2026. It installs over any 2026 build and keeps your activation, drawings and settings. Get it from the Start Page or Help > Check for Update.

Ruby Console: Will not Execute

Started by Alvin Gregorio, December 21, 2021, 09:15:52 AM

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

Alvin Gregorio

Hello All,

After messing around with a Ruby script, and getting some syntax or text wrong and being delivered an error message in the top pane (what's that pane called?), Execute is no longer working.  Not even for the installation-provided .rb files, when Loaded into the lower pane; they were working upon Execute previously.
When clicking Execute, nothing happens other than a number appearing in the top pane (such as 72); further attempts at Loading and Execute return a next-sequential number-- only.

Attempts at remedying but unsuccessful were:

  • Delete Built-in folder and re-Start TurboCAD
  • Run Repair from installation .exe file.  Run As Administrator.  Anti-Virus turned off.
  • Run Modify from installation .exe file.  Run As Administrator.  Anti-Virus turned off.
  • Log on as a different Windows User; start TurboCAD; run Ruby Console; try Load/Execute-- same problem result.
>Computer re-started after #2 and #3 above.

Besides UnInstall, then Install again, does anyone have any next try remedy suggestions?
Alvin Gregorio
TurboCAD: v2024_Plat (31.0.77.1); v2022_Plat; v2020_Plat; v2019_DL; v20.2_PP
Lenovo Thinkpad P20Y laptop; Windows 11 Pro; i7-11800H 2.30GHz, 8-core; 32GB RAM; NVIDIA T1200
3D_Printer: Ender-3 S1 (NOT Pro)

Andy H

#1
Quote from: Alvin Gregorio on December 21, 2021, 09:15:52 AM
Besides UnInstall, then Install again, does anyone have any next try remedy suggestions?

Alvin.  Don't uninstall.

The top panel is an output panel,  it is to evaluate the code, not specifically run a load of code to insert graphic.  For example, type this into bottom pane.
a = 5
b = 10
puts a * b
Then click execute,  the output is 50.  If you then change the code to
puts a * b / 0
The output is a warning about divide by zero.

However.  if one has loaded a script into the input (bottom) panel. and click execute.  Then the result in the output panel is often meaningless,  because the output panel cannot draw a spline, polyline etc.   If you had it working previously,  I'm sorry but I've no idea why it worked, as it has never (since ruby was first introduce) worked that way for me.   

The bottom panel can be used with execute, but not necessarily the way you may think.   Example. load TC20 ApiRectangle.rb,  (this puts it into memory).  Untick the multiline checkbox.  This will clear the input panel. Type in tc_rectangle_test  Then click execute.  A dialog box should pup up.  What execute did, was told ruby to run a specific function (def) contained within TC20 ApiRectangle.rb.  To run ones own code via execute, one would need to load it into the bottom input panel.  then specifically tell Ruby to run the code, before clicking execute.

Hope that makes sense,  Like I say, if you could load a code, and click execute before.  I don't know how you managed it.  :)

   

Alvin Gregorio

Thanks Andy.  Using the Ruby Console is new to me.

I was able to use your method successfully.  To output my own script, I Load it, select and Copy the def line (minus the "def"), clear Multiline, Paste that def text, then Execute.  Successful.

But, MAN..., I am so sure that the past couple of days I was just Load-ing the .rb files, while the text was in the lower, input, pane, clicking Execute, and it was executing.  I'm still sure that's how it was working up until that bad syntax or script this morning.

Anyway... if how you say it works is how you say it is supposed to work, I'll just go with that moving forward.

Thanks Andy!  I should have posted initially and waited patiently, rather than all the Built-in deletes and Repair and Modify.  Live-and-Learn (I hope).
Alvin Gregorio
TurboCAD: v2024_Plat (31.0.77.1); v2022_Plat; v2020_Plat; v2019_DL; v20.2_PP
Lenovo Thinkpad P20Y laptop; Windows 11 Pro; i7-11800H 2.30GHz, 8-core; 32GB RAM; NVIDIA T1200
3D_Printer: Ender-3 S1 (NOT Pro)

Andy H

#3
Normally with ruby.   Once one has got the code working, and saved as a .rb file, in documents - whatever TC version - ruby scripts.  When TC is first started it reads the list of ruby documents,  Once one has opened the ruby console, the drop down box (bottom right of the console) is used, which lists the available files. And on clicking ones file, it will normally auto run.   This is the normal way to run a file in the console. There is normally, no need to use load, unless one is altering the code.  (Or if, for some reason the file isn't listed.)

Alvin Gregorio

Quote from: Andy H on December 21, 2021, 05:15:12 PM
Normally with ruby.   Once one has got the code working, and saved as a .rb file, in documents - whatever TC version - ruby scripts.  When TC is first started it reads the list of ruby documents,  Once one has opened the ruby console, the drop down box (bottom right of the console) is used, which lists the available files. And on clicking ones file, it will normally auto run.   This is the normal way to run a file in the console. There is normally, no need to use load, unless one is altering the code.  (Or if, for some reason the file isn't listed.)

Is there something built into every Ruby code script that directs it to the default directory, C:\Users\[user name]\Documents\TurboCAD 2020 x64\RubyScripts?
Or is it built into the software, and we cannot locate our scripts somewhere else?
Alvin Gregorio
TurboCAD: v2024_Plat (31.0.77.1); v2022_Plat; v2020_Plat; v2019_DL; v20.2_PP
Lenovo Thinkpad P20Y laptop; Windows 11 Pro; i7-11800H 2.30GHz, 8-core; 32GB RAM; NVIDIA T1200
3D_Printer: Ender-3 S1 (NOT Pro)

Andy H

The ones in the drop down box, are automatically read when one starts TC.  This is why, if one saves a file, it won't show up in the drop down box, until TC is closed and re-opened.   As far as I know, the address to documents etc ruby scripts is built in, and cannot be changed.  If files are stored elsewhere, one would need to use the 'load' button, which opens the file open dialog.

nikkipollard

#6
From what I can tell -
The Syntax that loads it to the Ruby menu is that last line


UI.menu("Plugins").add_item("Import XYZ Spline By Fit Points"){import_XYZ_spline_by_fit_points}

if your script has this sort of thing - which you don't need

def import_XYZ_spline_by_fit_points
...........
end
Then that is a method and you need to call it

import_XYZ_spline_by_fit_points

but you can just type commands as Andy did - they don't need to be in a method. -
The problems you are having with the Ruby console is the reason I prefer the macro recorder.

Just a note that Torfinn pointed out
You cant Run the same script twice in a row (from the menu" with Ruby so you have to run it once then run another script and then run that one again.
I just added a blank script to the ruby list it does nothing and I can run the same script twice.

#Blank Ruby routine to enable running previous Ruby

def donothing
puts "cleared"

end

#donothing

UI.menu("Plugins").add_item("ClearLast"){donothing}




Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h