Jump to content

Recommended Posts

Posted

I'm looking a lisp that can run from modelspace that will move object(s) from modelspace to paperspace. I'm assuming that there is only one paperspace window.

 

Anyone see anything like this?

 

Thanks.

Posted

Simple and quickie one:

(defun c:test  (/ ss i lst lay doc)
 ;;	Tharwat 15.June.2016	;;
 (if (not (eq (getvar 'ctab) "Model"))
   (princ "\n ** Command not allowed in Paper Space **")
   (if (setq ss (ssget "_:L"))
     (progn
       (repeat (setq i (sslength ss))
         (setq lst (cons (vlax-ename->vla-object
                           (ssname ss (setq i (1- i))))
                         lst))
         )
       (setq doc (vla-get-activedocument (vlax-get-acad-object))
             lay (vla-item (vla-get-layouts doc) (car (layoutlist)))
             )
       (vlax-invoke doc 'copyobjects lst (vla-get-block lay))
       (mapcar 'vla-delete lst)
       )
     )
   )
 (princ)
 )(vl-load-com)

Posted

Awesome and almost!

 

The object just needs to be scaled according to the paperspace scale which I can figure out.

 

Don't know how you guys keep all that knowledge in your head all the time.:D

Posted

Hmm, a bit trickier for me than I thought. It needs to scale from 0,0 at the paperspace scale. So I don't know how to access that scale while in modelspace...

Posted
Don't know how you guys keep all that knowledge in your head all the time.:D

Become a habit. :D

The object just needs to be scaled according to the paperspace scale which I can figure out.

What is the scale factor that you would like to scale the objects when they moved to paper space?

Posted

Dangit. I just remembered that I can use the dimscale...below didn't work for me.

 

(defun c:test  (/ ss i lst lay doc int)
 ;;	Tharwat 15.June.2016	;;
 (if (not (eq (getvar 'ctab) "Model"))
   (princ "\n ** Command not allowed in Paper Space **")
   (if (setq ss (ssget "_:L"))
     (progn
       (repeat (setq i (sslength ss))
         (setq lst (cons (vlax-ename->vla-object
                           (ssname ss (setq i (1- i))))
                         lst))
         )
       (setq doc (vla-get-activedocument (vlax-get-acad-object))
             lay (vla-item (vla-get-layouts doc) (car (layoutlist)))
             )
       (vlax-invoke doc 'copyobjects lst (vla-get-block lay))
       (setq int (1 / (getvar "dimscale")))
       (command "scale" (entlast) "0,0" int)
       (mapcar 'vla-delete lst)
       )
     )
   )
 (princ)
 )(vl-load-com)

Posted

 

Thanks for chiming in Lee. I saw your LISP but I needed it to be able to run it without having to work through a viewport.

 

Thanks.

Posted

Try this:

 

(defun c:test  (/ ss i lst lay doc objs int)
 ;;	Tharwat 15.June.2016	;;
 (if (not (eq (getvar 'ctab) "Model"))
   (princ "\n ** Command not allowed in Paper Space **")
   (if (and (setq ss (ssget "_:L"))
            (progn
              (repeat (setq i (sslength ss))
                (setq lst (cons (vlax-ename->vla-object (ssname ss (setq i (1- i)))) lst))
                )
              lst
              )
            (setq doc (vla-get-activedocument (vlax-get-acad-object))
                  lay (vla-item (vla-get-layouts doc) (car (layoutlist)))
                  )
            (apply 'and (setq objs (vlax-invoke doc 'copyobjects lst (vla-get-block lay))))
            (setq int (/ 1. (getvar "dimscale")))
            )
     (progn
       (mapcar '(lambda (u) (vla-scaleentity u (vlax-3d-point '(0. 0. 0.)) int)) objs)
       (mapcar 'vla-delete lst)
       )
         )
       )    
 (princ)
 )(vl-load-com)

Posted

Ah yes, thank you much.

 

Now I can force those revclouds out of my modelspace...

 

For my ignorance, is it not possible to use entlast because of VLA?

Posted

@ Tharwat:

why do you have this in your code?:

(apply 'and (setq objs ... ))

Posted
@ Tharwat:

why do you have this in your code?:

(apply 'and (setq objs ... ))

 

Because list of objects would always return T even if the elements of the list is a list of nil and in my previous codes I added the apply with and to get sure that all elements in the list is valid and equal to true then to continue to next line.

eg:

_$ (and '(nil nil nil))
T
_$ (and '(t nil nil))
T
_$ (apply 'and '(t nil nil))
nil
_$ (apply 'and '(t t t))
T

Posted

@ Tharwat:

I understand that. But I can't think of a case where (vlax-invoke doc 'copyobjects ...) returns a list with a nil.

Posted

Agreed and it is just another way of writing the program, nothing's more.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...