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.

Steve Edwards

 I came across a wing design that I would like to incorporate in my model glider wing. The difference is the curved trailing edge profile. It seems a simultaneous Rail Sweep and Lofting are required.  How would I do this in TurboCad?
Your thoughts would be appreciated.
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

Andy H

A couple of ways spring to mind.  Either loft with a guide line.  occasionally takes trial and error.  Or. loft with an intermediate profile.   In the attached, the greem 3d spline is the guide.  And the green closed profile is the intermediate one.  Obviously nothing is to scale nor accurate for your needs, but it is just an example.  TCv2020 file attached.  Note, the wing is two separate pieces,  It can be made as a single piece with a bit more work.

Alvin Gregorio

Quote from: Wwwdotsteve on December 12, 2021, 07:54:26 AM
I came across a wing design that I would like to incorporate in my model glider wing. The difference is the curved trailing edge profile. It seems a simultaneous Rail Sweep and Lofting are required.  How would I do this in TurboCad?
Your thoughts would be appreciated.
Steve

Can to you upload/attach the file as you have it progressed thus far Steve.
As Andy said, achieving desired results via the Loft tool can be tricky and particular.
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

Thanks for replies. Andy, I shall have a play tomorrow along the lines you suggested. The tcw file is attached with the 2d profiles shown and used to "loft" the inner and outer profiles before subtracting one from the other. I will need inner and outer solids offset by 0.4mm (to keep it lightweight).


At this time the whole glider is complete and mostly printed, the wings in three 200mm sections, however even at this late stage I would like to change the root section along the lines discussed if possible.


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: Wwwdotsteve on December 12, 2021, 01:33:18 PM
Thanks for replies. Andy, I shall have a play tomorrow along the lines you suggested. The tcw file is attached with the 2d profiles shown and used to "loft" the inner and outer profiles before subtracting one from the other. I will need inner and outer solids offset by 0.4mm (to keep it lightweight).
...

I might suggest instead of lofting two sets of Profiles, and 3D_Subtracting one from the other to achieve a "shell", maybe just do one (the outer, makes most sense to me), and use TurboCAD's Shell Tool.
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

#5
I had a play with the wing, and TC did not like using guidelines on it.  This may be because the 2d profiles are polylines rather than splines,  I roughly traced with splines, and guidelines worked.  But I suspect lofting with polylines, TC is trying to line up straight node to node. and the guides completely throw it off.

For your wing I'd suggest using an intermediate profile.  What I did was loft as normal (using your two root profiles).  Sliced the loft, roughly in half, and deleted one half.  I them made a copy of the larger profile, and moved it to the face of the remaining half loft (if that makes sense).  Then resized it using the selector mode rather than node edit,  to match the face as close as possible.  Did a few bits of node editing to tweak the profile into place.  Again in selector mode, I just dragged the back edge in a bit, roughly a third of the way between the face and smaller (mid section) profile.  Lastly lofted the three profiles with compound profile turned on.  So I could tweak the intermediate profile without having to keep remaking the loft.

This is obviously trial and error to make sure it matched the middle section of the wing correctly.  It took a couple of tries to shell, but it worked.   It was also a touch fiddly aligning it with the existing wing sections as they are at an angle, but eventually it got there.

Steve Edwards

Hi Andy, you have obviously spent a lot of time on this and I will try to follow you methodology. I went to a polyline profile because my original spline profile caused problems when scaling the profile for the intermediate wing sections. They would not loft and you also end up with a radius on the trailing edge. Please would you post your tcw file, it will help me understand how to achieved to result. Thank you


Alvin, my first thoughts and attempts were to shell the sections too. The two larger sections worked but the tip section would not shell "Can,t shell  this object. ACIS message: Wire has self-intersecting"
I suspect as a smaller scale section the shelling has difficulty, there is also a slight twist on this section too (anti-tip stall feature) Lofting and subtracting works though.
Maybe as a spline profile, shell the whole wing and then cut into three sections might work? The sections need to be open at both ends.


My problem is not knowing where the pitfalls of each method are. What I think is the obvious way turns out not to be. If anyone wants to suggest the definitive way to produce these wing sections I would be pleased to hear. I will try the "Andy method"later
Thank all
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

Steve, can you supply us with whatever it is that you are working from.  You wrote " I came across a wing design that I would like to incorporate in my model glider wing".  Is that some type of dimensioned drawing?  Is is a non-dimensioned 2D image or pdf with the profiles and perhaps standard views?

That.  Can you provide us with that.
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

Quote from: Wwwdotsteve on December 13, 2021, 03:08:17 AM
Please would you post your tcw file, it will help me understand how to achieved to result. Thank you

Hmm. I didn't save the file.  But just remade it step by step.  Didn't take long, as you already had the 2d profiles.  except the first loft attempt failed to shell. remaking it solved that.   

You will notice I delete a couple of 'double nodes' (two nodes occupying the same space).  Whilst in many cases this won't affect the part.  In some circumstances they can affect things like shelling / blending.

Steve Edwards


Hi AlvinThe wing design came from a SolidWorks Youtube Video  https://youtu.be/wBV-tu7XQ5Y
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

Steve Edwards

Thanks for the tcw file with notes Andy.  Just what I needed.
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

Henry Hubich

A couple of comments...

You can use Spline profiles and still have a sharp trailing edge. Start the profile at the trailing edge and vertex snap to the starting point to finish the spline. Use "Finish," NOT "Close." In the latest few versions of TCad, "Close" is not really necessary in order to avoid creating a Sheet object.

My Loft would not shell directly, but I was able to select the curved faces with the Facet Editor, convert them via Create Surface>From Face(s), and Shell the result.

Henry H

Alvin Gregorio

#12
Quote from: Wwwdotsteve on December 13, 2021, 09:36:11 AM

Hi AlvinThe wing design came from a SolidWorks Youtube Video  https://youtu.be/wBV-tu7XQ5Y

Man... that was a cranked-up time-lapse video.
I slowed it down to .25 speed, muted the volume.
At the beginning, if I paused and un-paused real quick, I finally ascertained that he was probably using a Curve procured from airfoiltools.com, that airfoil being NACA 2414 (I could see the name flash by in his File Explorer window).

I copied the ordinates data from that Dat file, then pasted into Excel.  Doing some things in Excel, I then copied and pasted that into TurboCAD's Parametric Part Script Editor.  Saved that .ppm.  Then inserted it.  To my surprise, it was a curved looking object; I expected it be a Polyline with straight segments, which I would then have to Snap a Spline By Fit Points to its vertices.
It was the same airfoil the video author started out with.  As he did, we need to add the arc at the trailing edge.  [EDIT:  I ultimately did insert a Spline By Fit Points, using Vertex Running Snap, snapping to an Exploded instance of that inserted Parametric Symbol]

