.NET

Reply
Contributor
CodeBug
Posts: 18
Registered: ‎07-17-2012
Message 1 of 4 (556 Views)
Accepted Solution

Does not contain a public definition for 'GetEnumerator'

556 Views, 3 Replies
08-01-2012 05:30 AM

Hi all,

 

While I tried to start a loop on a selection set object as below,

 

foreach (AcadObject SelDrawingObject1 in GenSelSSetObj)

 

I get an error as below,

 

foreach statement cannot operate on variables of type 'Autodesk.AutoCAD.Interop.Common.AcadObject' because 'Autodesk.AutoCAD.Interop.Common.AcadObject' does not contain a public definition for 'GetEnumerator' 

 

Please  help me with changes required to fix this.

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 2 of 4 (552 Views)

Re: Does not contain a public definition for 'GetEnumerator'

08-01-2012 05:41 AM in reply to: CodeBug

Try use AcadEntity instead ,in example, this one is from my oldies

 

  <CommandMethod("DISC", CommandFlags.Modal Or CommandFlags.Session)> _
    Public Sub InteropDemo()

        Dim miss As Object = Type.Missing

        Dim AcadApp As AcadApplication = New Autodesk.AutoCAD.Interop.AcadApplication()

        AcadApp.Visible = True

        AcadApp.WindowState = AcWindowState.acMax

        Dim adoc As AcadDocument = AcadApp.Documents.Open("c:\test\WorkingDrawing.dwg")

        adoc.Application.ZoomExtents()

        Dim util As AcadUtility = adoc.Utility

        Dim oSset As AcadSelectionSet = adoc.SelectionSets.Add("mySset")
        '  get current tab name
        Dim layout As Object = adoc.GetVariable("ctab")
        '  using filter
        '  important: use short[] for dxf codes:
        Dim dxfcode As Short() = New Short() {0, 66, 410}
        '  use object[] for dxf values:
        Dim dxfvalue As Object() = New Object() {"insert", 1, layout}
        '  select all attributed block instances in the current tab
        oSset.Select(AcSelect.acSelectionSetAll, miss, miss, DirectCast(dxfcode, Object), DirectCast(dxfvalue, Object))
        '  send  message to the command line:
        adoc.Utility.Prompt(String.Format(vbLf & "Selected: {0} objects", oSset.Count))

        For Each ent As AcadEntity In oSset
            '  important: cast if AcadEntity is AcadBlockReference
            Dim oblkRef As AcadBlockReference = TryCast(ent, AcadBlockReference)

            If oblkRef IsNot Nothing Then
                '  send  message to the command line:
                util.Prompt(String.Format(vbLf & "Block Name:" & vbTab & "{0}", oblkRef.Name))

                Dim attVar As Object = oblkRef.GetAttributes()
                '  important: cast if object is array
                If attVar.GetType().IsArray Then

                    Dim attColl As Object() = TryCast(DirectCast(attVar, Object()), Object())

                    If attColl IsNot Nothing Then

                        For i As Integer = attColl.GetLowerBound(0) To attColl.GetUpperBound(0)
                            '  important: cast if object is AcadAttributeReference
                            Dim attRef As AcadAttributeReference = TryCast(attColl(i), AcadAttributeReference)

                            If attRef IsNot Nothing Then
                                '  send  message to the command line:
                                util.Prompt(String.Format(vbLf & "Tag:   {0}" & vbTab & "Value:   {1}", attRef.TagString, attRef.TextString))

                            End If
                        Next
                    End If
                End If
            End If
        Next

    End Sub

 

Change file name etc to your needs

 

~'J'~

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Contributor
CodeBug
Posts: 18
Registered: ‎07-17-2012
Message 3 of 4 (524 Views)

Re: Does not contain a public definition for 'GetEnumerator'

08-02-2012 11:57 PM in reply to: Hallex

Hallex,

 

Thanks for you code.

 

I changed the type from AcadObject to AcadEntity below and also GenSelSSetOb type to AcadSelectionSet

 

foreach(AcadEntity SelDrawingObject1 in GenSelSSetObj)

 

Fixed!

 

 

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 4 of 4 (520 Views)

Re: Does not contain a public definition for 'GetEnumerator'

08-03-2012 01:27 AM in reply to: CodeBug

Good for you

Glad I could help

Cheers :smileyhappy:

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community