CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

AutoCAD 2024 开发者帮助

关于查询光线 (ActiveX)

2024-5-18 19:06| 发布者: admin| 查看: 172| 评论: 0|原作者: admin|来自: AutoCAD

关于查询光线 (ActiveX)

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

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

添加、查询和编辑 Ray 对象

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

AutoLISP
(vl-load-com)
(defun c:Ch3_EditRay()
    (setq acadObj (vlax-get-acad-object)
          doc (vla-get-ActiveDocument acadObj)
          moSpace (vla-get-ModelSpace doc))

    ;; Define the ray
    (setq basePoint (vlax-3d-point 3 3 0)
          secondPoint (vlax-3d-point 4 4 0))

    ;; Creates a Ray object in model space
    (setq rayObj (vla-AddRay moSpace basePoint secondPoint))
    (vla-ZoomAll acadObj)
  
    ;; Find the current status of the Ray
    (setq LBPoint (vlax-safearray->list (vlax-variant-value (vla-get-BasePoint rayObj)))
          LDirVector (vlax-safearray->list (vlax-variant-value (vla-get-DirectionVector rayObj))))

    (alert (strcat "The base point of the ray is: "
                   (rtos (nth 0 LBPoint) 2) ", "
                   (rtos (nth 1 LBPoint) 2) ", "
                   (rtos (nth 2 LBPoint) 2)
                   "\nThe directional vector for the ray is: "
                   (rtos (nth 0 LDirVector) 2) ", "
                   (rtos (nth 1 LDirVector) 2) ", "
                   (rtos (nth 2 LDirVector) 2)))

    ;; Change the directional vector for the ray
    (setq newVector (vlax-3d-point -1 1 0))  
    (vla-put-DirectionVector rayObj newVector)
    (vla-Regen doc :vlax-false)

    (setq LBPoint (vlax-safearray->list (vlax-variant-value (vla-get-BasePoint rayObj)))
	         LDirVector (vlax-safearray->list (vlax-variant-value (vla-get-DirectionVector rayObj))))

    (alert (strcat "The base point of the ray is: "
                   (rtos (nth 0 LBPoint) 2) ", "
                   (rtos (nth 1 LBPoint) 2) ", "
                   (rtos (nth 2 LBPoint) 2)
                   "\nThe directional vector for the ray is: "
                   (rtos (nth 0 LDirVector) 2) ", "
                   (rtos (nth 1 LDirVector) 2) ", "
                   (rtos (nth 2 LDirVector) 2)))
)
VBA(仅限 AutoCAD)
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

路过

雷人

握手

鲜花

鸡蛋

最新评论

群   号:715888130

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

GMT+8, 2025-6-1 14:13

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部