News:

Interested in some really terrific mobile apps? Visit www.turboapps.com for details.

Main Menu

vb.net selecting graphics within a rectangle

Started by nikkipollard, August 15, 2021, 06:19:45 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

nikkipollard

I know how to select graphics using 2  ActiveView.GetMouseClick and ActiveView.PickRect

I would like to be able to see the blue rectangle (dragoutline?) when selecting
I presume I would need to use this

Visual Basic (Declaration)
DragOutline(Coords As Variant, XScreen As double, YScreen As double, DragState As Variant)
Visual C++
HRESULT View::DragOutline(VARIANT* Coords, double XScreen, double YScreen, VARIANT* DragState);

Parameters
Coords
Type: VARIANT*
Array of (X, Y, Z) polygon coordinates.
XScreen
Type: double
X coordinate of point in screen coordinate system.
YScreen
Type: double
Y coordinate of point in screen coordinate system.
DragState (optional)
Type: VARIANT*
Begin, continue or end of drag operation

But I am not sure how and when
This is what I have tried - but I get an error
I think my problem is with the coordinate array.


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim xleft#, ytop#, xright#, ybottom#
        Dim Vi As IMSIGX.View
        Vi = TCDraw.ActiveView
        Dim pres As IMSIGX.PickResult
        Vi.GetMouseClick(xleft, ytop)
        Dim xscreen#, yscreen#
        Vi.ViewToScreen(xleft, ytop, xscreen, yscreen)
        Dim coords(2)
        coords(0) = xleft
        coords(1) = ytop
        coords(2) = 0
        Vi.DragOutline(coords, xscreen, yscreen)
        Vi.GetMouseClick(xright, ybottom)
        Vi.ViewToScreen(xright, ybottom, xscreen, yscreen)
        coords(0) = xright
        coords(1) = ybottom
        coords(2) = 0
        Vi.DragOutline(coords, xscreen, yscreen)
        pres = Vi.PickRect(xleft, ytop, xright, ybottom)
        Dim pent As IMSIGX.PickEntry
        For i = 0 To pres.Count - 1
            pent = pres.Item(i)
            pent.Graphic.Select()

        Next

    End Sub



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

TedTheCarpenter

I haven't  tried running your code in VS but it seems to me that the coords declaration should be Dim coords(2) As Double or Dim coords() As Double followed by Redim coords(2). VB Net does not have the Variant type.
Ted D

2017 Pro, 2018>2023 Platinum
Windows 11 Pro 22H2  64GB
Ryzen 9 5900X 12 core
Radeon RX 6600 XT 8GB

TedTheCarpenter

You'll will probably also need to change Dim xleft#, ytop#, xright#, ybottom# to  Dim xleft, ytop, xright, ybottom as Double. The # symbol works in VBA or VB6 but not in VB Net. When I have Option Strict on in Visual Studio it throws an error and when it's off the variable type is set to Nothing.


Ted D

2017 Pro, 2018>2023 Platinum
Windows 11 Pro 22H2  64GB
Ryzen 9 5900X 12 core
Radeon RX 6600 XT 8GB

nikkipollard

I will try the hash tag thing. - Although it works if I take out the drag line function. - Ie I do get a value for xscreen and yscreen
It is the Dragline Sub that has errors.

I have tried every combination I can think of for the array - So I probably have mixed the example here.
I don't even know if I am using the right Sub to get a box around my selection.
The reason I didn't declare the array as Double - Is because the Type in the Documentation is Variant
I will try that too
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

nikkipollard

#4
I tested your suggestions - Thankyou I am no longer getting an error.
- I am not getting a box either
So I am probably using the wrong Sub.

I guess I can live without the visual aid
At least I have a little more insight into the hash thing.

What is the advantage of having Option Strict on?
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

TedTheCarpenter

#5
Option Strict forces you to resolve any ambiguous code before you debug. The SDK documentation is quite old- Visual Basic declarations refer to VB6 and VBA. and not VB Net. The good news is that after you Dim vi as IMSIGX.View Visual Studio Intellisense will show you what it's looking for when you type vi.DragOutline(.  The SDK says that coords is an  Array of (X, Y, Z) polygon coordinates. You are sending DragOutline only one point. At the very least it needs both corners. It's possible that it needs all four corners that defines the polygon. You may also need to add vi.Refresh() to see the outline.
Ted D

2017 Pro, 2018>2023 Platinum
Windows 11 Pro 22H2  64GB
Ryzen 9 5900X 12 core
Radeon RX 6600 XT 8GB

Marek

Hi Nikki
What type of error are you getting. I ran your script in VB 2019 and I can select objects in TC by picking two corners of the rectangle, but there is no highlighting of this rectangle. I don't know if this is possible.You have to click mouse twice, selecting each corner separately, and the highlighting appears in the TC with continuous, dynamic corners indication. I left your markings, including #, unchanged.
Marek
Marek

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

TedTheCarpenter

