Jump to content

Recommended Posts

  • Replies 33
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    18

  • Lee5150

    9

  • SteveK

    7

Top Posters In This Topic

Posted Images

Posted

From ACAD help:

 

You cannot use the entmod function to modify a viewport entity.
Posted

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:

  1. Set viewport 2 to have the same model-space x co-ordinate as viewport 1 (then re-lock the viewport)
  2. 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

Posted

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))

Posted

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?

Posted
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 :)

Posted

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))

Posted

It just does the same thing; aligns the x-coord viewports (paperspace) but does nothing to modelspace.

Appreciate your efforts so far. :)

Posted

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

Posted

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.

Posted

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

Posted

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 :oops:

 

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))

Posted

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:

  1. 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.
  2. It then copies these properties to the selected "second" viewport.

Thanks Lee

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...