Author Topic: ZWCAD Selection Set Error  (Read 2434 times)

0 Members and 1 Guest are viewing this topic.

neyton

  • Newt
  • Posts: 68
ZWCAD Selection Set Error
« on: November 09, 2015, 01:05:30 PM »

I have a problem with selection set in ZWCAD 2015.

It always returns status error when making:
Code: [Select]
<CommandMethod("teste")>
    Public Sub teste()
        For i = 0 To 100
            Dim ss = ED.SelectAll(New SelectionFilter({New TypedValue(DxfCode.Start, "LWPOLYLINE"),
                                                    New TypedValue(DxfCode.LayerName, "quadra")}))
            If ss.Status <> PromptStatus.OK Then
                MsgBox(ss.Status.ToString & vbNewLine & "i=" & i)
                Exit Sub
            End If
        Next

    End Sub

In autocad or gstarcad, runs without error (no message box). Why?
Visit my website: http://tbn2.blogspot.com

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: ZWCAD Selection Set Error
« Reply #1 on: November 09, 2015, 06:59:06 PM »
Do you need to AND them together?  Also, your messagebox will only show if there is an error.  As long as there is no error the subroutine will finish without printing anything out.  You probably need to change the <> to a =. 

Code - Visual Basic: [Select]
  1. <CommandMethod("teste")>    
  2. Public Sub teste()        
  3.     For i = 0 To 100            
  4.         Dim ss = ED.SelectAll(New SelectionFilter({New TypedValue(DxfCode.Operator, "<and",
  5.                                                    New TypedValue(DxfCode.Start, "LWPOLYLINE"),
  6.                                                    New TypedValue(DxfCode.LayerName, "quadra"
  7.                                                    New TypedValue(DxfCode.Operator, "and>" )}))            
  8.         If ss.Status <> PromptStatus.OK Then
  9.             MsgBox(ss.Status.ToString & vbNewLine & "i=" & i)                
  10.             Exit Sub
  11.         End If
  12.     Next
  13. End Sub
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

neyton

  • Newt
  • Posts: 68
Re: ZWCAD Selection Set Error
« Reply #2 on: November 10, 2015, 07:12:13 AM »
Hi, I made this changes, and the error persist

Calls "teste" command three times:

In first run, it is OK

In second run, show message box with a value greater than 0

In third, show message box with 0



Visit my website: http://tbn2.blogspot.com

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: ZWCAD Selection Set Error
« Reply #3 on: November 10, 2015, 07:30:59 AM »
Why are you selection filtering inside of a loop?  The results are the same for every iteration of the loop. You can loop from now to infinity the results will always be the same as the first iteration.

What's the error?

What line is it crashing on?
« Last Edit: November 10, 2015, 07:35:35 AM by MexicanCustard »
Revit 2019, AMEP 2019 64bit Win 10

neyton

  • Newt
  • Posts: 68
Re: ZWCAD Selection Set Error
« Reply #4 on: November 10, 2015, 09:58:17 AM »
This code only serves to show the problem.

When running it three times in a row, should finish running without showing any message, assuming that there are polylines in layer "quadra". Create some polylines and set  layer to "quadra" and test.

But to call the command "teste" for the second time, it shows a lower number to the number of objects that match the filter.

The third time you run the same command "teste", shows a message with "i=0". This means that, although there polylines in layer "quadra", the "SelectAll" fails.

I have a program that runs several times the "SelectAll" and the program does not run correctly because "SelectAll" does not work after the first call

Visit my website: http://tbn2.blogspot.com

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: ZWCAD Selection Set Error
« Reply #5 on: November 12, 2015, 07:43:01 AM »
I don't have ZWCAD to test this so I'll have to take you word for it. You've likely have found a bug that the ZWCAD development team should look into.  Maybe you should be showing these results to them.

I don't see them jumping right on fixing it though.  As long as it always works for the first iteration the bug should never be an issue for developers.  I can't see any situation where the code you've posted would ever be used in production.
Revit 2019, AMEP 2019 64bit Win 10

neyton

  • Newt
  • Posts: 68
Re: ZWCAD Selection Set Error
« Reply #6 on: November 12, 2015, 12:25:46 PM »
Hi,

It is working now:
Code: [Select]
<CommandMethod("teste")>
    Public Sub teste()
        Dim doc = ApplicationServices.Application.DocumentManager.MdiActiveDocument
        Dim ed = doc.Editor

        For i = 0 To 100
            Dim ss = ED.SelectAll(New SelectionFilter({New TypedValue(DxfCode.Operator, "<AND"),
                                                       New TypedValue(DxfCode.Start, "LWPOLYLINE"),
                                                       New TypedValue(DxfCode.LayerName, CadMemoOptions.LayerQuadra),
                                                       New TypedValue(DxfCode.Operator, "AND>")}))
            If ss.Status <> PromptStatus.OK Then
                MsgBox(ss.Status.ToString & vbNewLine & "i=" & i)
                Exit Sub
            End If
     
           ss.Value.Dispose() 'added this to ZWCAD works

        Next
    End Sub

ZWCAD can only have 255 selection sets at the same time, so when a selection set is no longer needed, developers should call its Dispose() method to free this selection set
Visit my website: http://tbn2.blogspot.com

Jeff H

  • Needs a day job
  • Posts: 6150
Re: ZWCAD Selection Set Error
« Reply #7 on: November 19, 2015, 05:43:12 PM »

Keith Brown

  • Swamp Rat
  • Posts: 601
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013