SetWidth メソッド(ActiveX)

セグメント インデックスを指定して、ポリラインの始点と終点の幅を設定します。

サポートされているプラットフォーム: Windows のみ

構文と要素

VBA:

object.SetWidth SegmentIndex, StartWidth, EndWidth
object

タイプ: LWPolylinePolyline

このメソッドが適用されるオブジェクト。

SegmentIndex

アクセス: 入力のみ

タイプ: 長整数型

幅を設定するセグメントを指定するインデックス。最初のセグメントは、インデックス 0。

StartWidth

アクセス: 入力のみ

タイプ: 倍精度浮動小数点数型

指定されたセグメントの始点の幅。

EndWidth

アクセス: 入力のみ

タイプ: 倍精度浮動小数点数型

指定されたセグメントの終点の幅。

戻り値(RetVal)

戻り値はありません。

注意

SegmentIndex は、ポリラインの特定セグメントのインデックスです。たとえば、3 つのセグメントを持つポリラインには、セグメント インデックス 0、1、および 2 があります。

Polyline: このメソッドはポリラインの Type プロパティが acCubicSplinePoly または acQuadSplinePoly の場合は失敗します。

VBA:

Sub Example_SetWidth()
    ' The following code prompts you to select a lightweight
    ' polyline, and then prompts you for the width to set each 
    ' segment of the polyline. 
    ' Pressing ENTER without specifying a width is equivalent to
    ' entering 0.

    AppActivate ThisDrawing.Application.Caption

    Dim returnObj As AcadObject
    Dim basePnt As Variant
    Dim retCoord As Variant
    Dim StartWidth As Double
    Dim EndWidth As Double
    Dim i, j As Long
    Dim nbr_of_segments As Long
    Dim nbr_of_vertices As Long
    Dim segment As Long
    Dim promptStart As String
    Dim promptEnd As String
              
    On Error Resume Next
   
    ThisDrawing.Utility.GetEntity returnObj, basePnt, "Select a polyline"
       
    ' Make sure the user selected a polyline.
    If Err <> 0 Then
        If returnObj.EntityName <> "AcDbPolyline" Then
            MsgBox "You did not select a polyline"
        End If
        Exit Sub
    End If
    
    ' Obtain the coordinates of each vertex of the selected polyline.
    ' The coordinates are returned in an array of points.
    retCoord = returnObj.Coordinates
    
    segment = 0
    i = LBound(retCoord)                 ' Start index of coordinates array
    j = UBound(retCoord)                 ' End index of coordinates array
    nbr_of_vertices = ((j - i) \ 2) + 1  ' Number of vertices in the polyline
    
    ' Determine the number of segments in the polyline.
    ' A closed polyline has as many segments as it has vertices.
    ' An open polyline has one fewer segment than it has vertices.
    ' Check the Closed property to determine if the polyline is closed.
    
    If returnObj.Closed Then
        nbr_of_segments = nbr_of_vertices
    Else
        nbr_of_segments = nbr_of_vertices - 1
    End If
    
    ' Have user set the width for each segment of the polygon
    Do While nbr_of_segments > 0
          
        ' Get width values from the user
        promptStart = vbCrLf & "Specify the width at the beginning of the segment at " & retCoord(i) & "," & retCoord(i + 1) & " ==> "
        promptEnd = vbCrLf & "Now specify the width at the end of that segment ==> "
       
        StartWidth = ThisDrawing.Utility.GetReal(promptStart)
        EndWidth = ThisDrawing.Utility.GetReal(promptEnd)

        ' Set the width of the current segment
        returnObj.SetWidth segment, StartWidth, EndWidth
     
        ' Prepare to obtain width of next segment, if any
        i = i + 2
        segment = segment + 1
        nbr_of_segments = nbr_of_segments - 1
    Loop
      
    MsgBox "Segment widths have been set", , "SetWidth Example"

End Sub

Visual LISP:

(vl-load-com)
(defun c:Example_SetWidth()
    ;; The following code prompts you to select a lightweight
    ;; polyline, then displays the width of each segment of the
    ;; selected polyline. 
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))
   
    (vla-GetEntity (vla-get-Utility doc) 'returnObj 'basePnt "Select a polyline: ")
       
    ;; Make sure the user selected a polyline.
    (if (/= returnObj nil)
        (progn
            (if (= (vla-get-ObjectName returnObj) "AcDbPolyline")
	               (progn
		                  ;; Obtain the coordinates of each vertex of the selected polyline.
		                  ;; The coordinates are returned in an array of points.
		                  (setq retCoord (vlax-variant-value (vla-get-Coordinates returnObj)))
		    
		                  (setq segment 0
		                        i (vlax-safearray-get-l-bound retCoord 1)                 ;; Start index of coordinates array
		                        j (vlax-safearray-get-u-bound retCoord 1)                 ;; End index of coordinates array
		                        nbr_of_vertices (+ (/ (- j i) 2) 1))                      ;; Number of vertices in the polyline
		    
		                  ;; Determine the number of segments in the polyline.
		                  ;; A closed polyline has as many segments as it has vertices.
		                  ;; An open polyline has one fewer segment than it has vertices.
		                  ;; Check the Closed property to determine if the polyline is closed.
		                  (if (= (vla-get-Closed returnObj) :vlax-true)
		                      (setq nbr_of_segments nbr_of_vertices)
		                      (setq nbr_of_segments (1- nbr_of_vertices))
		                  )
		    
		                  ;; Get the width of each segment of the polyline
		                  (while (>= nbr_of_segments 0)
		                      ;; Get width values from the user
		                      (setq promptStart (strcat "\nSpecify the width at the beginning of the segment at " (rtos (vlax-safearray-get-element retCoord i) 2) ","
                                                                                                            (rtos (vlax-safearray-get-element retCoord (1+ i)) 2) " ==> "))
		                      (setq promptEnd (strcat "\nNow specify the width at the end of that segment ==> "))

		                      (setq StartWidth (vla-GetReal (vla-get-Utility doc) promptStart))
		                      (setq EndWidth (vla-GetReal (vla-get-Utility doc) promptEnd))

		                      ;; Set the width of the current segment
		                      (vla-SetWidth returnObj segment StartWidth EndWidth)

		                      ;; Prepare to obtain width of next segment, if any
		                      (setq i (+ i 2)
		                            segment (1+ segment)
		                            nbr_of_segments (1- nbr_of_segments))
	              	    )
	              	)
                (alert "Object selected was not a polyline")
            )
       	)
        (alert "No object was selected.")
    )
)