News:

Please remember to do a search before you ask a question!

Main Menu

TC IronRuby Inputbox

Started by sauerkraut2018, September 11, 2021, 09:16:39 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

sauerkraut2018

Hi there,

I am currently testing IronRuby in Turbocad.

I would like to create an inputbox. For example to draw a rectangle.
In thought it would look like this:
Enter width
Entering height
Enter position (standard 0,0,0) or (x, y, z)

Has anyone already done that?

Thank you in advance for your contributions.
#-----
Very low knowledge of English - I ask for indulgence - Thanks
Currently installed
TurboCAD Professional 32-bit V.17.2.77.1
TurboCAD 2016 ProPlatinum 64-bit V23.2-61.2 engl.
TurboCAD 2021 Platinum 64-bit V28.0 B.82.3 de.
#-----

nikkipollard

#1
Take a look at the dynamic form creation Example in the Ruby examples supplied by Turbocad.
It shows you how to code a windows form.

This is how far I got before I gave up.

require "System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
require "System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"

##System::Windows::Forms::Form.new.Show
def myform
# my script
Font = System::Drawing::Font.new("Microsoft Sans Serif", 10.0)
lblWidth = System::Windows::Forms::Label.new
lblWidth.text = "Width"
lblWidth.AutoSize = false
lblWidth.Font = Font
lblWidth.Top = 12
lblWidth.Left=50

lblHeight = System::Windows::Forms::Label.new
lblHeight.text = "Height"
lblHeight.AutoSize = false
lblHeight.Font = Font
lblHeight.Top = 38
lblHeight.Left=50

Font = System::Drawing::Font.new("Microsoft Sans Serif", 12.0)
txbWidth =  System::Windows::Forms::TextBox.new
txbWidth.Font = Font
txbWidth.text = "100"
txbWidth.Top = 9
txbWidth.Left=150

txbHeight =  System::Windows::Forms::TextBox.new
txbHeight.Font = Font
txbHeight.text = "50"
txbHeight.Top = 35
txbHeight.Left = 150

butDraw = System::Windows::Forms::Button.new
Font = System::Drawing::Font.new("Microsoft Sans Serif", 16.0,FontStyle.Bold)
butDraw.Font = Font
butDraw.Text = 'Draw'
butDraw.Top = 70
butDraw.Left = 150
butDraw.Width =100
butDraw.Height = 50

butDraw.click do |sender,args|

#validate input data
ValidData = false

begin
  W = System::Convert.ToDouble(txbWidth.Text)
  H = System::Convert.ToDouble(txbHeight.Text)
  ValidData = true
rescue
  puts "Invalid input data"
end

TcDraw =TCApplication.ActiveDrawing
graph =TcDraw.Graphics
tcGr = graph.AddLineRectangle(0,0,0,W,H,0)
grProps = tcGr.Properties

tcGr=nil
TcDraw=nil
butDraw.parent.Close
end

Form = System::Windows::Forms::Form.new
Form.Width = 350
Form.Height = 200
Form.Text = 'First Ruby form'
Form.controls.Add(lblWidth)
Form.controls.Add(lblHeight)
Form.controls.Add(txbWidth)
Form.controls.Add(txbHeight)
Form.controls.Add(butDraw)
Form.StartPosition = FormStartPosition.CenterScreen
Form.ShowDialog ()


end


myform



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

Andy H

If you want something a bit fancy.  you could make a windows xaml form.  (See TC rectangle and rectangle xaml files in the ruby scripts folder (documents - tc version - ruby scripts)),  They can be opened in Notepad.

The attached was designed in Visual studio 2019, and adapted to open from the ruby console in TC.  though I have not got round to trying to do any ruby programming yet.

nikkipollard

Before you get too fancy with forms in Ruby, check that you can make Ruby do what you want it to do with Turbocad Objects.

I tried a simple hello world with text - as soon as I try to change properties of some graphics via Ruby - Ruby doesn't like it.
Apparently text graphics don't have properties.
I thought it would be easy to adapt what I have learnt about the SDK in visual studio to Ruby. - It is not that straight forward.

It is much easier to make forms in Visual studio. - both window forms and WPF.
Whilst you are there you can take advantage of the intellisense to explore the Turbocad SDK.
Hopefully you will be better at figuring out the differences between the 2 languages.

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

Andy H

Quote from: nikkipollard on September 12, 2021, 12:56:01 AM
Before you get too fancy with forms in Ruby, check that you can make Ruby do what you want it to do with Turbocad Objects.

