Is it possible to change Viewport Type via AutoLISP?

Is it possible to change Viewport Type via AutoLISP?

fk
Advocate Advocate
259 Views
2 Replies
Message 1 of 3

Is it possible to change Viewport Type via AutoLISP?

fk
Advocate
Advocate

Hi.
Can someone help me with som code in AutoLISP to change the type of a Viewport in AutoCAD Civil 3D? I want to change an existing Viewport to Plan, Profile or Section.
Thanks in advance.
\Freddy

0 Likes
260 Views
2 Replies
Replies (2)
Message 2 of 3

hippe013
Advisor
Advisor
0 Likes
Message 3 of 3

hippe013
Advisor
Advisor

See the following code for changing the Viewport Type.

(defun GetVpType (vpObj / APPNAME xTypeOut xDataOut)
  (setq APPNAME "AeccPlanProd50ViewportType")
  (vlax-invoke-method vpObj 'GetXData APPNAME 'xTypeOut 'xDataOut)
  (if (not xDataOut) 0 (vlax-variant-value (cadr (vlax-safearray->list xDataout))))
  )

(defun SetVpType (vpObj vpType / APPNAME xTypeIn xDataIn)
  (setq APPNAME "AeccPlanProd50ViewportType")
  (regapp APPNAME)
  
  (setq xTypeIn (vlax-make-safearray vlax-vbInteger '(0 . 1)))
  (setq xDataIn (vlax-make-safearray vlax-vbVariant '(0 . 1)))

  (vlax-safearray-put-element xTypeIn 0 1001)
  (vlax-safearray-put-element xDataIn 0 APPNAME)

  (vlax-safearray-put-element xTypeIn 1 1070)
  (vlax-safearray-put-element xDataIn 1 vpType)

  (vlax-invoke-method vpObj 'SetXData xTypeIn xDataIn)
  )
  

(defun c:Test ( / ss vpObj vpType)
  (setq ss (ssget ":s" '(( 0 . "VIEWPORT"))))
  (if ss
    (progn
      (setq vpObj (vlax-ename->vla-object (ssname ss 0)))
      (setq vpType (GetVpType vpObj))
      (cond
	((= vpType 0) (setq vpType 1))
	((= vpType 1) (setq vpType 2))
	((= vpType 2) (setq vpType 3))
	((= vpType 3) (setq vpType 0))
	)
      (SetVpType vpObj vpType)
      )
    )
  (princ)
  )
0 Likes