#7
I tried your code and I had to change the variable# to Dim variable as Double to eliminate the error. I ran it using Net5.0- perhaps Marek was using an earlier version. DragOutline does need the coords Array to have all four corners to show the selection box but it's not dynamic and you don't see it until you select the second corner. You should comment out the first couple of lines- they refer to my Sub to get TC's Active Drawing.

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim OK As Boolean
        openTC(OK)
        Dim xleft, ytop, xright, ybottom As Double
        Dim xscreen, yscreen, xL, yT As Double
        Dim Vi As IMSIGX.View
        Dim pres As IMSIGX.PickResult
        Dim coords(11) As Double
        Vi = drw.ActiveView
        Vi.GetMouseClick(xleft, ytop)
        Vi.ViewToScreen(xleft, ytop, xL, yT)
        Vi.GetMouseClick(xright, ybottom)
        coords(0) = xleft
        coords(1) = ytop
        coords(2) = 0
        coords(3) = xright
        coords(4) = ytop
        coords(5) = 0
        coords(6) = xright
        coords(7) = ybottom
        coords(8) = 0
        coords(9) = xleft
        coords(10) = ybottom
        coords(11) = 0
        Vi.DragOutline(coords, xL, yT)
        pres = Vi.PickRect(xleft, ytop, xright, ybottom)
        Dim pent As IMSIGX.PickEntry
        For i = 0 To pres.Count - 1
            pent = pres.Item(i)
            pent.Graphic.Select()
        Next
        Vi.Refresh()
        End
    End Sub
Ted D

2017 Pro, 2018>2023 Platinum
Windows 11 Pro 22H2  64GB
Ryzen 9 5900X 12 core
Radeon RX 6600 XT 8GB

nikkipollard

#8
Thank You
I was only putting the first coordinate in
In my head I wanted the outline to appear as I was selecting - I guess not.
Any guesses at how the last argument works Begin , continue or end?

I am now getting a rectangle but it doesnt line up with my selection and it disappears really quickly
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

TedTheCarpenter

#9
I know that Begin is 0, Continue is 1, and End is 2. You can add 0 as the last argument to DragOutLine but it won't mean anything because you're not dragging anything. Adding 1 or 2 to the first instance of DragOutLine will throw an error. I don't know why your box is not aligned with the selections- it did line up when I ran it. It will disappear as soon as the selections are complete. You might be better off drawing a rectangle, waiting a short amount of time, and then deleting it. Here's a sub you can use for the timer:Private Sub wait(ByVal seconds As Integer)
        For i As Integer = 0 To seconds * 100
            System.Threading.Thread.Sleep(10)
            Application.DoEvents()
        Next
    End Sub
Ted D

2017 Pro, 2018>2023 Platinum
Windows 11 Pro 22H2  64GB
Ryzen 9 5900X 12 core
Radeon RX 6600 XT 8GB

nikkipollard

#10
Thanks I got it working

Drawing a rectangle rectangle would only show after the second point is picked. The same effect as this
I was hoping the behaviour would be the same as a rectangle selection in Turbocad.
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

TedTheCarpenter

To make your selection rectangle dynamic you probably need to add Dim TCevent As IMSIGX.IAppEvents and then use the TCevent.MouseMove event to continuously update your coords array when calling DragOutLine. Cancel the MouseMove event
when the second MouseClick happens. I'll play with the code when I have some free time and get back to you.
Ted D

2017 Pro, 2018>2023 Platinum
Windows 11 Pro 22H2  64GB
Ryzen 9 5900X 12 core
Radeon RX 6600 XT 8GB

nikkipollard

#12
Thanks Ted I do appreciate your help.
If you don't have time don't worry too much about it.
I think this method has been replaced with the drawing pick interactive method . - I just need to figure out how that works.
It seems to crash TC
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

nikkipollard

#13
Here is the code for the  Drawing PickInteractive method.
The - top level option is optional (true) but if you don't put it in it seems to crash TC

   Dim pres As IMSIGX.PickResult
        pres = TCDraw.PickInteractive(IMSIGX.ImsiPickType.imsiPickRect, True)
        Dim pent As IMSIGX.PickEntry
        For i = 0 To pres.Count - 1
            pent = pres.Item(i)
            pent.Graphic.Select()
        Next


only the pick point and pick rectangle seem to work
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

TedTheCarpenter

#14
You're right- PickPoly throws an error. I'm not sure why but PickInterative works fine on my computer without any of the optional arguments. It might be because I run Visual Studio and TC as administrator. Here's my version of the code: Dim PkR As IMSIGX.PickResult
        PkR = TCdrw.PickInteractive(1) '0=PickPoint  1=PickRectangle
        For n As Integer = 0 To PkR.Count - 1
            PkR.Item(n).Graphic.Select()
        Next
Edit: I just tried it not running as administrator and it still worked. There was one difference: The selection has no handle and bounding box when run as administrator.
Ted D

2017 Pro, 2018>2023 Platinum
Windows 11 Pro 22H2  64GB
Ryzen 9 5900X 12 core
Radeon RX 6600 XT 8GB

nikkipollard

Maybe it is just my version of Turbocad.
Other things - not SDK related keep crashing it too.
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

TedTheCarpenter

I'm running Platinum TC 2021.1 (Build 60.1). I followed Torfinn's advice by uninstalling TC and installing the ESD rather than just installing the patch. So far it has been remarkably stable. I'm using imsigx28.dll for the IMSIGX reference in Visual Studio 2019 (Net 5.0). You might want look for outdated chipset and graphic card drivers. I would also run MemTest to check your RAM. Computer issues are probably a longshot unless you're also having problems with your other programs.
Ted D

2017 Pro, 2018>2023 Platinum
Windows 11 Pro 22H2  64GB
Ryzen 9 5900X 12 core
Radeon RX 6600 XT 8GB