Below is my .ppm script.  I forgot how to get rid of the spaces/tabs from Excel into a Text editor, and I'm sleepy, so I stopped trying, knowing that TurboCAD's PPSE doesn't care; it could be cleaned up (the text/script, not the resultant airfoil curve).
//NACA 2414 airfoil curve
//After insertion into TurboCAD Modelspace, insert an arc at the trailing edge end

Units(1[mm]);

P= Polyline(
Point ( 1.00000 , 0.00147 ) ,
Point ( 0.99739 , 0.00210 ) ,
Point ( 0.98929 , 0.00396 ) ,
Point ( 0.97587 , 0.00700 ) ,
Point ( 0.95729 , 0.01112 ) ,
Point ( 0.93372 , 0.01620 ) ,
Point ( 0.90542 , 0.02207 ) ,
Point ( 0.87267 , 0.02857 ) ,
Point ( 0.83582 , 0.03552 ) ,
Point ( 0.79527 , 0.04274 ) ,
Point ( 0.75143 , 0.05004 ) ,
Point ( 0.70480 , 0.05723 ) ,
Point ( 0.65586 , 0.06412 ) ,
Point ( 0.60515 , 0.07053 ) ,
Point ( 0.55324 , 0.07629 ) ,
Point ( 0.50069 , 0.08120 ) ,
Point ( 0.44808 , 0.08512 ) ,
Point ( 0.39598 , 0.08787 ) ,
Point ( 0.34454 , 0.08913 ) ,
Point ( 0.29482 , 0.08866 ) ,
Point ( 0.24740 , 0.08645 ) ,
Point ( 0.20285 , 0.08255 ) ,
Point ( 0.16169 , 0.07707 ) ,
Point ( 0.12440 , 0.07014 ) ,
Point ( 0.09141 , 0.06198 ) ,
Point ( 0.06310 , 0.05281 ) ,
Point ( 0.03977 , 0.04289 ) ,
Point ( 0.02165 , 0.03245 ) ,
Point ( 0.00892 , 0.02171 ) ,
Point ( 0.00169 , 0.01085 ) ,
Point ( 0.00000 , 0.00000 ) ,
Point ( 0.00379 , -0.01031 ) ,
Point ( 0.01293 , -0.01956 ) ,
Point ( 0.02730 , -0.02770 ) ,
Point ( 0.04669 , -0.03471 ) ,
Point ( 0.07087 , -0.04054 ) ,
Point ( 0.09957 , -0.04516 ) ,
Point ( 0.13246 , -0.04858 ) ,
Point ( 0.16918 , -0.05082 ) ,
Point ( 0.20937 , -0.05195 ) ,
Point ( 0.25260 , -0.05208 ) ,
Point ( 0.29844 , -0.05133 ) ,
Point ( 0.34644 , -0.04987 ) ,
Point ( 0.39611 , -0.04787 ) ,
Point ( 0.44739 , -0.04537 ) ,
Point ( 0.49931 , -0.04232 ) ,
Point ( 0.55129 , -0.03886 ) ,
Point ( 0.60276 , -0.03516 ) ,
Point ( 0.65316 , -0.03132 ) ,
Point ( 0.70194 , -0.02745 ) ,
Point ( 0.74857 , -0.02365 ) ,
Point ( 0.79252 , -0.01998 ) ,
Point ( 0.83331 , -0.01650 ) ,
Point ( 0.87048 , -0.01328 ) ,
Point ( 0.90360 , -0.01035 ) ,
Point ( 0.93230 , -0.00776 ) ,
Point ( 0.95626 , -0.00557 ) ,
Point ( 0.97518 , -0.00381 ) ,
Point ( 0.98886 , -0.00252 ) ,
Point ( 0.99713 , -0.00173 ) ,
Point ( 1.00000 , -0.00147 )
);

Output(P);
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)

Alvin Gregorio

Here's a semi-colon delimited .csv file of that NACA 2414 airfoil that can be used for TurboCAD's Ruby Console "Import XYZ Points".
Since the airfoil ordinates are provided at a factor 1 in width/scale, and the author of that video scaled it to be 150 wide/long, in Excel I multiplied all the airfoil.com-provided ordinates by 150 (and added the 0's for the Z's) before exporting as .csv.

After insertion via the Ruby Console, one can Vertex Snap a Spline By Fit Points to the Point Objects to get the airfoil profile (except for that trailing edge closing arc).

I believe one can just copy/paste the text below into Notepad and Save, then change the file extension to .csv for that Ruby Script to recognize.

I was going to try to replicate the wing; but not enough information can be ascertained from the video.

150.00000;0.22050;0
149.60850;0.31500;0
148.39350;0.59400;0
146.38050;1.05000;0
143.59350;1.66800;0
140.05800;2.43000;0
135.81300;3.31050;0
130.90050;4.28550;0
125.37300;5.32800;0
119.29050;6.41100;0
112.71450;7.50600;0
105.72000;8.58450;0
98.37900;9.61800;0
90.77250;10.57950;0
82.98600;11.44350;0
75.10350;12.18000;0
67.21200;12.76800;0
59.39700;13.18050;0
51.68100;13.36950;0
44.22300;13.29900;0
37.11000;12.96750;0
30.42750;12.38250;0
24.25350;11.56050;0
18.66000;10.52100;0
13.71150;9.29700;0
9.46500;7.92150;0
5.96550;6.43350;0
3.24750;4.86750;0
1.33800;3.25650;0
0.25350;1.62750;0
0.00000;0.00000;0
0.56850;-1.54650;0
1.93950;-2.93400;0
4.09500;-4.15500;0
7.00350;-5.20650;0
10.63050;-6.08100;0
14.93550;-6.77400;0
19.86900;-7.28700;0
25.37700;-7.62300;0
31.40550;-7.79250;0
37.89000;-7.81200;0
44.76600;-7.69950;0
51.96600;-7.48050;0
59.41650;-7.18050;0
67.10850;-6.80550;0
74.89650;-6.34800;0
82.69350;-5.82900;0
90.41400;-5.27400;0
97.97400;-4.69800;0
105.29100;-4.11750;0
112.28550;-3.54750;0
118.87800;-2.99700;0
124.99650;-2.47500;0
130.57200;-1.99200;0
135.54000;-1.55250;0
139.84500;-1.16400;0
143.43900;-0.83550;0
146.27700;-0.57150;0
148.32900;-0.37800;0
149.56950;-0.25950;0
150.00000;-0.22050;0
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

