'nother newbie question: area parameter

'nother newbie question: area parameter

Anonymous
Not applicable
277 Views
3 Replies
Message 1 of 4

'nother newbie question: area parameter

Anonymous
Not applicable
I'm using ACAD2008, Visual Studio Express 08 and am just starting out with this whole vb.net thing.

I "borrowed" some code Fatty posted here
http://discussion.autodesk.com/thread.jspa?messageID=5804172

and was wondering how to do a similar thing with LWpolyline area. I don't see a GetAreaatparameter.

Could somone point me in the right direction?

Thanks!!
0 Likes
278 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
I don't know why Fatty wasn't using the Length property. There is also an area property.
0 Likes
Message 3 of 4

Anonymous
Not applicable
Thanks, Nathan
I don't remember why, perhaps it was written for
older version

~'J'~
0 Likes
Message 4 of 4

Anonymous
Not applicable
Try these functions instead:

'//
Public Shared Function TotalLength() As Double
Dim totlen As Double = 0

Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor

Dim dxf() As TypedValue = {New TypedValue(DxfCode.Start, "LWPOLYLINE")}
Dim filt As New SelectionFilter(dxf)

Dim opts As PromptSelectionOptions = New PromptSelectionOptions
opts.MessageForAdding = "Select polylines to calculate the total length:"
opts.AllowDuplicates = False 'by suit
opts.SingleOnly = False

Dim res As PromptSelectionResult = ed.GetSelection(opts, filt)
If res.Status PromptStatus.OK Then
Return 0
End If

Dim db As Database = HostApplicationServices.WorkingDatabase
Using tr As Transaction = db.TransactionManager.StartTransaction()

Dim sset As SelectionSet = res.Value
Dim IDs() As ObjectId = sset.GetObjectIds
Dim n As Integer = 0
For Each Id As ObjectId In IDs
Dim ent As Entity = tr.GetObject(IDs(n), OpenMode.ForRead)
Dim pl As Polyline = tr.GetObject(ent.ObjectId, OpenMode.ForRead)
Dim ln As Double = pl.Length
totlen = totlen + ln
n += 1
Next

MessageBox.Show(String.Format("Total length = {0}", totlen)) ' for debug only

tr.Dispose()
End Using

Return totlen

End Function

'//
'//
'//
Public Shared Function TotalArea() As Double
Dim totar As Double = 0

Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor

Dim dxf() As TypedValue = {New TypedValue(DxfCode.Start, "LWPOLYLINE")}
Dim filt As New SelectionFilter(dxf)

Dim opts As PromptSelectionOptions = New PromptSelectionOptions
opts.MessageForAdding = "Select polylines to calculate the total length:"
opts.AllowDuplicates = False 'by suit
opts.SingleOnly = False

Dim res As PromptSelectionResult = ed.GetSelection(opts, filt)
If res.Status PromptStatus.OK Then
Return 0
End If

Dim db As Database = HostApplicationServices.WorkingDatabase
Using tr As Transaction = db.TransactionManager.StartTransaction()

Dim sset As SelectionSet = res.Value
Dim IDs() As ObjectId = sset.GetObjectIds
Dim n As Integer = 0
For Each Id As ObjectId In IDs
Dim ent As Entity = tr.GetObject(IDs(n), OpenMode.ForRead)
Dim pl As Polyline = tr.GetObject(ent.ObjectId, OpenMode.ForRead)
Dim ar As Double = pl.Area
totar = totar + ar
n += 1
Next

MessageBox.Show(String.Format("Total area = {0}", totar)) ' for debug only

tr.Dispose()
End Using

Return totar

End Function
'//

~'J'~
0 Likes