Incase anyone is still looking at this thread, here is the updated version of my routine that will wok when you have rotated the ucs. I'm not sure about with twists, as I don't use them, so I don't really know how to test them.
Have fun.
Code:
(defun c:VG ( / ActDoc Vpss VpEnt Vport Ent EntData EntType PtList VpType VpRad MjrAx RadRto VpCntPs VpCnt VpSc MdSpace
NewPtList VpModel cnt)
; Will draw in model space, where the viewport is showing. If you are in a viewport, then it will draw that one,
; if you are not, then it will let you select the viewport.
; Sub's - 'list->variant
(setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(vla-EndUndoMark ActDoc)
(vla-StartUndoMark ActDoc)
(setq MSpace (vla-get-MSpace ActDoc))
(if
(and
(/= (strcase (getvar "ctab")) "MODEL")
(if (equal (setq VpId (getvar "cvport")) 1)
(Setq vpss (ssget '((0 . "VIEWPORT"))))
(setq Vpss (ssget "x" (list '(0 . "VIEWPORT") (cons 69 VpId))))
)
(setq cnt -1)
)
(while (setq VpEnt (ssname Vpss (setq cnt (1+ cnt))))
(setq PtList nil)
(setq NewPtList nil)
(setq VpType nil)
(setq Vport (vlax-ename->vla-object VpEnt))
(if (setq Ent (cdr (assoc 340 (entget VpEnt))))
(cond
((= (setq EntType (cdr (assoc 0 (setq EntData (entget Ent))))) "LWPOLYLINE")
(setq tmpList (vlax-get (vlax-ename->vla-object Ent) 'Coordinates))
(setq cnt 0)
(while (< cnt (length tmpList))
(setq PtList (cons (list (nth cnt tmpList) (nth (1+ cnt) tmpList) 0.0) PtList))
(setq cnt (+ 2 cnt))
)
(setq VpType "Poly")
)
((= EntType "CIRCLE")
(setq VpRad (cdr (assoc 40 EntData)))
(setq VpType "Circle")
)
((= EntType "ELLIPSE")
(setq MjrAx (cdr (assoc 11 EntData)))
(setq RadRto (cdr (assoc 40 EntData)))
(setq VpType "Ellipse")
)
)
(progn
(vla-GetBoundingBox Vport 'MnPt 'MxPt)
(setq MnPt (safearray-value MnPt))
(setq MxPt (safearray-value MxPt))
(setq temp1 (list (car MxPt) (cadr MnPt) (caddr MnPt)))
(setq temp2 (list (car MnPt) (cadr MxPt) (caddr MnPt)))
(setq PtList (list MnPt temp1 MxPt temp2))
(setq VpId (cdr (assoc 69 (entget VpEnt))))
)
)
(setq VpCntPs (vlax-get Vport 'Center))
(if (vl-catch-all-apply 'vla-put-MSpace (list ActDoc :vlax-true))
(progn
(vla-ZoomAll (vlax-get-Acad-Object))
(vla-put-ModelSpace ActDoc ':vlax-true)
)
)
(vla-SetVariable ActDoc "cvport" VpId)
(setq VpCnt (getvar "viewctr"))
(setq VpCntPs (trans VpCntPs 0 2))
(setq PtList (mapcar '(lambda (x) (trans x 0 2)) PtList))
(setq VpSc (vla-get-CustomScale Vport))
(setq MdSpace (vla-get-ModelSpace ActDoc))
(if PtList
(progn
(foreach item PtList
(foreach item2 (list (car item) (cadr item))
(setq NewPtList (cons item2 NewPtList))
)
)
(setq PtList (list->variant (reverse NewPtList) vlax-vbDouble))
)
)
(cond
((= VpType "Poly")
(setq VpModel (vla-AddLightweightPolyline MdSpace PtList))
(if (= (vla-get-Closed VpModel) ':vlax-false)
(vla-put-Closed VpModel ':vlax-true)
)
(vla-Move VpModel (vlax-3d-point VpCntPs) (vlax-3d-point (trans VpCnt 1 0)))
)
((= VpType "Circle")
(setq VpModel (vla-AddCircle MdSpace (vlax-3d-point (trans VpCnt 1 0)) VpRad))
)
((= VpType "Ellipse")
(setq VpModel (vlax-invoke MdSpace 'AddEllipse (trans VpCnt 1 0) MjrAx RadRto))
)
(
(setq VpModel (vla-AddLightweightPolyline MdSpace PtList))
(if (= (vla-get-Closed VpModel) ':vlax-false)
(vla-put-Closed VpModel ':vlax-true)
)
(vla-Move VpModel (vlax-3d-point VpCntPs) (vlax-3d-point (trans VpCnt 1 0)))
)
)
(vla-ScaleEntity VpModel (vlax-3d-point (trans VpCnt 1 0)) (/ 1.0 VpSc))
(vl-catch-all-apply 'vla-put-Layer (list VpModel "Defpoints"))
)
(prompt "\n No Viewport active.")
)
(vla-put-MSpace ActDoc MSpace)
(vla-EndUndoMark ActDoc)
(princ)
)
;-------------------------------------------------------------------------------------
(defun list->variant (lst vartype)
; By Frank Oquendo
(vlax-make-variant
(vlax-safearray-fill
(vlax-make-safearray vartype (cons 0 (1- (length lst))))
lst
)
)
)