News:

The purpose of these forums is to discuss TurboCAD.  Please keep the discussion of other products to compatibility issues or how the other software can be used with TurboCAD.

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.

How to create curved wing root section

Started by Steve Edwards, December 12, 2021, 07:54:26 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Alvin Gregorio

Quote from: Alvin Gregorio on December 22, 2021, 04:53:02 PM
Quote from: Alvin Gregorio on December 22, 2021, 06:03:04 AM
...

TO DO:  Add commas, commas+spaces, Tabs, Tabs+spaces, to the c = b.gsub(/; */, " ") Line.
...

Well, heck... that was easy.
I just added another c = b.gsub(/; */, " ")  line under this one, and edited it to c = b.gsub(/[Tab]/, " ").
Parsed well and executed well on a .txt file in which I changed all the semicolon separators to Tabs.

I'm trying to recall if the above actually attended to all-- commas, commas+spaces, Tabs, Tabs+spaces.  The script can be easily modified again, to include any of those that are omitted, if the latest revision does not.

I'd like to also edit the Ruby script such that the coordinates .csv, .txt, (or other) file does not have to have a third column for the Z=0.
I think it would be possible to edit the script such that all Z coordinates are auto-populated with 0.  Rename the script "... Import XY Spline(s) By Fit Point".
Would save yet another pre-step in getting from supplied coordinates file (such as is available at airfoiltools.com) into TurboCAD drawing space as a 2D Spline on the World Workplane via the Ruby Console.
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)

Steve Edwards

Third time lucky,Instructions for importing Aerofoil data, revised to say Spline By Fit Points instead of Spline By Control Points.
TurboCAD Platinum 2024
NVIDIA RTX 4000
12th Gen Intel(R) Core(TM) i9-12900K   3.20 GHz
Windows 11 Pro (64)
64 GB RAM
Bambu P1S with AMS

nikkipollard

#52
Quote from: wwwdotsteve on December 30, 2021, 01:52:37 AM
Third time lucky, Instructions for importing Aerofoil data, revised to say Spline By Fit Points instead of Spline By Control Points.
Thanks Steve.
Did you try using Alvin's  Ruby script?, It draws the spline for you
Basically follow your instructions but switch to the spline script.

The other thing I did was add a simple script to my ruby menu
The script does nothing but clears the previous script from turbocads brain
I run that after I run a script and I can use the script again without too much fuss.

#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

nikkipollard

#53
Quote from: Alvin Gregorio on December 29, 2021, 02:06:39 PM
Quote from: Alvin Gregorio on December 22, 2021, 04:53:02 PM
Quote from: Alvin Gregorio on December 22, 2021, 06:03:04 AM
...

TO DO:  Add commas, commas+spaces, Tabs, Tabs+spaces, to the c = b.gsub(/; */, " ") Line.
...

Well, heck... that was easy.
I just added another c = b.gsub(/; */, " ")  line under this one, and edited it to c = b.gsub(/[Tab]/, " ").
Parsed well and executed well on a .txt file in which I changed all the semicolon separators to Tabs.

I'm trying to recall if the above actually attended to all-- commas, commas+spaces, Tabs, Tabs+spaces.  The script can be easily modified again, to include any of those that are omitted, if the latest revision does not.

I'd like to also edit the Ruby script such that the coordinates .csv, .txt, (or other) file does not have to have a third column for the Z=0.
I think it would be possible to edit the script such that all Z coordinates are auto-populated with 0.  Rename the script "... Import XY Spline(s) By Fit Point".
Would save yet another pre-step in getting from supplied coordinates file (such as is available at airfoiltools.com) into TurboCAD drawing space as a 2D Spline on the World Workplane via the Ruby Console.
I don't know if my solution (in the macro recorder version) is the best solution - but maybe you could try something like that.
All I did was count the number of elements in the array after the first line of text was split. If it had 3(2) - there was a z if it had 2(1) there wasn't a z so I used 0.
Don't forget that Ruby arrays start counting at 0
the regular expression made sure there was at least 2 numbers.

