马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
Getting the centroid of a closed polyline
ID 35353
Applies to: AutoCAD Map
AutoCAD Map
AutoCAD Map 2000
This document is part of Polyline Regions VBA AutoCAD MAP Technical Newsletter - January 2000 Map Automation
- [FONT=courier new]
- Question
- How do I get the centroid of a closed polyline in AutoCAD Map 5 without
- creating a topology?
- Answer
- You need to form a Region object from the polyline and then calculate the
- centroid of the region. The Visual Basic code example that follows shows how
- this is done.
- Sub GetCentroid()
- Dim Doc As AcadDocument
- Dim Entity As AcadEntity
- Dim Region As AcadRegion
- Dim Polylist(0 To 0) As AcadEntity
- Dim Entities As AcadModelSpace
- Dim nPoly As Integer 'number of polylines
- Dim i As Integer
- Set Doc = ThisDrawing
- Set Entities = Doc.ModelSpace
- Dim Centroid As Variant
- 'Form a region from each polyline
- For Each Entity In Entities
- If Entity.ObjectName = "AcDbPolyline" Then 'Polyline ?
- Set Polylist(0) = Entity
- Entities.AddRegion Polylist
- MsgBox Entity.ObjectName
- End If
-
- Next
- 'Find centroid of each region
- For i = 0 To Entities.Count - 1
- If Entities.Item(i).ObjectName = "AcDbRegion" Then 'Region ?
- Set Region = Entities.Item(i)
- Centroid = Region.Centroid
- MsgBox "Centroid X: " & Centroid(0) & vbCrLf & "Centroid Y: " & Centroid(1)
- End If
-
- Next
- End Sub
- [/FONT]
|