I'm pleased to say, with your help I have managed to achieve the glider wing design I was after. I adopted the "Andy method" and inserted not one but two extra sections to Loft through. Two gave me the most pleasing result.
[/size]A few of comments
[/size]1. I did not redraw the aerofoil profiles, they remained as 2DPolyline objects. In earlier attempts to do similar, using a 2D Spline object overlay copied from a PDF underlay, the Lofting failed (maybe too many control point or overlapping ones particularly when scaled down from the original)
[/size]2. I was unable to Shell the object and whilst I could have adopted Henry's approach and Facet Edit to convert to Surface I instead Offset the 2D profiles by 0.4, created an inner core by the same Lofting technique, and then Subtracted the inner core from the outer Solid, it worked fine.
[/size]3. Of the various tools that I could have used, Rail Sweep or Lofting following a line seemed the obvious tools. I could not get either to work and there is no way I would have guessed Lofting through intermediate profiles would have produced a curve. I thought it would straight-lined between them.
[/size]4. Shelling seems to be the obvious way to produce this part (all wing sections that is), and when it did work on the middle section it left one closed end, which I then had to Slice off. No real problem with that, but in reality Subtracting inner from outer was much easier.
[/size]
[/size]I have 3D printed this Curved Wing Root section (see attached) as a *Surface model in Lightweight PLA. It looks really good even if I say so myself, weighing just over 40g.
[/size]The other sections were already printed, so I'm ready to put the thing together after which I'll post an image of the full thing in due course.
[/size]
[/size]* Surface is a term used by the slicer software and nothing to do with a TurboCAD Surface
[/size]
[/size]What does please me is TurboCAD has never failed to produce the result I'm after. It may not be the most intuitive and can often be frustrating to use at times, however is always equal to the task albeit, as in this case, with assistance.
[/size]I guess that's why we have a Forum!
[/size]I downloaded the aerofoil profile from NACA (Knacker) website NACA Database. The coordinates were copied and pasted as a .CSV or .txt file in Excel.  I used the Import Terrain function but it tries to triangulate each point (as you would with terrain data) and the results on screen are difficult to interpret, they are good enough to create a Polyline or Spline.
[/size]I did find the Ruby script, but got confused on how to use it. Subsequently I have seen Alvin's post. I'll read this later and have another go.
[/size]
[/size]The NACA site is really good site if you want Aerofoils.
[/size]
[/size]Thanks all .............on to the next project.
[/size]Steve
[/size]I will have to post the images separately, seems iPad images cause the post to crash
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

Steve Edwards

Here are the images and tcw file....... hopefully.
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

#16
Quote from: Wwwdotsteve on December 15, 2021, 02:03:43 AM
Here are the images and tcw file....... hopefully.

Looks good Steve.  Mission accomplished.  I need to get me a 3D Printer.  What make/model do you use and how much $US would it set someone back?

How do you weld up the sections?  Perhaps (in the future) implementing a tab/extension that slides into the adjoining section would facilitate joining the sections together.  One could even put small tabs on that tab/extension that click into receiver notches in the adjoining section.

Could you Save and post a 2020 version of your Drawing file for me?  I think I have an idea/suggestion for future wing projects.
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)

Jeff_in_90620

Quote from: Alvin Gregorio on December 15, 2021, 03:41:31 AM
Could you Save and post a 2020 version of your Drawing file for me?  I think I have an idea/suggestion for future wing projects.

Here you go.

Jeff
Jeff

TC 2026 Pro Platinum plus 2015->2024 (most with LightWorks & RedSDK) & V21
System: AMD Ryzen 9 7950X, MSI Mag X670E Tomahawk WiFi, 64GB RAM @ 4.80GHz, ARC A770 w/16GB, 3 x Samsung NVMe 990 (1TB), Windows 11 Pro (64-bit)

Steve Edwards

I had the Windows default "open file" set to TC2018, which I think is the source of the version problem. I have changed it to 2020.


On the NACA site if you click on the "send to plotter" link you can download the .CSV file directly. The only problem is Ruby does not like the format to open it. The data is comma separated and we need Semi colon. Despite my best efforts I cant seem to fix this.
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

murray dickinson

You can open a .csv directly into a text editor like Notepad, and use edit|find|replace to change delimiters.

Andy H

It turned out really well Steve.  Its good to see drawings turned into physical form.

Steve Edwards

Thanks Murray, will try Notepad later.


Alvin my Printer is a Creality CR10 S and about 3 years old. The later version is https://www.creality.com/goods-detail/cr-10-v2-3d-printer No price on the US website but around $300 to $350.


Please feel contact me by email (Members details) if you wish to know more. There are few pitfalls, but the Creality machines are good, high quality parts and large buildplate and good price 
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: Wwwdotsteve on December 15, 2021, 04:36:35 AM
On the NACA site if you click on the "send to plotter" link you can download the .CSV file directly. The only problem is Ruby does not like the format to open it. The data is comma separated and we need Semi colon. Despite my best efforts I cant seem to fix this.

That would have saved me a lot of time yesterday.  I was so sleepy yesterday (my circadian has been way off the past several months), my brain was functioning <60%.

I like this project.  For a blue-collar, high-school-educated, framing-carpenter, general-contractor guy that got into CAD to do architectural submittal and construction plans, all this stuff is very interesting and intriguing to me.
__________
I used Murray's suggested method in Notepad to Find/Replace the commas to semicolons.
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)

Alvin Gregorio

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)

Alvin Gregorio

#24
I used the NACA_6409-9% airfoil .csv file, first set to a chord width of 100, from that NACA Database site to
In Excel, added some Text, then selected all that and Copied
In Notepad, pasted; then used Find/Replace in Notepad to find all the tab space entries in unison and delete them in unison.
Then Copied that and Pasted into TurboCAD Parametric Part Script Editor.
Added a bit of script in PPSE, making it a Spline when inserted.

Inserted.

Changed the Units Scale (at the top of the script) from 1 to 1.15, then inserted again;
Changed the Units Scale from 1.15 to 1.5 and inserted again.

Moved the 1[x100] insertion and the 1.15[x100] insertion 212mm and 112mm respectively.
With Make Copy active, moved a copy of the 1.5[x100] insertion 12mm.

Exploded all four of those Parametric Symbols to turn them into Splines.

Use the Offset Tool to create offset copies of those Splines, -4mm.  Created a Category for them in Design Director; so that I can hide them easily.
Inserted a Line and an Arc, to be used as Loft Guide Lines.
Lofted each sub-section of the wing section individually, selecting those Guide Lines for the middle sub-section, that has the curve at the trailing edge.
3D_Added those three sub-sections together.