Also Kevins original script was for more then one polyline
You haven't changed the last polyline to a curve and set the first curve to a spline by fit points. -
it confused me initially so the first I posted was wrong.
I corrected my error in #39

I don't know how to work with properties in Ruby -I get an error- so I cant help with the hatching problem.
I will change the macro script - and maybe you can figure out how Ruby handles our property system.
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

Steve Edwards

Hi Nikki
I plan to try following  Alvin's instructions today and copy the code into Ruby. I'm somewhat cautious about venturing into an aspect of TC (Ruby) that I know very little.
I have read all the posts and I can see you and Alvin have made a number of code changes to cope with the differing separators, using spline by fixed point, csv or txt and data as xy or xyz and I thank you for that. I'm not sure as I write this which is the most up to date code I should use. Does the code in Alvin's post, the one with the instructions for importing to Ruby , is that the one to use.
Thanks once again for your interest, I'm sure it will make importing aerofoil data a breeze.
TurboCAD Platinum 2024
NVIDIA RTX 4000
12th Gen Intel(R) Core(TM) i9-12900K   3.20 GHz
Windows 11 Pro (64)
64 GB RAM
Bambu P1S with AMS

nikkipollard

#55
I am not really sure where Alvin is with the Ruby script.
Kevins' original script got too complicated for me so I switched to vbscript in the macro recorder because I am more familiar with vb.

It seems Alvin has set it to always close the spline and I think he was trying to explain how to change the script, to read a tab delimited file.
The vbscript version I posted in #49 only draws 1 spline at a time.
It asks which delimiter your file has , and it will also accept an x and y coordinate only
It closes the spline if the end points are the same.
open the macro recorder and paste the script. Click on the blue arrow.
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

Alvin Gregorio

I have made some edits to the script.  In addition, I am still working on eliminating the need to enter a Z column in a spreadsheet, before importing XYZ coordinates.

I am also wanting to simplify it and delete some stuff that is extraneous to airfoil profile spline only use.

I ran into a problem yesterday.  I added the ability to replace commas with the required spaces for XYZ column separators; but the problem with using that is when a user's coordinates import file uses commas as decimal delimiters-- such as in Norway, I believe.
    However, since this is intended to be an airfoil coordinates import only Ruby script, those coordinates procured from airfoiltools.com, and that site's provided .csv files use periods (dots) as decimal delimiters, I think I'm going to accept the problem/limitation.  Someone can modify the script rather quickly if they wanted to cancel out the commas being detected and changed to spaces.

It will be middle of next week, if and at the soonest, that I will revisit modifying the script.  Perhaps early next week (I'm away for the weekend; no TurboCAD computer with me) I will post the latest, cleanest, simplest script that I have.
_____
On the "Closed" (Spline) topic:  I am electing to have the spline not insert from the Ruby console as closed.  Doing so changes the polynomial curve math ever so slightly and creates a closed curve that I don't know is intentional or wanted by the airfiool profile creator.  I decided that it is best to leave it as inserting not-Closed, and let the user decide if and what to do with that "pointed" trailing edge, after insertion.
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)

nikkipollard

I agree with not putting closed in
I managed to change the script so that there is an option to not have a z value.
- so that the same script can be used for 3d splines - which a lot of people have asked for
I have commented out the closed spline bit
I have included a tab or comma as a delimiter  - This will need to be removed if your locale has a comma decimal separator.

# Import_XYZ_points_for_Spline_By_ Fit_Points.rb
# Ruby script to import xyz text files as lines using the TC API.
# Version 20.0.1.6
#
# Written by Kevan Chapman on Jan. 25, 2013 for IMSI Design LLC.
# Caveats: The file is expected to be properly formatted, with the first three
# columns on each line consisting of x, y, and z values separated by spaces , tabs, commas or semicolons
# If your locale uses a comma instead of a period as the decimal separator,
# you will need to remove the comma see notes further down in script
#  Additional columns on a line will be ignored.
# Blank lines in the data file indicate the end of the points for one line graphic.
# "Lines" consisting of only one point are possible, and will be modified by adding
# a second, identical point.
# Comment lines may be added by beginning a line with '#' as the very first character.

