指定折线中所有线段的全局宽度。 支持的平台:仅窗口 属性值只读:不 类型:双 对象中所有段的全局宽度。 言论此属性将折线中所有线段的起点和终点宽度设置为统一值。仅当所有段都设置为统一宽度时,此属性才会返回恒定宽度。 使用 与 方法指定单个段的宽度。SetWidthGetWidth 例子工 务 局: 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
Visual LISP: (vl-load-com)
(defun c: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.
(setq acadObj (vlax-get-acad-object))
(setq doc (vla-get-ActiveDocument acadObj))
;; Define the 2D polyline points
(setq points (vlax-make-safearray vlax-vbDouble '(0 . 9)))
(vlax-safearray-fill points '(1 1
1 2
2 2
3 2
4 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.
(setq modelSpace (vla-get-ModelSpace doc))
(setq plineObj (vla-AddLightWeightPolyline modelSpace points))
(vla-ZoomAll acadObj)
;; Display segment information before altering the width of segment 1
;; Check to see if the segment widths are uniform
(setq err (vl-catch-all-apply 'vla-get-ConstantWidth (list plineObj)))
(if (vl-catch-all-error-p err)
(setq msg " are not equal.")
(setq msg " are all equal."
CWidth err)
)
(alert (strcat "The segments of the new polyline" msg))
;; Set the first segment width
(vla-SetWidth plineObj 1 0.1 0.3)
(vla-Regen doc acAllViewports)
;; Display segment information after altering the width of segment 1
;; Check to see if the segment widths are uniform
(setq err (vl-catch-all-apply 'vla-get-ConstantWidth (list plineObj)))
(if (vl-catch-all-error-p err)
(setq msg " are not equal.")
(setq msg " are all equal."
CWidth err)
)
(alert (strcat "The segments of the new polyline" msg))
;; Make all segments uniform in width
(vla-put-ConstantWidth plineObj 0.1)
(vla-Regen doc acAllViewports)
;; Display segment information after making the segments uniform
;; Check to see if the segment widths are uniform
(setq err (vl-catch-all-apply 'vla-get-ConstantWidth (list plineObj)))
(if (vl-catch-all-error-p err)
(setq msg " are not equal.")
(setq msg " are all equal."
CWidth err)
)
(alert (strcat "The segments of the new polyline" msg))
)
|
|Archiver|CAD开发者社区
( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-10-29 08:44
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.