Repeated that for the Offset copies that will be used to create a shell by 3D_Subtracting.  (because of the sharp edge at the curved trailing edge, the Shell Tool won't work)

Used Quick Pull to pull the ends of the to-be Subtrahend object out 10mm, so as to not have coincident faces when doing the 3D_Subtract.
Did the 3D_Subract.

Came out good.  Smooth.  I don't like the extraneous profiles where the sub-sections were joined by the 3D_Add, but I can live with it I guess.

Below is the PPM script and the resultant .tcw file.  Select/Copy the script and Paste into TurboCAD PPSE.  Insert.  Change the PPM scale at the top of the script, and Insert again, ensuring the far-right button at the top of the PPSE is not engaged (if it is engaged, it will "update" the previous insertion, thereby replacing it, not inserting another).  Repeat.

//Airfoil Profile; NACA_6409-9%

Units(1[mm]);

Sc=Parameter("Scale",1,LINEAR);//ignore; work in progress
ScX=ScaleX(Sp,2);//ignore; work in progress

Output(Sp)

Sp=Spline(
Point(100,0),
Point(99.732,0.084),
Point(98.93,0.333),
Point(97.603,0.737),
Point(95.76,1.284),
Point(93.423,1.954),
Point(90.615,2.724),
Point(87.357,3.571),
Point(83.69,4.464),
Point(79.647,5.378),
Point(75.272,6.283),
Point(70.608,7.153),
Point(65.71,7.961),
Point(60.627,8.684),
Point(55.413,9.302),
Point(50.132,9.796),
Point(44.84,10.152),
Point(39.59,10.36),
Point(34.367,10.352),
Point(29.315,10.086),
Point(24.502,9.584),
Point(19.988,8.874),
Point(15.83,7.992),
Point(12.08,6.982),
Point(8.78,5.889),
Point(5.968,4.762),
Point(3.677,3.646),
Point(1.92,2.581),
Point(0.72,1.603),
Point(0.08,0.737),
Point(0,0),
Point(0.467,-0.573),
Point(1.467,-0.956),
Point(2.973,-1.157),
Point(4.97,-1.192),
Point(7.428,-1.08),
Point(10.317,-0.844),
Point(13.607,-0.513),
Point(17.257,-0.119),
Point(21.235,0.307),
Point(25.498,0.729),
Point(30.012,1.112),
Point(34.73,1.425),
Point(39.618,1.639),
Point(44.707,1.772),
Point(49.868,1.871),
Point(55.04,1.925),
Point(60.167,1.929),
Point(65.193,1.88),
Point(70.065,1.78),
Point(74.728,1.634),
Point(79.13,1.451),
Point(83.223,1.241),
Point(86.957,1.017),
Point(90.288,0.791),
Point(93.18,0.576),
Point(95.593,0.383),
Point(97.503,0.221),
Point(98.883,0.101),
Point(99.722,0.025),
Point(100,0));

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

Hi Alvin,
Wow you have got into this. I need a day to analyse your methods.


In the meantime I have written some instructions on downloading and preparing CSV data for use in Ruby somewhat expanding on your description and hopefully between us making it less prone to error for anyone wanting to input xyz data.
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

#26
Quote from: Wwwdotsteve on December 15, 2021, 02:11:37 PM
In the meantime I have written some instructions on downloading and preparing CSV data for use in Ruby somewhat expanding on your description and hopefully between us making it less prone to error for anyone wanting to input xyz data.

Thanks for that Steve.  Well done; very clear and concise.

Regarding your Step-12:  For a reason currently unknown to me, Excel adds a Tab between the columns', which presents as a space.  So, for me in Excel, after Pasting into Notepad, I have to select/highlight one of those Tab-created spaces and Copy, then Paste into and do that Find/Replace thing for all instances of that Tab/Space, Replacing that Tab/Space with nothing-- null.
I'm sure with a little research I can learn how to rectify that in Excel and/or within the Copy/Paste operations.
_____
[EDIT:  Since you are just using the Ruby Console created/inserted Point Objects to Snap a Spline or Polyline to, I see why you say you can omit that last Point's coordinates.]
A Note:  In your Step-9, you state "... you might notice the same value(s) at the top and bottom of the data, you can delete the bottom duplicate row."  But if we do that, we are missing segment and get a gap at the bottom of the airfoil profile's trailing edge.
See below.  [EDIT:  That's my Snap Aperture in the bottom-right of the TurboCAD drawing space, overlaying the word "it", in the image below]
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)

Alvin Gregorio

#27
Regarding the shelling.

I did it with the Shell Tool.  With a caveat.
That tapered-to-zero trailing edge could use being beefed up.  It's subject to damage easily.
So I temporarily separated that from the rest of the wing section.
Shelled the wing section.
Then Added them back together.  This way, everything is .4mm thick, except that tapered-to-zero trailing edge-- which wouldn't receive much of the ribbing support-- is solid.
See annotated image below and .tcw file with Part Tree.
-Alvin

p.s.:  I might have been able to simply use a surface object to Slice the trailing edge from the rest of the wing section.
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


Hi AlvinMy aerofoil profile is modified to give some thickness to the trailing edge, however because the same profile is used scaled down in the outer sections of the wing this naturally diminishes to virtually tapered to zero on these sections and I guess this prevents Shelling working. I did wonder if I Shelled +0.4 to a Lofted core offset -0.4.
Adding a shell instead of subtracting, this would ad thickness to the tapered to zero features?



I take note of your comments about Excel adding a tabbed space in the data and I will modify my instructions accordingly to include this possible abnormality. Hopefully saving someone a lot of grief.


The wing sections in my design will be joined with "pegs" and carbon fibre tubes. This will ensure alignment and strength. The printing process adopted for these parts does not like horizontal or step features (surface mode printing) so I could not include location features. It is very experimental to me, but actually works really well. I just need to remember to select "normal" mode when finished.


Your wing model looks really good, I think you are being very critical of the sub section joins, I can tell you once this is saved as an .stl file for printing they will disappear.I'm still working through you method and appreciate the support you have given to my project.

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

I thought I'd share and clarify:
The airfoil Spline Parametric Symbol scripts I provided in this thread are not 100% accurate.  They are actually Splines "By Control Points", not "by Fit Points".  If we Explode the inserted airfoil Parametric Symbol once, and modify the resultant Spline's Properties to "Show Frame", and Zoom In very close, and ascertain somehow the points/nodes/knots coordinates, we can see that the PPM scripts' Points coordinates are actually to the Frame, not the associated displayed Spline.  Bummer... I thought I had happened across an easy way of inserting accurate Splines via coordinates input into PPSE.
____
I bumped into that by trying to answer my own query here.
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

Attached is an update to my "Instructions for importing aerofoil data". Now includes the some further screen images and a note concerning tabbed data in Excel and what to do about it.
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: wwwdotsteve on December 20, 2021, 05:56:55 AM
Attached is an update to my "Instructions for importing aerofoil data". Now includes the some further screen images and a note concerning tabbed data in Excel and what to do about it.
Steve

Nice document Steve.

A note:  At the bottom of Page-5 you state "If you use Spline by control point to join the dots you will have an odd shape at the trailing edge
where it comes to a point. Go to Node edit a manipulate the profile in this area to make it look right.
"

I think it's best to advise initially using "Spline by Fit Points"-- to result in a more correctly (in conformity with the airfoil design and coordinates) inserted Spline.  And, assuming one starts at the trailing edge, as they should-- I advise they use "Finish" to end the Spline By Fit Points operation, as opposed to "Close".
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

Awesome Steve. The ruby file can be easily modified to import the points as a spline by fitpoint instead of a polyline.
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

Alvin Gregorio

#33
Quote from: nikkipollard on December 20, 2021, 10:58:48 AM
Awesome Steve. The ruby file can be easily modified to import the points as a spline by fitpoint instead of a polyline.

Spline By Fit Points via Ruby Console is the way to go.  Of course, I don't know a thing about writing Ruby scripts.
Steve's instructions have us inserting Point Objects from the TurboCAD-installation-provided Ruby script "Import XYZ points" ("crosses"), then inserting/snapping a Spline to those.
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

#34
I altered Kevins script
You might want to change the name and fix the bottom
I commented out the bit that saves it to the menu - to check it works.


# TC20_RubyImportspline by fit points
# 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 or
# semicolons. 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

# Additional notes:
# If your locale uses a comma instead of a period as the decimal separator,
# you may need to format your xyz data as x,0; y,0; z,0 instead of x.0; y.0; z.0

# 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_lines

  # 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 polyline, 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.
  # This script currrently accepts spaces or semicolons as delimiters.
  # Adjust this behavior as you see fit.
   
  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
          #puts "drawing line"
          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
        #puts "adding new line"
        tcGr = tcGrs.Add(11) # Add new, empty polyline. Again, clear vertices and set UseWorldCS.
        grVerts = tcGr.Vertices
        types = 0
        grVerts.Clear(types)
        grVerts.UseWorldCS = true
        next
       
      else
  # Convert semicolons and semicolon-plus-spaces to spaces only.
  c = b.gsub(/; */, " ")
  #MessageBox.Show c
 
  # Split the line into numeric variables.
  d = c.split
 
  # 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]))
  #MessageBox.Show "Converted x: " + System::Convert.ToString(x)
 
  y = System::Convert.ToDouble(System::Convert.ToString(d[1]))
  #MessageBox.Show "Converted y: " + System::Convert.ToString(y)
 
  z = System::Convert.ToDouble(System::Convert.ToString(d[2]))
  #MessageBox.Show "Converted z: " + System::Convert.ToString(z)
 
        grVerts.Add(x, y, z) # Append this vertex to the current polyline.
  end  # This line processed.
  end  # All lines processed.
 
    # Draw the last polyline if it contains any vertices.
    if grVerts.Count > 0 then
      tcGr.Draw
    end
    tcGr.SetCurveVertexAsFitPoints
 
    # 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_lines
#UI.menu("Plugins").add_item("Import XYZ lines"){import_XYZ_lines}

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

Alvin Gregorio

#35
Quote from: nikkipollard on December 20, 2021, 11:38:38 AM
I altered Kevins script
You might want to change the name and fix the bottom
I commented out the bit that saves it to the menu - to check it works.

...

Wow.  That works great!  Perfect.  Steve's going to like this.

Makes me wanna model and build some airplanes.
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)

Alvin Gregorio

#36
I slightly edited the Ruby script Nikki provided so that it can be will be added to the drop-down list of available functions in the Ruby Console's pre-loads button.
There's a few ways of going about using my text below; one way:

>Select the code text below, and Copy it to the Windows clipboard.
>In TurboCAD, open the Ruby Console.
>In the lower pane of Ruby Console, Paste the text.
>"Save", at the bottom of the Ruby Console.
>Navigate to the Folder you want to save it in; probably best to keep it organized and all in one place by placing it in the default C:\Users\[user]\Documents\TurboCAD 2020 x64\RubyScripts folder.
>Enter "Import_XYZ_points_for_Spline_By_Fit_Points" as the File Name.  The .rb extension will automatically be added (assuming you leave "Save as type" as such; you should).
>Save and Close out of your current Drawing file.  Close out of TurboCAD.
>ReStart TurboCAD.
>Open the Ruby Console.
>If you did everything correctly, "Import XYZ points for Spline By Fit Points" should be listed in your Ruby Console available functions drop-down list.  (It is for me).
>Click on it.  That will prompt you to locate an .csv, .txt, or "All files".  You've got it from here.  (works for me)

# 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 or
# semicolons. 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

# Additional notes:
# If your locale uses a comma instead of a period as the decimal separator,
# you may need to format your xyz data as x,0; y,0; z,0 instead of x.0; y.0; z.0

# 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 polyline, 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.
   # This script currrently accepts spaces or semicolons as delimiters.
   # Adjust this behavior as you see fit.
   
   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
          #puts "drawing line"
          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
        #puts "adding new line"
        tcGr = tcGrs.Add(11) # Add new, empty polyline. Again, clear vertices and set UseWorldCS.
        grVerts = tcGr.Vertices
        types = 0
        grVerts.Clear(types)
        grVerts.UseWorldCS = true
        next
       
      else
     # Convert semicolons and semicolon-plus-spaces to spaces only.
     c = b.gsub(/; */, " ")
     #MessageBox.Show c
   
     # Split the line into numeric variables.
     d = c.split

     # 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]))
     #MessageBox.Show "Converted x: " + System::Convert.ToString(x)

     y = System::Convert.ToDouble(System::Convert.ToString(d[1]))
     #MessageBox.Show "Converted y: " + System::Convert.ToString(y)

     z = System::Convert.ToDouble(System::Convert.ToString(d[2]))
     #MessageBox.Show "Converted z: " + System::Convert.ToString(z)

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

    # Draw the last polyline if it contains any vertices.
    if grVerts.Count > 0 then
      tcGr.Draw
    end
    tcGr.SetCurveVertexAsFitPoints

    # 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

UI.menu("Plugins").add_item("Import XYZ Spline By Fit Points"){import_XYZ_spline_by_fit_points}
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

#37
Thanks Alvin I was being lazy.
I didn't check Does Kevins script close the spline?
I see that it is meant to deal with multiple splines
As I have it I think it will only work on the last spline. I am not that familiar with Ruby so I am a little unsure where one spline ends and the next starts
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

nikkipollard

I altered the script to all splines
I am still unsure how to make this script close the splines - the multiple splines complicates things for me.
Maybe someone with Ruby Skills can fix that.

# 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 or
# semicolons. 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

# Additional notes:
# If your locale uses a comma instead of a period as the decimal separator,
# you may need to format your xyz data as x,0; y,0; z,0 instead of x.0; y.0; z.0

# 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 polyline, 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.
   # This script currrently accepts spaces or semicolons as delimiters.
   # Adjust this behavior as you see fit.
   
   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
          #puts "drawing line"
          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
     # converts spline by control points to Fit points
     tcGr.SetCurveVertexAsFitPoints

      #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 and semicolon-plus-spaces to spaces only.
     c = b.gsub(/; */, " ")
     #MessageBox.Show c
   
     # Split the line into numeric variables.
     d = c.split

     # 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]))
     #MessageBox.Show "Converted x: " + System::Convert.ToString(x)

     y = System::Convert.ToDouble(System::Convert.ToString(d[1]))
     #MessageBox.Show "Converted y: " + System::Convert.ToString(y)

     z = System::Convert.ToDouble(System::Convert.ToString(d[2]))
     #MessageBox.Show "Converted z: " + System::Convert.ToString(z)

        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
      tcGr.Draw
    end
# converts spline by control points to Fit points
   tcGr.SetCurveVertexAsFitPoints

    # 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

nikkipollard

#39
]I am a little more comfortable with VB so
Here is a Vbscript version for the macro recorder.  - it only works with 1 spline at a time.
It will close the spline if the end points are the same.
Copy the script into the macro recorder and click the blue arrow to run.
You can choose the separator
The file looks for  points in this format
100.5,3001.2,600.3
If your decimal separator is a comma
you can change the pattern at the end
to
pat1="(-?\d+(?:\,?\d+))"