# Example format :
#
=begin
#test2.xyz -- this line is a comment
# this data set forms a rectangle on the plane y=0
12.5; 0.0; 3.5
12.5 0.0 0.0
24.5  0.0  0.0
24.5; 0.0  3.5
12.5;0.0;3.5
=end


# Load the necessary libraries to show the "Done" message.
require "System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
include System::Windows::Forms

def import_XYZ_spline_by_fit_points

  # Select the XYZ file to open via standard Windows file open dialog.
  fd =  OpenFileDialog.new
  # Set Title/default extension/initial directory properties for fd
  fd.Title = "XYZ Import"
  fd.DefaultExt = "csv"
  fd.Filter = "CSV files (*.csv)|*.csv|XYZ files (*.xyz)|*.xyz|All files (*.*)|*.*"
  # Display the configured File Open dialog box and get the result.
  res = fd.show_dialog

  if res == DialogResult.OK then

   f = File.open(fd.file_name)

   # Read the file into an array of lines.
   a = f.readlines
   f.close

   # Get a pointer to the drawing's graphics collection.
   tcApp = TCApplication
   tcActDwg = tcApp.ActiveDrawing
   tcActVw = tcActDwg.ActiveView
   tcGrs = tcActDwg.Graphics

    # Add a new, empty spline, clear the Vertices, and set it up for UseWorldCS.
    # UseWorldCS is necessary to properly support non-zero Z values.
    tcGr = tcGrs.Add(11,"TCW30CURVE")
    grVerts = tcGr.Vertices
    grVerts.Clear(0)
    grVerts.UseWorldCS = true
   
    # Inspect each line.
   # If the line is a comment (starts with '#'), skip it.
   # If the line is a blank line, and we are creating vectors from
   # the point data, end the current line.
   # Otherwise, parse the line into x, y, and z values.
     
   a.each do |b|

    b.strip!
    bchars = b.scan(/./)

    if (bchars[0] == "#") then
      # Skip comment lines.
        #puts "skipped a comment"
     next

    elsif (b.length == 0) or (b == nil) then
        # For empty lines, close out current graphic and start a new, empty one.
        if grVerts.Count > 0 then
               tcGr.Draw
          # Single-vertex line graphics become "point" graphics in TurboCAD, but
          # they aren't visible and have no Point properties in the Selector info.
          # In such cases this script simply adds a second, identical vertex to
          # make the line graphic visible (though barely).
          if grVerts.Count == 1 then # Add a second identical point.
            vert = grVerts.Item(0)
            grVerts.Add(vert.x, vert.y, vert.z)
            vert = nil
          end
          tcGr = nil
          grVerts = nil
        end
 
    # grVerts.AddClose(true, true, true, true, true, true)
       # converts spline by control points to Fit points
     tcGr.SetCurveVertexAsFitPoints
     tcGr.Update
     tcGr.Draw
   
  #puts "adding new spline"
           tcGr = tcGrs.Add(11,"TCW30CURVE") # Add new, empty spline by control points. Again, clear vertices and set UseWorldCS.
        grVerts = tcGr.Vertices
        types = 0
        grVerts.Clear(types)
        grVerts.UseWorldCS = true
        next
       
      else
     # Convert semicolons,commas, and tabs -plus optional extra space to a single space
    # NB remove comma option if using a comma decimal separator
     # c =  b.gsub(/; ?|\t/, " ")          no comma option
   
      c = b.gsub(/; ?|, ?|\t/, " ")
   
      # Split the line into numeric variables.
     d = c.split
    nm = d.length
     # Important note:
     # Ruby script native variables are not always entirely .NET-compatible.
     # Thus careful conversion is required to avoid crashes.
     # Here I'm converting the text array elements from the split result
     # to .NET-compatible strings, then converting those to doubles
     # for use in the TC API

     x = System::Convert.ToDouble(System::Convert.ToString(d[0]))
 
     y = System::Convert.ToDouble(System::Convert.ToString(d[1]))
   
   if nm >= 3
     z = System::Convert.ToDouble(System::Convert.ToString(d[2]))
    else
    z = 0
   end

        grVerts.Add(x, y, z)                      # Append this vertex to the current polyline.
    end                    # This line processed.
   end                          # All lines processed.

    # Draw the last spline if it contains any vertices.
    if grVerts.Count > 0 then
    #closes the spline note all splines will be closed
    #grVerts.AddClose(true, true, true, true, true, true)
    # converts spline by control points to Fit points
     tcGr.SetCurveVertexAsFitPoints
     tcGr.Update
     tcGr.Draw
