Author Topic: Selection Ordinate Dimensions with Filter (dxf code)  (Read 1575 times)

0 Members and 1 Guest are viewing this topic.

Offline madmat

  • Newbie
  • *
  • Posts: 5
  • Karma: +0/-0
  • Gender: Male
    • prefered language: VB
    • Prog expertise: Good
    • View Profile
Selection Ordinate Dimensions with Filter (dxf code)
« on: February 01, 2013, 11:15:43 PM »
Hello,

I need your help... (my problem is on the 3rd "MyParam.Setvalue" line)
I try to make a SelectionSet with Filter, in order to have only Ordinate Dimensions in my SelectionSet.
I've done following, but the "100" dxfCode doesn't seem to work (but the 2 other do).

-----------------
Dim MyParam(2) As TypedValue
MyParam.SetValue(New TypedValue(0, "Dimension"), 0)
MyParam.SetValue(New TypedValue(DxfCode.DimStyleName, "ISO-25"), 1)
MyParam.SetValue(New TypedValue(100, "AcDbOrdinateDimension"), 2)  '<-This one doesn't seem to work...

Dim MyFilter As SelectionFilter = New SelectionFilter(MyParam)

Dim PSR As PromptSelectionResult = myEd.GetSelection(MyFilter)
-----------------


I've tried to write "DxfCode.Subclass" instead of "100" but the result was the same.
When I type "(entget(car(entsel)))" in Autocad, I find "AcDbOrdinateDimension" for the 100 dxfCode.
Does anybody know what to do?
Is there maybe another way to filter this selection?

Offline (gile)

  • C#
  • *
  • Posts: 87
  • Karma: +8/-0
  • Gender: Male
    • prefered language: F
    • Prog expertise: Good
    • View Profile
Re: Selection Ordinate Dimensions with Filter (dxf code)
« Reply #1 on: February 02, 2013, 02:27:08 PM »
Hi,

Look at the 70 dxf group.

Code: [Select]
TypedValue[] tvs = {
    new TypedValue(0, "dimension"),
    new TypedValue(3, "ISO-25"),
    new TypedValue(-4, "&="),
    new TypedValue(70, 6)};

SelectionFilter filter = new SelectioFilter(tvs);

PromptSelectionResult psr = ed.GetSelection(filter);

Offline (gile)

  • C#
  • *
  • Posts: 87
  • Karma: +8/-0
  • Gender: Male
    • prefered language: F
    • Prog expertise: Good
    • View Profile
Re: Selection Ordinate Dimensions with Filter (dxf code)
« Reply #2 on: February 02, 2013, 03:36:48 PM »
The upper method isn't very strict, even it will work fine with ordinate dimensions because it uses a bitwise test on values wich aren't binary codes: it will work with 6, 5 (3 points angular dimensions), 3 (diameter dimension) but not with 4, 2, 1 or 0.

Another way, better in my opinion, is to combinate a classical selection filter and a Editor.SelectionAdded event handler to filter the selected objects.

C#
Code: [Select]
        [CommandMethod("Test")]
        public void test()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

            TypedValue[] filter = { new TypedValue(0, "dimension"), new TypedValue(3, "ISO-25") };

            ed.SelectionAdded += ed_SelectionAdded;
            PromptSelectionResult psr = ed.GetSelection(new SelectionFilter(filter));
            ed.SelectionAdded -= ed_SelectionAdded;
            if (psr.Status != PromptStatus.OK) return;
            ed.SetImpliedSelection(psr.Value);
        }

        void ed_SelectionAdded(object sender, SelectionAddedEventArgs e)
        {
            for (int i = 0; i < e.AddedObjects.Count; i++)
            {
                if (e.AddedObjects[i].ObjectId.ObjectClass.Name != "AcDbOrdinateDimension")
                    e.Remove(i);
            }
        }

VB
Code: [Select]
        <CommandMethod("Test")> _
        Public Sub test()
            Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor

            Dim filter As TypedValue() = { New TypedValue(0, "dimension"), new TypedValue(3, "ISO-25") }

            AddHandler ed.SelectionAdded, AddressOf ed_SelectionAdded
            Dim psr As PromptSelectionResult = ed.GetSelection(New SelectionFilter(filter))
            RemoveHandler ed.SelectionAdded, AddressOf ed_SelectionAdded
            If psr.Status <> PromptStatus.OK Then
                Return
            End If
            ed.SetImpliedSelection(psr.Value)
        End Sub

        Private Sub ed_SelectionAdded(sender As Object, e As SelectionAddedEventArgs)
            For i As Integer = 0 To e.AddedObjects.Count - 1
                If e.AddedObjects(i).ObjectId.ObjectClass.Name <> "AcDbOrdinateDimension" Then
                    e.Remove(i)
                End If
            Next
        End Sub

Offline madmat

  • Newbie
  • *
  • Posts: 5
  • Karma: +0/-0
  • Gender: Male
    • prefered language: VB
    • Prog expertise: Good
    • View Profile
Re: Selection Ordinate Dimensions with Filter (dxf code)
« Reply #3 on: February 03, 2013, 12:13:07 PM »
Thanx Gile for your answers, I've tried your last solution and it's working fine.