Option Explicit
'_____________________________________________________________________________
'# macro to import points from csv file as a 3d or 2d  spline by fitpoints
'only draws one spline
'will ask how the csv file is separated - defaults to a comma
'If the end points are the same the spline will be closed
'_______________________________________________________________________________

Call Main


'_______________________________________________________________________________
Sub Main

Dim objFile,strLine,objFso,fileName
Dim Spline
Dim x1,y1,z1
Dim i, num,j
Dim IsClosed
Dim hasZ
Dim Points,Point
Dim sep

j = 0

fileName = Application.GetOpenFilename(".csv")
  If fileName = "" Then Exit Sub                                   '# User cancelled
sep = Inputbox("Point Separator","",",")
If sep = "" then Exit Sub                                           '# User Cancelled

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(fileName)

Do While Not objFile.AtEndOfStream
  strLine = objFile.readline
  If IslinePoint(strLine,sep) Then
   Call AddToArray(Points,strLine)
   End If
Loop

objFile.Close

If IsArray(Points)=False Then
MsgBox "The points don't seem to be in the right format"
Exit sub
End If

num = Ubound(Points)

If Ubound(Points)<1 then
MsgBox "The points don't seem to be in the right format"
Exit sub
End If

Point = Split(Points(0),sep)
hasZ = True
If Ubound(Point) < 2 Then hasZ = False

