.NET

Reply
Member
wouter
Posts: 5
Registered: ‎03-22-2011
Message 1 of 6 (482 Views)

Find nearest polyline with block

482 Views, 5 Replies
11-07-2012 08:24 AM

Hi,

 

I'm using VB.NET to write a routine that autmatically calculates the area of the polyline nearest to a block (the pline surrounds the block) an then adds the area to the blocks attribute.

I managed to write the program to do this manually for a selected pline and block.

 

How can I automatically select a pline nearest to the selected blocks' insertion point?

 

Help is much appreciated..

 

thanks in advance!

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

Re: Find nearest polyline with block

11-07-2012 09:56 AM in reply to: wouter

You might be want instead to select block within the crossingpolygon method,

if you've added just one block within, see if this helps:

        <CommandMethod("TUR")> _
        Public Shared Sub testUpdateRooms()
            Dim blockname As String = "ROOM"
            ' chnage block name
            Dim tagname As String = "ROOMAREA"
            ' change tag
            Dim db As Database = HostApplicationServices.WorkingDatabase
            Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
            Dim ed As Editor = doc.Editor

            Dim filtpline As TypedValue() = New TypedValue(1) {New TypedValue(0, "lwpolyline"), New TypedValue(70, 1)}
            Dim pres As PromptSelectionResult = ed.SelectAll(New SelectionFilter(filtpline))
            If pres.Status <> PromptStatus.OK Then
                Return
            End If
            Dim filtblock As TypedValue() = New TypedValue(1) {New TypedValue(0, "insert"), New TypedValue(2, blockname)}
            Using tr As Transaction = doc.TransactionManager.StartTransaction()
                For Each sobj As SelectedObject In pres.Value
                    Dim ent As DBObject = tr.GetObject(sobj.ObjectId, OpenMode.ForRead, False)
                    Dim pline As Polyline = TryCast(ent, Polyline)
                    If pline Is Nothing Then
                        Return
                    End If
                    Dim pts As New Point3dCollection()
                    For n As Integer = 0 To pline.NumberOfVertices - 2
                        pts.Add(pline.GetPoint3dAt(n))
                    Next
                    Dim res As PromptSelectionResult = ed.SelectCrossingPolygon(pts, New SelectionFilter(filtblock))

                    If res.Status <> PromptStatus.OK Then
                        Continue For
                    End If

                    Dim sset As SelectionSet = res.Value
                    If sset.Count = 0 Then
                        Continue For
                    End If
                    ' if more than one block found, then make polyline to be cyan colored to select room with extrafluous blocks
                    If sset.Count > 1 Then
                        pline.UpgradeOpen()
                        pline.ColorIndex = 121
                    Else
                        Dim ids As ObjectId() = sset.GetObjectIds()
                        Dim blkobj As DBObject = tr.GetObject(ids(0), OpenMode.ForRead, False)
                        Dim bref As BlockReference = TryCast(blkobj, BlockReference)
                        If bref Is Nothing Then
                            Continue For
                        End If
                        Dim atts As AttributeCollection = bref.AttributeCollection
                        For Each id As ObjectId In atts
                            Dim attref As AttributeReference = DirectCast(tr.GetObject(id, OpenMode.ForRead, False), AttributeReference)
                            If attref.Tag = tagname Then
                                bref.UpgradeOpen()
                                attref.UpgradeOpen()
                                attref.TextString = Math.Round(pline.Area, 2).ToString() '' i.e. precision 2 decimals, or
                                ' possible to use a field with pline area as well
                                attref.DowngradeOpen()
                                bref.DowngradeOpen()
                            End If
                        Next
                    End If
                Next
                tr.Commit()
            End Using
        End Sub

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Member
wouter
Posts: 5
Registered: ‎03-22-2011
Message 3 of 6 (453 Views)

Re: Find nearest polyline with block

11-08-2012 12:07 AM in reply to: Hallex

Tnx, I'm going to try it!

Member
wouter
Posts: 5
Registered: ‎03-22-2011
Message 4 of 6 (448 Views)

Re: Find nearest polyline with block

11-08-2012 02:58 AM in reply to: wouter

It is a nice solution but it worked partly.

 

First, I changed SelectCrossingPolygon to SelectWindowPolygon because some blocks are bigger dan the room, so they overlap with another room.

 

Secondly Some plines contain arcs, so the the returned vertices not always create a polygone that is around the block.

 

 

Is there a way to also use of arcs in the pointselection to form the SelectWindowPolygon?

 

 



 

 

 

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

Re: Find nearest polyline with block

11-08-2012 06:04 AM in reply to: wouter

I think in this case you an to gather the points along the polyline route

with small steps between,then gather them all in the point3dcollection

to perform the  window selection

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Member
wouter
Posts: 5
Registered: ‎03-22-2011
Message 6 of 6 (390 Views)

Re: Find nearest polyline with block

11-23-2012 08:33 AM in reply to: Hallex

tnx for your help!

Do you think it's possible to make a selection for just the insertion point of the block?

 

The size of the attributes changes with the different text lengths.
That makes it difficult to select just one block, because the text overlaps more then one pline...

 

Thanks,

Wouter

 

 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!