TurboCAD Forums

The Ultimate Resource for TurboCAD Knowledge

Register
 
When replying to a specific statement be sure to quote the previous post.

vb.net polyline with arcs syntax
Read 215 times
* June 14, 2020, 02:52:05 AM
what procedure do you use for drawing a polyline with arcs in it. I am trying to learn vb.net latest version

I can draw a polyline using these 2 methods but if I try to add a bulge as per the VBA example in the sdk I am getting an error.

   'draw polyline

        Dim poly As IMSIGX.Graphic
        poly = TCDraw.Graphics.AddLineMultiline(0, 0, 0)
        poly.Vertices.UseWorldCS = True
        poly.Vertices.Add(0, 500, 0)
        poly.Vertices.Add(600, 600, 0)
        poly.Vertices.AddClose()
        poly.Draw()

    End Sub

    Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
        Dim poly As IMSIGX.Graphic

        poly = TCDraw.Graphics.Add(, "TCW50Polyline")
        poly.Vertices.UseWorldCS = True
        poly.Vertices.Add(0, 0, 0)
        poly.Vertices.Add(5, 0, 0)
        poly.Vertices.Add(5, 2.5, 0)  'arc centre
        'poly.Vertices.Add.Bulge = True
        poly.Vertices.Add(7.5, 2.5, 0)
        'poly.Vertices.Add.Bulge = True
        poly.Vertices.Add(5, 5, 0)
        'poly.Vertices.Add.Bulge = False
        poly.Vertices.Add(0, 5, 0)
        poly.Draw()

the example in the sdk

'Add an arc "bulge" segment.
        'First specify the arc's center, then a pass-through point.
        'Set vx = verts.Add (5, 2.5, 0) arc center'
        'vx.Bulge = True
        'set vx = verts.Add(7.5, 2.5, 0)
        'arc pass-through
        'vx.Bulge = True
        'Set vx = verts.Add (5, 5, 0)
        'end of arc segment'vx.Bulge = False
        'verts.Add 0, 5, 0, False
        'hide this segment by setting PenDown to False'verts.AddClose True
        'close the polyline and show the last segment
        'grf.Draw


 
Nikki
TC20 platinum
TC 2015 platinum
TC 2017 with lightworks

Logged
Nikki
TC20 platinum
TC 2015 platinum
TC 2017 with lightworks


* June 15, 2020, 02:51:53 AM
#1
The only thing I can think of. Is that there are two examples in the SDK doc.

On the "Specifying Arc Segments in a Polyline" page, it doesn't specify what type of graphic to add the vertices to.  I don't know whether you tried this. Or
At the bottom of the "Using 2D Polyline Graphics (Regen)" page, The example is missing the Dim statements.  So a combination of the two should make it work.

You can use either Polyline or TCW50Polyline.

I could only try using VBS in AnimationLab. but the code works, except it does not close the polyline (did not bother trying to find out why). However the first few lines are slightly different in VBS, and I used the active drawing not adding a new one (AnimationLab runs in the active drawing).  So it won't look the same as your code for the first few lines (VBS used simple Dim statements not the full syntax like VB)

Dim appl
Dim drw
Dim grf
Dim verts
Dim vx

Set appl  = GetObject("", "TurboCAD.Application")
Set drw = appl.ActiveDrawing
Set grf = drw.Graphics.Add(, "TCW50Polyline")
Set verts = grf.Vertices
Set vx = verts.Add(0, 0, 0)
Set vx = verts.Add(5, 0, 0)
' Add an arc "bulge" segment. First specify the arc's center, then a pass-through point.
Set vx = verts.Add (5, 2.5, 0) 'arc center
vx.Bulge = True
set vx = verts.Add(7.5, 2.5, 0) 'arc pass-through
vx.Bulge = True
Set vx = verts.Add (5, 5, 0)  'end of arc segment
vx.Bulge = False
verts.Add 0, 5, 0, False 'hide this segment
verts.AddClose True
grf.Draw

Set grf = Nothing
Set drw = Nothing
Set app = Nothing
« Last Edit: June 15, 2020, 02:55:28 AM by Andy H »

Logged


* June 15, 2020, 04:25:20 AM
#2
Thanks Andy that is the code I had.
The bulge is not working I can see the option in the intellisense (???)
But I cant figure out what  what to do with the bulge. = true is an option but it throws an error.