If Points(j) = Points(num) Then
  IsClosed = True
  num = num - 1
Else
Isclosed = False
End If

x1 = Cdbl(Point(0))
y1 = Cdbl(Point(1))
  If HasZ = True Then
  z1 = Cdbl(Point(2))
  Else
  z1 = 0
End If

Set Spline = ActiveDrawing.Graphics.AddcurveSpline(x1,y1,z1)
Spline.Vertices.UseWorldCS = True
On Error Resume Next
For i = 0 to num
Point = Split(Points(i),sep)
x1 = cdbl(Point(0))
y1 = cdbl(Point(1))
   If HasZ = True Then
   z1 = cdbl(Point(2))
   Else
   z1 = 0
   End If
Spline.Vertices.Add x1,y1,z1
next

  If IsClosed = True Then
   Spline.Vertices.AddClose
   End If
Spline.SetCurveByFitPoints
Spline.Update
Spline.Draw
Dim UndoRec
Set UndoRec = ActiveDrawing.AddUndoRecord("Add Spline from csv")
UndoRec.AddGraphic Spline
UndoRec.Close

Set Spline = Nothing
ActiveDrawing.ActiveView.Refresh

End sub


'_____________________________________________________________________________________
Sub AddToArray(ByRef a, v)
   On Error Resume Next
   ReDim Preserve a(UBound(a)+1)
    a(UBound(a)) = v
If Err <> 0 Then
  Redim a(0)
  a(0) = v
  End If
Err.Clear
End Sub
 
'______________________________________________________________________________________

Function IsLinePoint(line,sep)

dim pat,pat1
'(-?\d+(?:\.?\d+));(-?\d+(?:\.?\d+));(-?\d+(?:\.?\d+))|(-?\d+(?:\.?\d+));(-?\d+(?:\.?\d+))

pat1="(-?\d+(?:\.?\d+))"

pat = pat1 & sep & pat1 & sep & pat1 & "|" & pat1 & sep & pat1
dim re
Set re = New RegExp
  with re
             .Pattern    =   pat
            .IgnoreCase = True
            .Global = False
  end with

IsLinePoint = re.Test(line)

End Function




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

Alvin Gregorio

#40
Quote from: nikkipollard on December 20, 2021, 10:01:45 PM
Thanks Alvin I was being lazy.
I didn't check Does Kevins script close the spline?
I see that it is meant to deal with multiple splines
As I have it I think it will only work on the last spline. I am not that familiar with Ruby so I am a little unsure where one spline ends and the next starts

The script does not close the Spline.  Per Henry recently, in recent versions, entities do not have to be Closed in order to be Extruded, Lofted, etc. and result in a non-surface 3D object (that was news to me).  Of course, if not Closed, it will not accept a Brush.

I have no clue as to what you are referring to regarding "multiple splines" and "work only on the last spline".

Here is a .txt file you can use for experimenting.  An airfoil (wing profile).  Start Point and End Point are the same; but not Closed.
Reminder:  What we have last inserted a Curve object, in regards to "Show Frame" (and Number of segments?, and Degree?), is what will occur with this Ruby insertion.

