Author Topic: Selection Set Filtering for XData  (Read 9523 times)

0 Members and 1 Guest are viewing this topic.

smcclure

  • Guest
Selection Set Filtering for XData
« on: January 16, 2007, 01:43:34 PM »
Hi,

I am trying to find all blocks on a given page with XData from a given application. I constructed a filter that filtered based on DXF codes "0" and "-3", but unfortunately, it is returning an the error response code. I was wondering if anyone can see any obvious mistakes. I am not sure if using the DXF code "-3" is part of the "conditional filtering bug" described on these lists, does anyone know?

Code: [Select]
        Dim appName As String = "MYAPPNAME"
        Dim filter As New SelectionFilter(New TypedValue() {New TypedValue(DxfCode.Start, "INSERT"), New TypedValue(DxfCode.XDataStart, appName)})
        Dim res As PromptSelectionResult = doc.Editor.SelectAll(filter)
        MsgBox("status:" & res.Status)

Chuck Gabriel

  • Guest
Re: Selection Set Filtering for XData
« Reply #1 on: January 16, 2007, 03:18:19 PM »
1001 is the group code for app name.

Nathan Taylor

  • Guest
Re: Selection Set Filtering for XData
« Reply #2 on: January 16, 2007, 04:17:53 PM »
1001 is the group code for app name.

Corresponding constant is dxfcode.ExtendedDataRegAppName.

smcclure

  • Guest
Re: Selection Set Filtering for XData
« Reply #3 on: January 16, 2007, 04:54:10 PM »
1001 is the group code for app name.

Are you allowed to filter by that group code? In ARX, we always used -3. I checked just to make sure, and the old reference manuals all claim that a group code of -3 should be used to filter for extended entity data. If this is not the case, what has changed?

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8722
  • AKA Daniel
Re: Selection Set Filtering for XData
« Reply #4 on: January 16, 2007, 05:20:00 PM »
DxfCode.XDataStart = -3

Dan

DoH! you already had that

try New TypedValue(DxfCode.XDataStart) with no second parameter
« Last Edit: January 16, 2007, 05:39:00 PM by Danielm103 »

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8722
  • AKA Daniel
Re: Selection Set Filtering for XData
« Reply #5 on: January 16, 2007, 06:07:15 PM »
here is a sample in c#

edit: For Acad 2007

Code: [Select]
[CommandMethod("test")]
    static public void test()
    {
      TypedValue[] values = new TypedValue[]
                     {
                        new TypedValue((short)DxfCode.Start, "INSERT") ,
                        //the TypedValue can accept a null second parameter
                        new TypedValue((short)DxfCode.XDataStart) ,
                        new TypedValue((short)DxfCode.ExtendedDataRegAppName, "MYAPPNAME")
                     };
      SelectionFilter filter = new SelectionFilter(values);
      PromptSelectionOptions selopts = new PromptSelectionOptions();
      Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
      selopts.MessageForAdding = "Select";
      selopts.AllowDuplicates = false;
      PromptSelectionResult result = ed.GetSelection(selopts, filter);
      if (result.Status == PromptStatus.OK)
      {
        ObjectId[] idarray = result.Value.GetObjectIds();
        Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = Application.DocumentManager.MdiActiveDocument.Database.TransactionManager;
        Transaction tr = tm.StartTransaction();
        try
        {
          foreach (ObjectId id1 in idarray)
          {
            Entity entity1 = (Entity)tm.GetObject(id1, OpenMode.ForRead, true);
            ed.WriteMessage("\nYou selected: " + entity1.GetType().FullName);
          }
        }
        finally
        {
          tr.Dispose();
        }
      }
    }
« Last Edit: January 16, 2007, 06:46:46 PM by Danielm103 »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Selection Set Filtering for XData
« Reply #6 on: January 16, 2007, 08:26:09 PM »
Great demo code Daniel !
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Chuck Gabriel

  • Guest
Re: Selection Set Filtering for XData
« Reply #7 on: January 17, 2007, 08:37:35 AM »
1001 is the group code for app name.

Are you allowed to filter by that group code? In ARX, we always used -3. I checked just to make sure, and the old reference manuals all claim that a group code of -3 should be used to filter for extended entity data. If this is not the case, what has changed?

I have always used group code 1001 for regapp name when filtering selection sets in VB(A).  I've never actually had occasion to try the equivalent in ObjectARX.

According to the DXF Reference:

-3 = APP: extended data (XDATA) sentinel (fixed)
1001 = Registered application name (ASCII string up to 31 bytes long) for extended data

smcclure

  • Guest
Re: Selection Set Filtering for XData
« Reply #8 on: January 17, 2007, 10:18:20 AM »
For those unfortunate enough to have to code in VB .NET (my fate!), I have translated Daniel's clean C# code in to good ol' crummy VB:

Code: [Select]
    <Autodesk.AutoCAD.Runtime.CommandMethod("test")> _
    Public Sub test()
        Dim values As TypedValue() = New TypedValue() { _
                        New TypedValue(CType(DxfCode.Start, Short), "INSERT"), _
                        New TypedValue(CType(DxfCode.XDataStart, Short)), _
                        New TypedValue(CType(DxfCode.ExtendedDataRegAppName, Short), "MYAPPNAME") _
                     }
        Dim filter As SelectionFilter = New SelectionFilter(values)
        Dim selopts As PromptSelectionOptions = New PromptSelectionOptions()
        Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
        selopts.MessageForAdding = "Select"
        selopts.AllowDuplicates = False
        Dim result As PromptSelectionResult = ed.GetSelection(selopts, filter)
        If (result.Status = PromptStatus.OK) Then
            Dim idarray As ObjectId() = result.Value.GetObjectIds()
            Dim tm As Autodesk.AutoCAD.DatabaseServices.TransactionManager = Application.DocumentManager.MdiActiveDocument.Database.TransactionManager
            Dim tr As Transaction = tm.StartTransaction()
            Try
                For Each id1 As ObjectId In idarray
                    Dim entity1 As Entity = CType(tm.GetObject(id1, OpenMode.ForRead, True), Entity)
                    ed.WriteMessage("\nYou selected: " + entity1.GetType().FullName)
                Next
            Finally
                tr.Dispose()
            End Try
        End If
    End Sub