| 
有些朋友问如何获取模型空间VPORT的view direction,我发现了一个技巧,之所以说是技巧,因为在不转换TILEMODE模式的情况下,确实没有一个简洁的解决方案。
×
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册 
    
 由于性能的原因,view direction仅仅在转换tilemode的时候才更新,在ARX或者.net,可以通过acedVports2VportTableRecords全局函数获得实时的结果,但是在LISP中并不容易实现,除非你用ARX写一个函数调用acedVports2VportTableRecords给LISP使用。
 
 下面是实现的代码:
 
 
  (defun c:vptest () 
   (vl-load-com) ; always make sure the COM system is loaded
   ; This is done to synchronize the viewports with the Viewport Table records 
   ; In ObjectARX this is done with acedVports2VportTableRecords()  
   (setvar "tilemode" 0) 
   (setvar "tilemode" 1) 
  
  ;Get the Viewports collection 
  (setq objAcad   (vlax-get-acad-object) 
        objDoc    (vla-get-ActiveDocument objAcad) 
        objVports (vla-get-viewports objDoc) 
  )
  ; use a for loop and loop through the viewports 
  (vlax-for objVport objVports
    ;(vlax-dump-object objVport)   ; Print out objects properties 
    ; get the direction of the viewport 
    (setq directionVariant (vla-get-direction objVport)) 
    (setq safArray (vlax-variant-value directionVariant))
    ; Get the x,y,z values of the direction 
    ; this can be used to determine the view 
    (setq x (vlax-safearray-get-element safArray 0)) 
    (print (strcat "X=" (rtos x))) 
    (setq y (vlax-safearray-get-element safArray 1)) 
    (print (strcat "Y=" (rtos y))) 
    (setq z (vlax-safearray-get-element safArray 2)) 
    (print (strcat "Z=" (rtos z)))
    ; this is a simple example of setting the active viewport 
    ; if x equals zero then make this viewport the active viewport 
    ; this test would need to be enhanced to test the y and z values 
    ; y should equal zero and x should be 1 (that is WCS) 
    (if (= x 0.0) 
      (vla-put-activeviewport objDoc objVport) 
    )    
  )
  (princ)
) 
 |