end

    # Zoom to the drawing's extents.
   tcActVw.ZoomToExtents()
   MessageBox.Show "Done"

    # Clear API class variables.
    grVerts = nil
    tcGr = nil
   tcGrs = nil
   tcActVw = nil
   tcActDwg = nil
   tcApp = nil
  end

end

#import_XYZ_spline_by_fit_points
UI.menu("Plugins").add_item("Import XYZ Spline By Fit Points"){import_XYZ_spline_by_fit_points}
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

Steve Edwards

Got It ! Works a treat, I followed the instructions and used the code posted by Nikki. Thanks everyone. Steve
TurboCAD Platinum 2024
NVIDIA RTX 4000
12th Gen Intel(R) Core(TM) i9-12900K   3.20 GHz
Windows 11 Pro (64)
64 GB RAM
Bambu P1S with AMS

Alvin Gregorio

Quote from: nikkipollard on December 31, 2021, 07:57:05 AM
I agree with not putting closed in
I managed to change the script so that there is an option to not have a z value.
- so that the same script can be used for 3d splines - which a lot of people have asked for
I have commented out the closed spline bit
I have included a tab or comma as a delimiter  - This will need to be removed if your locale has a comma decimal separator.

...


What Line(s) of the script creates "... an option to not have a z value", Nikki.

I spent considerable time with a variation of this script yesterday, so I'm pretty familiar with it; but I'm not able to identify that Line(s) in your script.
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)

Henry Hubich

#60
Quote from: Alvin Gregorio on December 31, 2021, 11:06:03 AM
Quote from: nikkipollard on December 31, 2021, 07:57:05 AM
I agree with not putting closed in
I managed to change the script so that there is an option to not have a z value.
- so that the same script can be used for 3d splines - which a lot of people have asked for
I have commented out the closed spline bit
I have included a tab or comma as a delimiter  - This will need to be removed if your locale has a comma decimal separator.

...


What Line(s) of the script creates "... an option to not have a z value", Nikki.

I spent considerable time with a variation of this script yesterday, so I'm pretty familiar with it; but I'm not able to identify that Line(s) in your script.

Could it be ...?

if nm >= 3
     z = System::Convert.ToDouble(System::Convert.ToString(d[2]))
    else
    z = 0

Henry H

Alvin Gregorio

Quote from: Henry Hubich on December 31, 2021, 02:10:08 PM
...

Could it be ...?

if nm >= 3
     z = System::Convert.ToDouble(System::Convert.ToString(d[2]))
    else
    z = 0

Henry H

Yes, that would make sense Henry.  Thanks.  I can relax now and get back to helping my girlfriend get ready for her New Year's Eve Party.  ;D

Happy New Years! everyone...
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)

Dean

Quote from: nikkipollard on December 31, 2021, 07:57:05 AM
I agree with not putting closed in
I managed to change the script so that there is an option to not have a z value.
- so that the same script can be used for 3d splines - which a lot of people have asked for
I have commented out the closed spline bit
I have included a tab or comma as a delimiter  - This will need to be removed if your locale has a comma decimal separator.

Works like a charm Nikki  :) nice work
Simple > import the NACA foil dat file, no fussing.
"What do I know, I'm still learning".
Lenovo Legion T5  Intel(R) Core(TM) i7-14th Gen 20 cores Nvidia RTX 4070 Super 16GB Windows 11 home TurboCad 2025 with Animation Lab 6.0