.NET

Reply
Contributor
Posts: 17
Registered: ‎08-14-2007
Message 1 of 3 (206 Views)

Create Selection set and get insert point of multiple blocks

206 Views, 2 Replies
07-03-2012 07:46 AM

I am very new to VB.NET and I am need some help.

 

What I am trying to do is create a selection set of blocks with the same name. Then step throught the selection set and if the block has an attribute "Tag" with a Specific "Value" then get the insert point.

 

Is there a good tutorial or example that someone could point me to?


Thanks

Valued Mentor
Posts: 376
Registered: ‎04-11-2010
Message 2 of 3 (193 Views)

Re: Create Selection set and get insert point of multiple blocks

07-03-2012 09:54 AM in reply to: AaronLucy

Hi,

 

this is a very crude example of a function to get a list of insertion points from a selection set (crossing):

Public Function getBlockInsPoints(ByVal tag As String) As List(Of Point3d)
        Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
        Dim db As Database = doc.Database

        Dim ipoints As New List(Of Point3d)

        Dim p1, p2 As Point3d

        Using acTrans As Transaction = db.TransactionManager.StartTransaction()
            Dim acTypValAr(1) As TypedValue
            Dim blkref As BlockReference

            acTypValAr.SetValue(New TypedValue(DxfCode.Start, "INSERT"), 0)
            acTypValAr.SetValue(New TypedValue(DxfCode.AttributeTag, tag), 1)

            Dim acSelFtr As SelectionFilter = New SelectionFilter(acTypValAr)
            Dim acSSPrompt As PromptPointResult = doc.Editor.GetPoint("Select First Point:")

            If acSSPrompt.Status = PromptStatus.OK Then
                p1 = acSSPrompt.Value
                acSSPrompt = doc.Editor.GetCorner("Select Second Point: ", p1)
                If acSSPrompt.Status = PromptStatus.OK Then
                    p2 = acSSPrompt.Value
                    Dim wssprompt As PromptSelectionResult

                    wssprompt = ed.SelectCrossingWindow(p1, p2, acSelFtr)
                    If wssprompt.Status = PromptStatus.OK Then
                        Dim wss As SelectionSet = wssprompt.Value
                        For Each acSSObj As SelectedObject In wss
                            If Not IsDBNull(acSSObj) Then
                                blkref = acSSObj.ObjectId.GetObject(OpenMode.ForRead)
                                ipoints.Add(blkref.Position)
                            End If
                        Next
                    End If
                End If
            End If
            acTrans.Commit()
        End Using
        Return ipoints
    End Function

Put the function in a command, ask for the tag name and pass it to the function, or hardcode the tag name in the function call.

 

Gaston Nunez

Contributor
Posts: 17
Registered: ‎08-14-2007
Message 3 of 3 (190 Views)

Re: Create Selection set and get insert point of multiple blocks

07-03-2012 10:03 AM in reply to: gasty1001

Thanks for the help. I will look over the code and see if I can get it to work for me.

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
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

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

Ask the Community