ConstantWidth Example

Using Programming Languages other than VBA

Sub Example_ConstantWidth()
	 ' This example creates a lightweight polyline in model space and
	 ' uses the ConstantWidth property to determine if the polyline comprises
	 ' equal width segments.  If the segments are not equal,
	 ' use the ConstantWidth property to set all the segments to the same
	 ' width.

	Dim plineObj As AcadLWPolyline
	Dim points(0 To 9) As Double
	Dim msg As String, CWidth As Double

	' Define the 2D polyline points
	points(0) = 1: points(1) = 1
	points(2) = 1: points(3) = 2
	points(4) = 2: points(5) = 2
	points(6) = 3: points(7) = 2
	points(8) = 4: points(9) = 4
	
	' Create a lightweight Polyline object in model space
	'
	' * Note: Return the new PolyLine object into a Module
	' level variable, which allows events associated
	' with that particular object to be intercepted.
	Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)
	ThisDrawing.Application.ZoomAll

	' Display segment information before altering the width of segment 1
	GoSub DISPLAYSEGMENTS

	' Set the first segment width
	plineObj.SetWidth 1, 0.1, 0.3
	ThisDrawing.Regen acAllViewports

	' Display segment information after altering the width of segment 1
	GoSub DISPLAYSEGMENTS

	' Make all segments uniform in width
	plineObj.ConstantWidth = 0.1
	ThisDrawing.Regen acAllViewports

	' Display segment information after making the segments uniform
	GoSub DISPLAYSEGMENTS

	Exit Sub

DISPLAYSEGMENTS:
	On Error Resume Next

	' Check to see if the segment widths are uniform
	CWidth = plineObj.ConstantWidth

	' If ConstantWidth returns an error, the
	' segments are not all the same width
	If Err.Description = "Invalid input" Then
		msg = " are not equal."
	Else
		msg = " are all equal."
	End If
	On Error GoTo 0

	MsgBox "The segments of the new polyline" & msg

	Return
End Sub





   Comments?