I tried a simple hello world with text - as soon as I try to change properties of some graphics via Ruby - Ruby doesn't like it.
Apparently text graphics don't have properties.
I thought it would be easy to adapt what I have learnt about the SDK in visual studio to Ruby. - It is not that straight forward.


I've no doubt your correct Nikki.   TC's Ruby has zero documentation, on what will / won't work.   I haven't looked at Ruby programming yet.  To be honest, I just did the form for a bit of fun, to see if i could get it into TC. 

nikkipollard

To be honest I think I have misunderstood the whole concept.
I was under the impression that Ruby was just another way to work with Turbocad SDK, using the same dll file.

So In my head , even though the syntax is different- the methods should be similar. They are not.
I am not clever enough to figure out why I can work with properties of a dimension object but using the same syntax for a Text object throws an error.




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

sauerkraut2018

Hi there,

thank you very much for your contributions.

@Andy H:
I don't have Visual Studio 2019 and I won't buy it "just" to run tests.

@Nikkipollard
Your listing shows me a window, looks great.
To create this window you had to write 86 lines.
In a PPM this works with about 5 lines.
I think I'll give up Ruby too and stick with the PPMs.

I would be interested to know what Ruby could be useful for within Turbocad?

Now if someone wants to explore Ruby can try or enter the following.
In Ruby there are among others: classes, modules, constants
Use the words "list" or "sort" at the end
_ = means classname, modulesname or constantsname
Input in the Ruby console:
_.methods.list
_.ancestors.list
_.constants.list
_.included_modules.list
_.instance_methods.list
_.private_instance_methods.list
_.public_instance_methods.list
_.private_methods.list
_.public_methods.list
_.singleton_methods.list

Here is an example class for c+p to test
File.methods.list
Here is an example module
TC_API.constants.list
Math.private_instance_methods.list
Math.constats.list

Maybe it will be helpful to someone. I would appreciate your feedback.

;)
#-----
Very low knowledge of English - I ask for indulgence - Thanks
Currently installed
TurboCAD Professional 32-bit V.17.2.77.1
TurboCAD 2016 ProPlatinum 64-bit V23.2-61.2 engl.
TurboCAD 2021 Platinum 64-bit V28.0 B.82.3 de.
#-----

Andy H

Quote from: sauerkraut2018 on September 13, 2021, 06:34:46 AM

@Andy H:
I don't have Visual Studio 2019 and I won't buy it "just" to run tests.


VS 2019 (express version now called community) is free for individuals.   

nikkipollard

@Sauerkraut.
The way I see it PPMs are useful for symbols. Powerful blocks that don't interact with the drawing. They are Like Dynamic blocks in Autocad.
The contents of a PPM are predictable - you are limited by the fact that you can't  loop through repetitive tasks - unless the action is identical.
Using Ruby or the SDK you have a bit more freedom
You can work with selected objects
You can loop through repetitive tasks
You can create complex objects - that you don't need to be parametric.
There is the ability to make parametric graphics with the SDK. Using  Regen Objects. But they load when you start Turbocad and I guess you would need that file. on every computer you shared the parametric object with.
An example would be the Slot tool.
I havent tried to script one as it seems like there is a recipe for them. I am not good at following Recipes.

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

sauerkraut2018

Hi there,

@Andy:
Thanks for the hint. I downloaded the manual for it. There are 2319 pages  :o that I should read through. It's really tough.

@nikkipollard:
Thank you again for your comments.
Yes, PPMs cannot be processed further (e.g. a drilling), they have to be exploded beforehand. This is not good.
Everything you write about Ruby / SDK is certainly correct. My thought is "input first, output then". Hence my original question about the input box.

Thanks, see you soon.  :)
#-----
Very low knowledge of English - I ask for indulgence - Thanks
Currently installed
TurboCAD Professional 32-bit V.17.2.77.1
TurboCAD 2016 ProPlatinum 64-bit V23.2-61.2 engl.
TurboCAD 2021 Platinum 64-bit V28.0 B.82.3 de.
#-----

nikkipollard

@ Sauerkraut.
You wont need to read the whole manual.
I am sure I just did a few tutorials - if they were too difficult to understand I skipped that tutorial and went to the next.
Even if you stick to Ruby - Turbocad uses IronRuby. Which uses the .Net Framework. (so does vb.net and c#)
It helps to know what is available and how to use them
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h