Inspired by the request in this thread (http://www.cadtutor.net/forum/showthread.php?84297) at CADTutor, I accepted the challenge of writing a program allowing the user to copy a selection of objects from modelspace to paperspace such that the objects will appear exactly as they are displayed through the active viewport.really good start :)
I realise that it is already possible to transfer objects between modelspace/paperspace using the CHSPACE command, however, I was interested in the challenge of performing the various matrix transformations required to display the objects correctly.
I have written the following program as an initial draft of this idea, however, the program currently only performs correctly with viewports for which the viewtwist is zero:Code - Auto/Visual Lisp: [Select]
I wondered if anyone could offer an insight into what I am overlooking in my calculations?
Or perhaps offer a better approach?
Many thanks,
Lee
(setq d '(0.0 0.0 0.0)
d (trans d 0 1)
)
4 - Create a block of the selection set using the base point 'd' as calculated in step 3.(setq d (trans d 1 2)
d (trans d 2 3)
)
6 - Insert the block prefixed with "*" to invoke exploding, in paperspace (with UCS world), at the translated insert point 'd', scale 'c' and rotation 0.0.
It's the translation steps that intrigue me. Having become rusty on matrix maths, I do wonder if there are any shortcuts to the translation steps?
;; Modelspace to Paperspace - Lee Mac
(defun c:ms2ps ( / ang doc idx lst mat org sel )
(cond
( (= 1 (getvar 'tilemode))
(prompt "\nCommand only available in Paperspace.")
)
( (= 1 (getvar 'cvport))
(prompt "\nPlease activate a viewport.")
)
( (setq sel (ssget '((410 . "Model"))))
(repeat (setq idx (sslength sel))
(setq lst (cons (vlax-ename->vla-object (ssname sel (setq idx (1- idx)))) lst))
)
(setq ang (getvar "viewtwist")
mat
(vlax-tmatrix
(append
(mapcar
'(lambda ( a b )
(append (mapcar '- (trans a 2 3) org) (list b))
)
(list (list (cos ang) (- (sin ang)) 0.0)
(list (sin ang) (cos ang) 0.0)
'(0.0 0.0 1.0)
)
(setq org (trans (trans '(0.0 0.0 0.0) 0 2) 2 3))
)
'((0.0 0.0 0.0 1.0))
)
)
)
(foreach obj
(vlax-invoke (setq doc (vla-get-activedocument (vlax-get-acad-object))) 'copyobjects lst
(vla-get-block
(vla-item
(vla-get-layouts doc)
(getvar 'ctab)
)
)
)
(vla-transformby obj mat)
)
)
)
(princ)
)
(vl-load-com) (princ)
;; Modelspace to Paperspace - Lee Mac
(defun c:ms2ps ( / doc idx lst mat org sel )
(cond
( (= 1 (getvar 'tilemode))
(prompt "\nCommand only available in Paperspace.")
)
( (= 1 (getvar 'cvport))
(prompt "\nPlease activate a viewport.")
)
( (setq sel (ssget '((410 . "Model"))))
(repeat (setq idx (sslength sel))
(setq lst (cons (vlax-ename->vla-object (ssname sel (setq idx (1- idx)))) lst))
)
(setq mat
(vlax-tmatrix
(append
(mapcar
'(lambda ( a b )
(append (mapcar '- (trans (trans a 2 0 T) 2 3) org) (list b))
)
'(
(1.0 0.0 0.0)
(0.0 1.0 0.0)
(0.0 0.0 1.0)
)
(setq org (trans (trans '(0.0 0.0 0.0) 0 2) 2 3))
)
'((0.0 0.0 0.0 1.0))
)
)
)
(foreach obj
(vlax-invoke (setq doc (vla-get-activedocument (vlax-get-acad-object))) 'copyobjects lst
(vla-get-block
(vla-item
(vla-get-layouts doc)
(getvar 'ctab)
)
)
)
(vla-transformby obj mat)
)
)
)
(princ)
)
(vl-load-com) (princ)