100;0;0
99.732;0.084;0
98.93;0.333;0
97.603;0.737;0
95.76;1.284;0
93.423;1.954;0
90.615;2.724;0
87.357;3.571;0
83.69;4.464;0
79.647;5.378;0
75.272;6.283;0
70.608;7.153;0
65.71;7.961;0
60.627;8.684;0
55.413;9.302;0
50.132;9.796;0
44.84;10.152;0
39.59;10.36;0
34.367;10.352;0
29.315;10.086;0
24.502;9.584;0
19.988;8.874;0
15.83;7.992;0
12.08;6.982;0
8.78;5.889;0
5.968;4.762;0
3.677;3.646;0
1.92;2.581;0
0.72;1.603;0
0.08;0.737;0
0;0;0
0.467;-0.573;0
1.467;-0.956;0
2.973;-1.157;0
4.97;-1.192;0
7.428;-1.08;0
10.317;-0.844;0
13.607;-0.513;0
17.257;-0.119;0
21.235;0.307;0
25.498;0.729;0
30.012;1.112;0
34.73;1.425;0
39.618;1.639;0
44.707;1.772;0
49.868;1.871;0
55.04;1.925;0
60.167;1.929;0
65.193;1.88;0
70.065;1.78;0
74.728;1.634;0
79.13;1.451;0
83.223;1.241;0
86.957;1.017;0
90.288;0.791;0
93.18;0.576;0
95.593;0.383;0
97.503;0.221;0
98.883;0.101;0
99.722;0.025;0
100;0;0
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

#41
If you dont close a spline yoiu will get a sharp point at the end not a continuous curve.
In Kevins script - every time you get to an empty line  he starts a new polyline. So you can process as many polylines as you like with 1 command.
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

Alvin Gregorio

Quote from: nikkipollard on December 21, 2021, 09:03:54 AM
[A] If you dont close a spline yoiu will get a sharp point at the end not a continuous curve.
[Be] In Kevins script - every time you get to an empty line  he starts a new polyline. So you can process as many polylines as you like with 1 command.

(A) I figured the person who created the airfoil datapoint set knew more about airfoils than me, and intentionally wanted a sharp point at the trailing edge.  Having said that-- the first thing a guy does on a Solidworks video tutorial using an airfoil datapoint set from the same site Steve linked us to is inserted an arc at that trailing edge; the airfoil datapoint set he used had the Y coordinate of the Start and End points about a millimeter apart (very open).

(Be) I'll check that out, once I get my Ruby Console back fully operational.
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)

Alvin Gregorio

Quote from: wwwdotsteve on December 20, 2021, 05:56:55 AM
Attached is an update to my "Instructions for importing aerofoil data". Now includes the some further screen images and a note concerning tabbed data in Excel and what to do about it.
Steve

Tip:  If we modify the Ruby script (and Save), to include commas and commas+spaces (and Tabs?) in the list of delimeters that it will read from a .csv or .txt or similar file and substitute with a space, it would save required conversion steps before using the Ruby Console to insert the function into the active Drawing.

I think the edit would be in Line-112, shown below (Kevin Chapman's original "Import XYZ lines" Ruby script).  I'm not sure right now of the correct syntax; but I'm sure Andy and/or Nikki or someone can offer that, or we can suss it out.
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)

Alvin Gregorio

#44
This revised Ruby script* closes the Spline.  Whether or not a Brush is applied upon insertion (executing the function) is dependent on the last pre-set of one of TurboCAD's Curve Tools; I presume the same applies for Segments and Degrees, but that has not been tested by me.
This revised script also adds .txt files to the list of available file types in the Open file-types drop-down field-box.

TO DO:  Add commas, commas+spaces, Tabs, Tabs+spaces, to the c = b.gsub(/; */, " ") Line.
TO DO:  Add script so that insertion (executing the function) into the active Drawing space is added to the active Drawing's Undo list.
___
script writing is SO PARTICULAR!  can't omit or get wrong even ONE character

One nice thing about the Ruby Console:  The output dialogue, when we get something wrong, can be very informative and useful.  It told me exactly what I was entering wrong, and exactly how to repair it.
___
*revised from Nikki's provide script, which revised Kevin Chapman's original TurboCAD-installation provided script

# 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 or
# semicolons. 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

# Additional notes:
# If your locale uses a comma instead of a period as the decimal separator,
# you may need to format your xyz data as x,0; y,0; z,0 instead of x.0; y.0; z.0

# 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_4

  # 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|Text files (*.txt)|*.txt|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 polyline, 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.
   # This script currrently accepts spaces or semicolons as delimiters.
   # Adjust this behavior as you see fit.
   
   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
          #puts "drawing line"
          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
        #puts "adding new line"
        tcGr = tcGrs.Add(11) # Add new, empty polyline. Again, clear vertices and set UseWorldCS.
        grVerts = tcGr.Vertices
        types = 0
        grVerts.Clear(types)
        grVerts.UseWorldCS = true
        next
       
      else
     # Convert semicolons and semicolon-plus-spaces to spaces only.
     c = b.gsub(/; */, " ")
     #MessageBox.Show c
   
     # Split the line into numeric variables.
     d = c.split

     # 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]))
     #MessageBox.Show "Converted x: " + System::Convert.ToString(x)

     y = System::Convert.ToDouble(System::Convert.ToString(d[1]))
     #MessageBox.Show "Converted y: " + System::Convert.ToString(y)

     z = System::Convert.ToDouble(System::Convert.ToString(d[2]))
     #MessageBox.Show "Converted z: " + System::Convert.ToString(z)

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

    # Draw the last polyline if it contains any vertices.
    if grVerts.Count > 0 then
      tcGr.Draw
grVerts.AddClose(true, true, true, true, true, true)
    end
    tcGr.SetCurveVertexAsFitPoints

    # 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

UI.menu("Plugins").add_item("Import XYZ Spline By Fit Points; Closed"){import_XYZ_spline_by_fit_points_4}
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)

Alvin Gregorio

Quote from: nikkipollard on December 20, 2021, 11:40:00 PM
]I am a little more comfortable with VB so
Here is a Vbscript version for the macro recorder.  - it only works with 1 spline at a time.
It will close the spline if the end points are the same.
Copy the script into the macro recorder and click the blue arrow to run.
You can choose the separator
The file looks for  points in this format
100.5,3001.2,600.3
If your decimal separator is a comma
you can change the pattern at the end
to
pat1="(-?\d+(?:\,?\d+))"


Option Explicit
...


