CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ActiveX 开发指南

关于计算定义的面积 (VBA/ActiveX)

2023-1-5 02:12| 发布者: admin| 查看: 727| 评论: 0|来自: AutoCAD

摘要: 用户指定的点可用于获取封闭区域的面积。

用户指定的点可用于获取封闭区域的面积。

您可以测量由用户指定的 2D 或 3D 点定义的任意封闭区域。这些点必须是共面的。

从用户处获取点指定的区域

  • 循环使用该方法从用户那里获取点。GetPoint
  • 从用户提供的点创建轻量级折线。使用该方法创建折线。AddLightweightPolyline
  • 使用该属性获取新创建的折线的面积。Area
  • 使用该方法擦除折线。Erase

计算由用户输入的点定义的面积

本示例提示用户输入五个点。然后从输入的点创建一条折线。折线闭合,折线区域显示在消息框中。

Sub Ch3_CalculateDefinedArea()
  Dim p1 As Variant
  Dim p2 As Variant
  Dim p3 As Variant
  Dim p4 As Variant
  Dim p5 As Variant

  ' Get the points from the user
  p1 = ThisDrawing.Utility.GetPoint(, vbCrLf & "First point: ")
  p2 = ThisDrawing.Utility.GetPoint(p1, vbCrLf & "Second point: ")
  p3 = ThisDrawing.Utility.GetPoint(p2, vbCrLf & "Third point: ")
  p4 = ThisDrawing.Utility.GetPoint(p3, vbCrLf & "Fourth point: ")
  p5 = ThisDrawing.Utility.GetPoint(p4, vbCrLf & "Fifth point: ")

  ' Create the 2D polyline from the points
  Dim polyObj As AcadLWPolyline
  Dim vertices(0 To 9) As Double
  vertices(0) = p1(0): vertices(1) = p1(1)
  vertices(2) = p2(0): vertices(3) = p2(1)
  vertices(4) = p3(0): vertices(5) = p3(1)
  vertices(6) = p4(0): vertices(7) = p4(1)
  vertices(8) = p5(0): vertices(9) = p5(1)
  Set polyObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(vertices)
  polyObj.Closed = True
  ThisDrawing.Application.ZoomAll

  ' Display the area for the polyline
  MsgBox "The area defined by the points is " & _
  polyObj.Area, , "Calculate Defined Area"
End Sub

路过

雷人

握手

鲜花

鸡蛋

最新评论

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

GMT+8, 2024-5-12 09:43

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部