找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 401|回复: 1

[每日一码] 用VLISP获取模型空间视口观察方向向量VIEWDIR

[复制链接]

已领礼包: 20个

财富等级: 恭喜发财

发表于 2018-6-18 21:06:33 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
有些朋友问如何获取模型空间VPORT的view direction,我发现了一个技巧,之所以说是技巧,因为在不转换TILEMODE模式的情况下,确实没有一个简洁的解决方案。

由于性能的原因,view direction仅仅在转换tilemode的时候才更新,在ARX或者.net,可以通过acedVports2VportTableRecords全局函数获得实时的结果,但是在LISP中并不容易实现,除非你用ARX写一个函数调用acedVports2VportTableRecords给LISP使用。

下面是实现的代码:

  1. (defun c:vptest ()
  2.    (vl-load-com) ; always make sure the COM system is loaded

  3.    ; This is done to synchronize the viewports with the Viewport Table records
  4.    ; In ObjectARX this is done with acedVports2VportTableRecords()  
  5.    (setvar "tilemode" 0)
  6.    (setvar "tilemode" 1)
  7.   
  8.   ;Get the Viewports collection
  9.   (setq objAcad   (vlax-get-acad-object)
  10.         objDoc    (vla-get-ActiveDocument objAcad)
  11.         objVports (vla-get-viewports objDoc)
  12.   )

  13.   ; use a for loop and loop through the viewports
  14.   (vlax-for objVport objVports

  15.     ;(vlax-dump-object objVport)   ; Print out objects properties
  16.     ; get the direction of the viewport
  17.     (setq directionVariant (vla-get-direction objVport))
  18.     (setq safArray (vlax-variant-value directionVariant))

  19.     ; Get the x,y,z values of the direction
  20.     ; this can be used to determine the view
  21.     (setq x (vlax-safearray-get-element safArray 0))
  22.     (print (strcat "X=" (rtos x)))
  23.     (setq y (vlax-safearray-get-element safArray 1))
  24.     (print (strcat "Y=" (rtos y)))
  25.     (setq z (vlax-safearray-get-element safArray 2))
  26.     (print (strcat "Z=" (rtos z)))

  27.     ; this is a simple example of setting the active viewport
  28.     ; if x equals zero then make this viewport the active viewport
  29.     ; this test would need to be enhanced to test the y and z values
  30.     ; y should equal zero and x should be 1 (that is WCS)
  31.     (if (= x 0.0)
  32.       (vla-put-activeviewport objDoc objVport)
  33.     )   
  34.   )
  35.   (princ)
  36. )
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 8727个

财富等级: 富甲天下

发表于 2018-6-18 21:59:00 | 显示全部楼层
感谢分享程!!!!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-4-20 10:47 , Processed in 0.174270 second(s), 30 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表