Author Topic: Target property in Viewport  (Read 4853 times)

0 Members and 1 Guest are viewing this topic.

Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: Target property in Viewport
« Reply #15 on: July 23, 2009, 06:33:37 PM »
Perfection Tim.

Many thanks for your input - I shall draw from your code, and incorporate your ideas  :-)

Thanks once again,

Lee

PS> indeed, anything can be done  :-P

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Target property in Viewport
« Reply #16 on: July 23, 2009, 06:37:05 PM »
As long as we are learning, then it is all good.  I love figuring out stuff, that is why I have to try hard not to code everyone's problems.  You're welcome Lee.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: Target property in Viewport
« Reply #17 on: July 23, 2009, 06:51:01 PM »
Yeah, I'm a bit like that - I end up writing codes for every problem I can manage...

Went with this in the end:

Code: [Select]
(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 ( )
        (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))
        (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))


Thanks again Tim.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Target property in Viewport
« Reply #18 on: July 23, 2009, 07:03:32 PM »
Looks good.  One thing though.  I would change the Width property before the Center property.  On my small test I didn't, and they were not aligned after the width changed.  It pushed out one side, and not both sides like one would think.

You're welcome Lee.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: Target property in Viewport
« Reply #19 on: July 23, 2009, 07:07:36 PM »
Thanks for the heads up Tim  :-D