says true is not boolean. my coding skills are non existent so I cant even argue.

- If remove the bulge and I get a polyline. I think I am missing something.

Logged
Nikki
TC20 platinum
TC 2015 platinum
TC 2017 with lightworks


* June 15, 2020, 12:29:50 PM
#3
Hi Nikki.

Been a lot of years since I looked at VB coding.  Anyway. I tried in VBA via excel first and it worked fine using what I posted above.

So I then tried using VB in Visual Studio (the free community one).   After a few false starts, Mainly because I had forgotten how to use it. And because I didn't know that VB had done away with the Set statement.  So I had to remove all the Set's. and tweak a couple of things

I started a new Windows form application. added a button and in the buttons click event I used the code below.  I realised why the 'AddClose' appeared not to work. setting one of the vertex to false, hides a line segment, So what I thought was not closed is just hidden.

Again I used the active drawing instead of a new one.

If it still fails, can you post your full code.     ## Edit## If you are using an old version of VB, like VB6, it will probably still need the Set statements. ##End Edit ##

Code: [Select]
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim appl As IMSIGX.Application
        Dim drw As IMSIGX.Drawing
        Dim grf As IMSIGX.Graphic
        Dim verts As IMSIGX.Vertices
        Dim vx As IMSIGX.Vertex


        appl = GetObject("", "TurboCAD.Application")
        drw = appl.ActiveDrawing
        grf = drw.Graphics.Add(, "TCW50Polyline")
        verts = grf.Vertices
        vx = verts.Add(0, 0, 0)
        vx = verts.Add(5, 0, 0)
        ' Add an arc "bulge" segment. First specify the arc's center, then a pass-through point.
        vx = verts.Add(5, 2.5, 0)  'arc center
        ' vx.Bulge = True
        vx.Bulge = True
        vx = verts.Add(7.5, 2.5, 0)  'arc pass-through
        vx.Bulge = True
        vx = verts.Add(5, 5, 0)   'end of arc segment
        vx.Bulge = False
        verts.Add(0, 5, 0, False) 'hide this segment
        verts.AddClose(True)
        grf.Draw()

        grf = Nothing
        drw = Nothing
        appl = Nothing

    End Sub
« Last Edit: June 15, 2020, 01:02:14 PM by Andy H »

Logged


* June 15, 2020, 10:29:13 PM
#4
Thank You Andy I appreciate your effort.
I have been debating which language to learn.
I only know enough VBA to manipulate user forms in Excel.
I recently needed a small parametric object in an excel sheet. - for someone who doesn't have TC.
That was a bit of a fail because you cant do that easily in Excel so I switched to VB.net.
Created the sketch using Graphics in vb.net.
This is the next step in my learning process.



Logged
Nikki
TC20 platinum
TC 2015 platinum
TC 2017 with lightworks


* June 16, 2020, 11:39:45 AM
#5
Maybe you could try the AddArcTriplePoints method.
Marek

Logged
Marek

TC Pro 2016, TC Pro 2018, TC Plat 2019
Laptop Asus i7 6500U, dual-core 2,50GHz, NVIDIA GeForce GTX 950M, RAM 12 GB, SSD 480GB
Windows 10 64 bit


* June 17, 2020, 03:12:03 AM
#6
Thanks Marek.

Logged
Nikki
TC20 platinum
TC 2015 platinum
TC 2017 with lightworks


* June 17, 2020, 06:55:13 AM
#7
Marek do you join the arc to the poly line afterwards?

Logged
Nikki
TC20 platinum
TC 2015 platinum
TC 2017 with lightworks


* June 17, 2020, 07:23:45 AM
#8
Andy
I your method does work thank you.
Now I am trying to figure out how.
I am still trying to work out the difference between vertex and vertices I thought the one was the plural of the other.

Logged
Nikki
TC20 platinum
TC 2015 platinum
TC 2017 with lightworks


* June 17, 2020, 08:46:18 AM
#9
Marek do you join the arc to the poly line afterwards?
No, this is one method. The order of attached points and determining which sections will be invisible, are important. I don't know if I have determined the correct order of points.
Marek

Logged
Marek

TC Pro 2016, TC Pro 2018, TC Plat 2019
Laptop Asus i7 6500U, dual-core 2,50GHz, NVIDIA GeForce GTX 950M, RAM 12 GB, SSD 480GB
Windows 10 64 bit