CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ActiveX 开发指南

相关分类

GetWidth Method (ActiveX)

2023-1-4 06:25| 发布者: admin| 查看: 604| 评论: 0|来自: AutoCAD

摘要: 获取折线的开始宽度和结束宽度。

获取折线的开始宽度和结束宽度。

支持的平台:仅窗口

签名

工 务 局:

object.GetWidth Index, StartWidth, EndWidth
对象

类型:长线折线

此方法适用的对象。

指数

访问:仅输入

类型:整数

返回宽度的折线的索引位置。索引必须是以 0 开头的正整数。

起始宽度

访问:仅输出

类型:

给定索引处折线的起始宽度。

端宽

访问:仅输出

类型:

给定索引处折线的端宽。

返回值(RetVal)

无返回值。

言论

折线:如果折线属性是 ISOR,则此方法将失败。TypeacCubicSplinePolyacQuadSplinePoly

例子

工 务 局:

Sub Example_GetWidth()
    ' The following code prompts you to select a lightweight
    ' polyline, then displays the width of each segment of the
    ' selected polyline. 

    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 message_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
    
    ' Get the width of each segment of the polyline
    Do While nbr_of_segments > 0
          
        ' Get the width of the current segment
        returnObj.GetWidth segment, StartWidth, EndWidth
        
        message_string = "The segment that begins at " & retCoord(i) & "," & retCoord(i + 1) _
            & " has a start width of " & StartWidth & " and an end width of " & EndWidth
        MsgBox message_string, , "GetWidth Example"
     
        ' Prepare to obtain width of next segment, if any
        i = i + 2
        segment = segment + 1
        nbr_of_segments = nbr_of_segments - 1
    Loop
      
End Sub

Visual LISP:

(vl-load-com)
(defun c:Example_GetWidth()
    ;; 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 the width of the current segment
		                      (vla-GetWidth returnObj segment 'StartWidth 'EndWidth)
		        
		                      (setq message_string (strcat "The segment that begins at " (rtos (vlax-safearray-get-element retCoord i) 2) ","
						                                                                             (rtos (vlax-safearray-get-element retCoord (1+ i)) 2)
		                                                   " has a start width of " (rtos StartWidth 2) " and an end width of " (rtos EndWidth 2)))
                        (alert message_string)
		     
                        ;; Prepare to obtain width of next segment, if any
                        (setq i (+ i 2))
                        (setq segment (1+ segment))
                        (setq nbr_of_segments (1- nbr_of_segments))
		                  )
                )
                (alert "Object selected was not a polyline")
            )
        )
        (alert "No object was selected.")
    )
)

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )

GMT+8, 2024-5-11 14:46

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部