.NET
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Find nearest polyline with block
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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!
Re: Find nearest polyline with block
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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.D ocumentManager.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
Re: Find nearest polyline with block
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Tnx, I'm going to try it!
Re: Find nearest polyline with block
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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?
Re: Find nearest polyline with block
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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
Re: Find nearest polyline with block
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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
