Lee Mac Posted July 21, 2009 Posted July 21, 2009 From ACAD help: You cannot use the entmod function to modify a viewport entity. Quote
SteveK Posted July 21, 2009 Posted July 21, 2009 Oh. Thanks for informing me. That's no good. VLisp might be all that's left I wanted to make a few other changes to the viewports, hence why I wanted to just stick with what I know (autolisp). I would like to: Set viewport 2 to have the same model-space x co-ordinate as viewport 1 (then re-lock the viewport) If 1 is too easy :wink:, then round the paper-space y co-ordinate of viewport 2 to the nearest 25 based on the value of viewport 1's model-space y co-ordinate (perhaps a picture would help. I can't seem to export images with the viewport background so perhaps a pdf will do) I thought I could do this with autolisp but vlisp I don't know enough of the functions. Thanks to all who can help, Viewport Change.pdf Quote
Lee Mac Posted July 22, 2009 Posted July 22, 2009 Something like this? (defun c:MacVP (/ ent1 ent2 Obj1 Obj2) (vl-load-com) (while (progn (setq ent1 (car (entsel "\nSelect Source Viewport: "))) (cond ((eq 'ENAME (type ent1)) (if (eq "VIEWPORT" (cdadr (entget ent1))) (while (progn (setq ent2 (car (entsel "\nSelect Second Viewport: "))) (cond ((eq 'ENAME (type ent2)) (if (not (eq "VIEWPORT" (cdadr (entget ent2)))) (princ "\n** Object is not a Viewport **"))) (t (princ "\n** No Viewport Selected **"))))) (princ "\n** Object is not a Viewport **"))) (t (princ "\n** No Viewport Selected **"))))) (vl-catch-all-apply (function (lambda ( ) (vlax-put-property (setq Obj2 (vlax-ename->vla-object ent2)) 'Center (vlax-3D-point (append (list (car (vlax-get (setq Obj1 (vlax-ename->vla-object ent1)) 'Center))) (cdr (vlax-get Obj2 'Center))))) (vla-put-width Obj2 (vla-get-Width Obj1))))) (princ)) Quote
SteveK Posted July 22, 2009 Posted July 22, 2009 Thanks Lee. It's halfway like what I need. It makes Vp2's width and x co-ord in paper-space the same as Vp1's, but it doesn't make Vp2's model-space x co-ord also the same as Vp1's. Does that make sense? Quote
Lee Mac Posted July 22, 2009 Posted July 22, 2009 Thanks Lee. It's halfway like what I need. It makes Vp2's width and x co-ord in paper-space the same as Vp1's, but it doesn't make Vp2's model-space x co-ord also the same as Vp1's. Does that make sense? I think so. at least I'm on the right path Quote
Lee Mac Posted July 22, 2009 Posted July 22, 2009 I tried this, but I don't think it works (defun c:MacVP (/ ent1 ent2 Obj1 Obj2) (vl-load-com) (while (progn (setq ent1 (car (entsel "\nSelect Source Viewport: "))) (cond ((eq 'ENAME (type ent1)) (if (eq "VIEWPORT" (cdadr (entget ent1))) (while (progn (setq ent2 (car (entsel "\nSelect Second Viewport: "))) (cond ((eq 'ENAME (type ent2)) (if (not (eq "VIEWPORT" (cdadr (entget ent2)))) (princ "\n** Object is not a Viewport **"))) (t (princ "\n** No Viewport Selected **"))))) (princ "\n** Object is not a Viewport **"))) (t (princ "\n** No Viewport Selected **"))))) (vl-catch-all-apply (function (lambda ( ) (foreach prop '(Target Center) (vlax-put-property (setq Obj2 (vlax-ename->vla-object ent2)) prop (vlax-3D-point (append (list (car (vlax-get (setq Obj1 (vlax-ename->vla-object ent1)) prop))) (cdr (vlax-get Obj2 prop)))))) (vla-put-width Obj2 (vla-get-Width Obj1))))) (princ)) Quote
SteveK Posted July 22, 2009 Posted July 22, 2009 It just does the same thing; aligns the x-coord viewports (paperspace) but does nothing to modelspace. Appreciate your efforts so far. Quote
Lee Mac Posted July 23, 2009 Posted July 23, 2009 Yeah, thats what I thought. I've posted a thread on TheSwamp to see if they can help with my problems, we'll see what we can do Lee Quote
SteveK Posted July 24, 2009 Posted July 24, 2009 Thanks a lot Lee, you go out of your way to help. I'm not at a computer with autocad until monday but I'll be sure to let you know as soon as I try it. Quote
SteveK Posted July 26, 2009 Posted July 26, 2009 It looks like it should work, however when I run it nothing happens. I've attached the drawing of the pdf I made in an earlier post so you can see what I mean. Thanks for your help. I'm beginning to think it's best to leave viewports alone when it comes to using lisps... Viewport.dwg Quote
Lee Mac Posted July 27, 2009 Posted July 27, 2009 Dude, I'm so sorry, I altered the LISP when it was in the code frame in the reply and made a really stupid mistake with the variables This should hopefully work: (defun c:MacVP (/ *error* ent1 ent2 Obj1 Obj2 ctr scl doc app) (vl-load-com) (defun *error* (err) (if doc (vla-EndUndoMark doc)) (if (not (wcmatch (strcase err) "*BREAK,*CANCEL*,*EXIT*")) (princ (strcat "\n** Error: " err " **"))) (princ)) (while (progn (setq ent1 (car (entsel "\nSelect Source Viewport: "))) (cond ((eq 'ENAME (type ent1)) (if (eq "VIEWPORT" (cdadr (entget ent1))) (while (progn (setq ent2 (car (entsel "\nSelect Second Viewport: "))) (cond ((eq 'ENAME (type ent2)) (if (not (eq "VIEWPORT" (cdadr (entget ent2)))) (princ "\n** Object is not a Viewport **"))) (t (princ "\n** No Viewport Selected **"))))) (princ "\n** Object is not a Viewport **"))) (t (princ "\n** No Viewport Selected **"))))) (vla-StartUndoMark (setq doc (vla-get-ActiveDocument (setq app (vlax-get-acad-object))))) (vl-catch-all-apply (function (lambda ( ) (vla-put-width (setq Obj2 (vlax-ename->vla-object ent2)) (vla-get-Width (setq Obj1 (vlax-ename->vla-object ent1)))) (vlax-put-property Obj2 'Center (vlax-3D-point (append (list (car (vlax-get Obj1 'Center))) (cdr (vlax-get Obj2 'Center))))) (setq scl (vla-get-CustomScale Obj2)) (vla-put-MSpace doc :vlax-true) (setvar "CVPORT" (cdr (assoc 69 (entget ent1)))) (setq ctr (getvar "VIEWCTR")) (setvar "CVPORT" (cdr (assoc 69 (entget ent2)))) (vla-ZoomCenter app (vlax-3D-point (cons (car ctr) (cdr (getvar "VIEWCTR")))) 1.) (vla-put-CustomScale Obj2 scl) (mapcar (function (lambda (vp) (vla-put-Displaylocked vp :vlax-true))) (list Obj1 Obj2)) (vla-put-MSpace doc :vlax-false)))) (vla-EndUndoMark doc) (princ)) Quote
SteveK Posted July 27, 2009 Posted July 27, 2009 That fixed it. Sweet. Yeah that works well. Not sure if anyone else will find this beneficial, but just to summarize if other people were wondering what this code does: Takes a source viewport and retrieve's the properties of it's width as well as it's center x co-ordinate in both paper-space & model-space. It then copies these properties to the selected "second" viewport. Thanks Lee Quote
Recommended Posts
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.