[VBA]如何在VBA中画不同宽度的多线
请各位高手指点,如何在VBA中画不同宽度的多线,盼复,谢谢!reply
<P>帮助中的例子,SetWidth()方法:</P><P><BR>Sub Example_SetWidth()<BR> ' The following code prompts you to select a lightweight<BR> ' polyline, and then prompts you for the width to set each<BR> ' segment of the polyline.<BR> ' Pressing ENTER without specifying a width is equivalent to<BR> ' entering 0.<BR> <BR> Dim returnObj As AcadObject<BR> Dim basePnt As Variant<BR> Dim retCoord As Variant<BR> Dim StartWidth As Double<BR> Dim EndWidth As Double<BR> Dim i, j As Long<BR> Dim nbr_of_segments As Long<BR> Dim nbr_of_vertices As Long<BR> Dim segment As Long<BR> Dim promptStart As String<BR> Dim promptEnd As String<BR> <BR> On Error Resume Next<BR> <BR> ThisDrawing.Utility.GetEntity returnObj, basePnt, "Select a polyline"<BR> <BR> ' Make sure the user selected a polyline.<BR> If Err <> 0 Then<BR> If returnObj.EntityName <> "AcDbPolyline" Then<BR> MsgBox "You did not select a polyline"<BR> End If<BR> Exit Sub<BR> End If<BR> <BR> ' Obtain the coordinates of each vertex of the selected polyline.<BR> ' The coordinates are returned in an array of points.<BR> retCoord = returnObj.Coordinates<BR> <BR> segment = 0<BR> i = LBound(retCoord) ' Start index of coordinates array<BR> j = UBound(retCoord) ' End index of coordinates array<BR> nbr_of_vertices = ((j - i) \ 2) + 1 ' Number of vertices in the polyline<BR> <BR> ' Determine the number of segments in the polyline.<BR> ' A closed polyline has as many segments as it has vertices.<BR> ' An open polyline has one fewer segment than it has vertices.<BR> ' Check the Closed property to determine if the polyline is closed.<BR> <BR> If returnObj.Closed Then<BR> nbr_of_segments = nbr_of_vertices<BR> Else<BR> nbr_of_segments = nbr_of_vertices - 1<BR> End If<BR> <BR> ' Have user set the width for each segment of the polygon<BR> Do While nbr_of_segments > 0<BR> <BR> ' Get width values from the user<BR> promptStart = vbCrLf & "Specify the width at the beginning of the segment at " & retCoord(i) & "," & retCoord(i + 1) & " ==> "<BR> promptEnd = vbCrLf & "Now specify the width at the end of that segment ==> "<BR> <BR> StartWidth = ThisDrawing.Utility.GetReal(promptStart)<BR> EndWidth = ThisDrawing.Utility.GetReal(promptEnd)</P>
<P> ' Set the width of the current segment<BR> returnObj.SetWidth segment, StartWidth, EndWidth<BR> <BR> ' Prepare to obtain width of next segment, if any<BR> i = i + 2<BR> segment = segment + 1<BR> nbr_of_segments = nbr_of_segments - 1<BR> Loop<BR> <BR> MsgBox "Segment widths have been set", , "SetWidth Example"</P>
<P>End Sub</P>
页:
[1]