.NET

Reply
Mentor
truss_85
Posts: 173
Registered: ‎02-13-2011
Message 1 of 3 (185 Views)
Accepted Solution

Can not operate items in selection set

185 Views, 2 Replies
02-26-2012 07:19 AM

Hi Everyone,

I have a public sub it works fine with selectionsets.

But when I want to use in a fence selection set it did not work.

I get message "number of selected object:" truly but it did not set att values.

I post the code below. What am I missing?

 

Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.Runtime

Public Class Class1
    <CommandMethod("hs")> _
    Public Sub gget()

        Dim acDocEd As Editor = Application.DocumentManager.MdiActiveDocument.Editor
        Dim entOpt As PromptEntityOptions = New PromptEntityOptions("Pick a polyline:")
        entOpt.AllowNone = True
        Dim spoly As PromptEntityResult = acDocEd.GetEntity(entOpt)
        Dim acCurDb As Database = Application.DocumentManager.MdiActiveDocument.Database
        If spoly.Status = PromptStatus.None Then
            acDocEd.WriteMessage("Selection invalid!...")
        End If

        Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
            Dim obj As DBObject = acTrans.GetObject(spoly.ObjectId, OpenMode.ForWrite)

            If TypeOf (obj) Is Polyline Then
                Dim poly As Polyline = CType(obj, Polyline)
                Dim opt As New Point3d
                Dim sel_fence As New Autodesk.AutoCAD.Geometry.Point3dCollection
                For ii = 0 To poly.NumberOfVertices - 1
                    opt = poly.GetPoint3dAt(ii)
                    sel_fence.Add(opt)
                Next

                Dim acTypValAr(0) As TypedValue
                acTypValAr.SetValue(New TypedValue(DxfCode.Start, "INSERT"), 0)
                Dim acSelFtr As SelectionFilter = New SelectionFilter(acTypValAr)
                Dim prselres As PromptSelectionResult = acDocEd.SelectFence(sel_fence, acSelFtr)

                If prselres.Status = PromptStatus.OK Then
                    Dim acSSet As SelectionSet = prselres.Value
                    Dim nn As Integer = 0
                    For Each acSSObj As SelectedObject In acSSet
                        SetAttribute(acSSObj.ObjectId, "BLOCKNAME", "ATTNAME", nn.ToString)
                        nn = nn + 1
                    Next
                    acDocEd.WriteMessage("Number of objects selected: " & acSSet.Count.ToString())
                End If
            End If
        End Using
    End Sub

    Public Sub SetAttribute(ByVal BlockID As Autodesk.AutoCAD.DatabaseServices.ObjectId, ByVal blckname As String, ByVal AttTag As String, ByVal AttVal As String)
        Dim MyDb As Database = Application.DocumentManager.MdiActiveDocument.Database
        If BlockID.IsNull Then Exit Sub
        Try
            Using myTrans As Transaction = MyDb.TransactionManager.StartTransaction
                Dim myBlckRef As BlockReference
                Dim myAttColl As AttributeCollection
                Dim myBlckTable As BlockTableRecord
                myBlckRef = BlockID.GetObject(OpenMode.ForWrite)
                If myBlckRef.IsDynamicBlock Then
                    myBlckTable = myTrans.GetObject(myBlckRef.DynamicBlockTableRecord, OpenMode.ForRead)
                Else
                    myBlckTable = myTrans.GetObject(myBlckRef.BlockTableRecord, OpenMode.ForRead)
                End If

                If String.Compare(myBlckTable.Name, blckname, True) = 0 Then
                    myAttColl = myBlckRef.AttributeCollection
                    Dim myEnt As Autodesk.AutoCAD.DatabaseServices.ObjectId
                    Dim myAttRef As Autodesk.AutoCAD.DatabaseServices.AttributeReference
                    For Each myEnt In myAttColl
                        myAttRef = myEnt.GetObject(OpenMode.ForWrite)
                        If String.Compare(myAttRef.Tag, AttTag, True) = 0 Then
                            myAttRef.TextString = AttVal.ToString
                        End If
                    Next
                End If
                myTrans.Commit()
            End Using
        Catch ex As Exception
        End Try
    End Sub
End Class

 

*Expert Elite*
Alfred.NESWADBA
Posts: 8,867
Registered: ‎06-29-2007
Message 2 of 3 (181 Views)

Re: Can not operate items in selection set

02-26-2012 07:22 AM in reply to: truss_85

Hi,

 

you are working with nested transactions, that is a little bit more critical and you have to be careful commiting a sub-transaction, but not commiting the top-transaction.

As a first try do also a commit of the transaction in your primary sub "ssget"

 

HTH, - alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Mentor
truss_85
Posts: 173
Registered: ‎02-13-2011
Message 3 of 3 (176 Views)

Re: Can not operate items in selection set

02-26-2012 07:41 AM in reply to: Alfred.NESWADBA

Thanks,

How embarrassing it is!...

I did not see that thank you very musch again...

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