CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ActiveX 开发指南

关于查询光线 (VBA/ActiveX)

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

摘要: 创建后,您可以查询光线以确定用于创建对象的点。

创建后,您可以查询光线以确定用于创建对象的点。

该属性可用于获得射线的第一个点。虽然用于创建光线的第二个点不与对象一起存储,但您可以使用该属性获取光线的方向矢量。BasePointDirectionVector

添加、查询和编辑 Ray 对象

下面的示例代码使用两个点 (5, 0, 0) 和 (1, 1, 0) 创建一个对象。然后,它查询当前基点和方向向量,并在消息框中显示结果。然后更改方向矢量,查询并显示基点和新方向矢量。Ray

Sub Ch3_EditRay()
  Dim rayObj As AcadRay
  Dim basePoint(0 To 2) As Double
  Dim secondPoint(0 To 2) As Double

  ' Define the ray
  basePoint(0) = 3#: basePoint(1) = 3#: basePoint(2) = 0#
  secondPoint(0) = 4#: secondPoint(1) = 4#: secondPoint(2) = 0#

  ' Creates a Ray object in model space
  Set rayObj = ThisDrawing.ModelSpace.AddRay(basePoint, secondPoint)
  ThisDrawing.Application.ZoomAll

  ' Find the current status of the Ray
  MsgBox "The base point of the ray is: " & _
  rayObj.basePoint(0) & ", " & _
  rayObj.basePoint(1) & ", " & _
  rayObj.basePoint(2) & vbCrLf & _
  "The directional vector for the ray is: " & _
  rayObj.DirectionVector(0) & ", " & _
  rayObj.DirectionVector(1) & ", " & _
  rayObj.DirectionVector(2), , "Edit Ray"

  ' Change the directional vector for the ray
  Dim newVector(0 To 2) As Double
  newVector(0) = -1
  newVector(1) = 1
  newVector(2) = 0
  rayObj.DirectionVector = newVector
  ThisDrawing.Regen False

  MsgBox "The base point of the ray is: " & _
  rayObj.basePoint(0) & ", " & _
  rayObj.basePoint(1) & ", " & _
  rayObj.basePoint(2) & vbCrLf & _
  "The directional vector for the ray is: " & _
  rayObj.DirectionVector(0) & ", " & _
  rayObj.DirectionVector(1) & ", " & _
  rayObj.DirectionVector(2), , "Edit Ray"
End Sub

路过

雷人

握手

鲜花

鸡蛋

最新评论

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

GMT+8, 2024-5-11 23:18

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部