I thought you'd want to know Nikki.
I just now got around to trying this MacroRecorder script.
The result isn't Closed, although the start and end coordinates of the selected .csv (.txt, acutally) file are the same.  I'm using the below.  After insertion, a Brush applied in Properties does not display; also, using Edit Tool, the Local Menu option "Close" is available, not "Break".

Also:  You (or someone) included the ability to set the delimeter character after having selected the source file, but just before insertion.  Via a pop-up window.  So I didn't need to change pat1= to semicolon, I just entered ; in that popup window field-box.

100,0,0
99.732,0.084,0
98.93,0.333,0
97.603,0.737,0
95.76,1.284,0
93.423,1.954,0
90.615,2.724,0
87.357,3.571,0
83.69,4.464,0
79.647,5.378,0
75.272,6.283,0
70.608,7.153,0
65.71,7.961,0
60.627,8.684,0
55.413,9.302,0
50.132,9.796,0
44.84,10.152,0
39.59,10.36,0
34.367,10.352,0
29.315,10.086,0
24.502,9.584,0
19.988,8.874,0
15.83,7.992,0
12.08,6.982,0
8.78,5.889,0
5.968,4.762,0
3.677,3.646,0
1.92,2.581,0
0.72,1.603,0
0.08,0.737,0
0,0,0
0.467,-0.573,0
1.467,-0.956,0
2.973,-1.157,0
4.97,-1.192,0
7.428,-1.08,0
10.317,-0.844,0
13.607,-0.513,0
17.257,-0.119,0
21.235,0.307,0
25.498,0.729,0
30.012,1.112,0
34.73,1.425,0
39.618,1.639,0
44.707,1.772,0
49.868,1.871,0
55.04,1.925,0
60.167,1.929,0
65.193,1.88,0
70.065,1.78,0
74.728,1.634,0
79.13,1.451,0
83.223,1.241,0
86.957,1.017,0
90.288,0.791,0
93.18,0.576,0
95.593,0.383,0
97.503,0.221,0
98.883,0.101,0
99.722,0.025,0
100,0,0
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)

Alvin Gregorio

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.
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

Thanks Alvin.
The separator I added was to separate the x y and z coordinates
the dot is for numbers like this 2004.306
In some countries numbers are written like this 2004,306  - with a comma.
The regular expression uses that pattern to check the line of text is in the correct format before adding it to the array.
- less chance of errors further down the line.
it  allows you to add notes to the csv file.
I googled the pattern - It can be simplified but it works as is  so I left it.




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

nikkipollard

#48
Hi Alvin
I think I fixed the macro - it wasn't picking up points without a decimal place. - I changed the pattern
This script should work with 3d splines too

Option Explicit
'_____________________________________________________________________________
'# macro to import points from csv file as a 3d or 2d  spline by fitpoints
'only draws one spline
'If the end points are the same the spline will be closed
' points can be separated by a comma ,a space, atab or a semicolon.
' The script will need to be edited if your local decimal separator is a comma.- see GetPointsFunction

'_______________________________________________________________________________

Call Main
'_______________________________________________________________________________
Sub Main

Dim objFile,strLine,objFso,fileName
Dim Spline
Dim x1,y1,z1
Dim i, num,j
Dim IsClosed
Dim hasZ
Dim Points,Point
Dim sep
Dim Lay
Lay = "0"

fileName = Application.GetOpenFilename("CSV files (*.csv)|*.csv|XYZ files (*.xyz)|*.xyz|All files (*.*)|*.*")
'"
  If fileName = "" Then Exit Sub                                  '# User cancelled

sep = " "
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(fileName)

Do While Not objFile.AtEndOfStream
   strLine = objFile.readline
   strLine = GetPoint(strLine)
  If strLine <> "" Then
  Call AddToArray(Points,strLine)
  End If
Loop

objFile.Close

If IsArray(Points) = False Then
MsgBox "The points don't seem to be in the right format"
Exit sub
End If

num = Ubound(Points)
On Error Resume Next

Point = Split(Points(0),sep)
hasZ = True
If Ubound(Point) < 2 Then
hasZ = False
z1 = 0
End If

If Points(0) = Points(num) Then
  IsClosed = True
  num = num - 1
Else
  Isclosed = False
End If

'x1 = Cdbl(Point(0))
'y1 = Cdbl(Point(1))
' If HasZ = True Then z1 = Cdbl(Point(2))

Set Spline = ActiveDrawing.Graphics.Add(11,"TCW30CURVE")
Spline.Vertices.UseWorldCS = True

For i = 0 to num
  Point = Split(Points(i),sep)
  x1 = cdbl(Point(0))
  y1 = cdbl(Point(1))
   If HasZ = True Then z1 = cdbl(Point(2))
  Spline.Vertices.Add x1,y1,z1
Next

  If IsClosed = True Then
  Spline.Vertices.AddClose
  End If
With Spline
.SetCurveByFitPoints
.Layer = Lay
.Properties.Item("BrushStyle").Value = "None"
.Update
.Draw
End With
Dim UndoRec
Set UndoRec = ActiveDrawing.AddUndoRecord("Add Spline from csv")
UndoRec.AddGraphic Spline
UndoRec.Close

Set Spline = Nothing
ActiveDrawing.ActiveView.Refresh

End sub


'_____________________________________________________________________________________

  Sub AddToArray(ByRef a, v)

If IsArray(a) Then
  ReDim Preserve a(UBound(a)+1)
  a(UBound(a)) = v
Else
Redim a(0)
a(0) = v
End If

End Sub

'______________________________________________________________________________________

Function GetPoint(line)
   '# checks the line in file is in the correct point form and converts it to a space separated string

Dim spat
spat = "(; ?|, ?|\t| )"                                                                   ' #Coordinate Separator Pattern
'  # for comma decimal separator use
' spat = "(; ?|\t| )"         

Dim pat,pat1


pat1 = "(-?\d+\.?\d*)"                                                                    '# Coordinate Pattern
'  # for comma decimal separator use
'   "(-?\d+,?\d*)"

pat = "(^" & pat1 & spat & pat1 & spat & "?" & pat1 & "?$)"
Dim re
Set re = New RegExp
  With re
            .Pattern    =   pat
            .IgnoreCase = False
            .Global = False
  End With

If re.Test(line) = False Then
GetPoint = ""
Else

dim res
Set res = New RegExp
  with res
.Pattern    =   spat
.IgnoreCase = False
.Global = True
  end with


GetPoint = res.Replace(line," ")

End If

End Function




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

Steve Edwards

Looks like I have been missing out on a lot. I need to read all and digest.

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