Sub PolyLength
'--------------------------------------------------------------------------
' 折れ線の全長を算出するマクロ　by　森を走ろう！	2019-1-28
'
'	・全長を求めたい折れ線には'path'で始まる名前を付けておくこと
'		始点から終点までと、閉ループ化した時の全長がミリ単位で算出される
'--------------------------------------------------------------------------
'
Dim Doc As Object
Dim Page As Object
Dim PolyPolygonShape As Object
Dim PolyPolygon As Variant
Dim Coordinates(2) As New com.sun.star.awt.Point
 
Doc = ThisComponent
Page = Doc.drawPages(0)
 
 For I = 0 To Page.getCount()-1
   oElement = Page.getByIndex(I)

   If Left(oElement.Name, 4) = "path" Then
     oFound = oElement
	 If (NOT IsNull(oFound)) And ((oFound.getShapeTYpe()="com.sun.star.drawing.PolyPolygonShape") Or (oFound.getShapeTYpe()="com.sun.star.drawing.PolyLineShape")) Then
		PCoord = oFound.PolyPolygon(0)
		PLengthC = 0

		For J = 0 to UBound(PCoord)
	    	If (J=UBound(PCoord)) Then
				K = 0
			Else
				K = K+1
			End If
			PLengthC = PLengthC + ((PCoord(K).x - PCoord(J).x)^2 + (PCoord(K).y - PCoord(J).y)^2)^0.5
	    	If (J=UBound(PCoord)-1) Then
				PLengthO = PLengthC
			End If
		Next J

		MsgBox  "Name : " & oElement.Name & " / Length : " & Int(PLengthC/100) & "(close), " & Int(PLengthO/100) & "(open)"

 	 End If

   End If

 Next I

End Sub
