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

0 Members and 1 Guest are viewing this topic.

Lee Mac

  • Seagull
  • Posts: 12922
  • London, England
Target property in Viewport
« on: July 22, 2009, 06:49:08 PM »
I have been trying to modify the target property for a viewport, for a LISP I am helping a guy with, but I don't seem to be having much luck.

I have wrapped the business end of the code in a vl-catch-all-apply, so I dont expect an error, but, even when testing without this wrapper, I don't get an error, just nothing happens to the target point.

Perhaps I am barking up the wrong tree, but any help is appreciated.

Lee

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

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Target property in Viewport
« Reply #1 on: July 22, 2009, 07:27:53 PM »
It changes the ' target ' property on my test.
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: 12922
  • London, England
Re: Target property in Viewport
« Reply #2 on: July 23, 2009, 12:52:39 PM »
Thanks for the response Tim. :-)

On mine, the target property is always (0,0,0) no matter how the objects inside are moved.  :-(

Spike Wilbury

  • Guest
Re: Target property in Viewport
« Reply #3 on: July 23, 2009, 01:17:20 PM »
no idea what it does....  :lol:

but on the little test i did, it overlap two vp's

so it does something.... here


edit: tested on a2009

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Target property in Viewport
« Reply #4 on: July 23, 2009, 01:18:01 PM »
Thanks for the response Tim. :-)

On mine, the target property is always (0,0,0) no matter how the objects inside are moved.  :-(

I'm in '06 if that matters at all.
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: 12922
  • London, England
Re: Target property in Viewport
« Reply #5 on: July 23, 2009, 01:28:27 PM »
Sorry guys,

I should've explained a bit more..  :oops:

Two Viewports should be aligned by x-coordinate, and the widths of both should be equal. Also, the modelspace view (target, I think) should be aligned also by X coordinate -- but this is the part I am struggling to achieve.

I find that no matter what the modelspace view is, the target property on every VP is always '(0 0 0).

Thanks for the continued support,

Lee

Spike Wilbury

  • Guest
Re: Target property in Viewport
« Reply #6 on: July 23, 2009, 01:30:38 PM »
Sorry guys,

I should've explained a bit more..  :oops:

Two Viewports should be aligned by x-coordinate, and the widths of both should be equal. Also, the modelspace view (target, I think) should be aligned also by X coordinate -- but this is the part I am struggling to achieve.

I find that no matter what the modelspace view is, the target property on every VP is always '(0 0 0).

Thanks for the continued support,

Lee

mention your acadver

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Target property in Viewport
« Reply #7 on: July 23, 2009, 01:36:59 PM »
I think the only way to get the viewport center is to activate it, and then grab the system variable ' viewctr '.
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: 12922
  • London, England
Re: Target property in Viewport
« Reply #8 on: July 23, 2009, 01:38:14 PM »
Sorry guys,

I should've explained a bit more..  :oops:

Two Viewports should be aligned by x-coordinate, and the widths of both should be equal. Also, the modelspace view (target, I think) should be aligned also by X coordinate -- but this is the part I am struggling to achieve.

I find that no matter what the modelspace view is, the target property on every VP is always '(0 0 0).

Thanks for the continued support,

Lee

mention your acadver

Ahh yes - ACAD 2010.

I think the only way to get the viewport center is to activate it, and then grab the system variable ' viewctr '.

Good idea, I'll give it a go mate :-)

Lee

Lee Mac

  • Seagull
  • Posts: 12922
  • London, England
Re: Target property in Viewport
« Reply #9 on: July 23, 2009, 04:13:24 PM »
Ok Tim,

I have tried your method, but to no avail unfortunately :-(

Here is my current code:

Code: [Select]
(defun c:MacVP (/ ent1 ent2 Obj1 Obj2 ctr doc)
  (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))
        (vlax-invoke-method Obj1 'Display :vlax-true)
        (vla-put-MSpace
          (setq doc
            (vla-get-ActiveDocument
              (vlax-get-acad-object))) :vlax-true)
        (setq ctr (vla-getVariable doc "VIEWCTR"))
        (mapcar
          (function
            (lambda (Obj Arg)
              (vlax-invoke-method Obj 'Display Arg)))
          (list Obj1 Obj2) '(:vlax-false :vlax-true))
        (vla-ZoomCenter
          (vlax-get-acad-object) ctr 1.)
        (mapcar
          (function
            (lambda (vp)
              (vla-put-Displaylocked vp :vlax-true)))
          (list Obj1 Obj2))
        (vla-Display Obj2 :vlax-false)
        (mapcar
          (function
            (lambda (Obj)
              (vlax-put-property Obj 'ViewportOn :vlax-true)))
          (list Obj1 Obj2)))))

  (princ))


Crank

  • Water Moccasin
  • Posts: 1503
Re: Target property in Viewport
« Reply #10 on: July 23, 2009, 04:21:10 PM »
Lee,

I'm not sure what you're trying to accomplish, but I think you should take a look at the code of aspace.lsp and vpsync.lsp (express tools).
Vault Professional 2023     +     AEC Collection

Lee Mac

  • Seagull
  • Posts: 12922
  • London, England
Re: Target property in Viewport
« Reply #11 on: July 23, 2009, 05:05:51 PM »
Thanks for the suggestion Crank - I didn't know those functions existed 'til now...   :-)

I have tried them, but they don't seem to perform as I want this LISP to... perhaps this cannot be done  :-(

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Target property in Viewport
« Reply #12 on: July 23, 2009, 05:17:52 PM »
I have tried them, but they don't seem to perform as I want this LISP to... perhaps this cannot be done  :-(

It can be done.   :-)

Just explain to us in words what you want, and I'm sure we can get it.  It you did already, then point me back to it, and we shall see what we can come up with.
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: 12922
  • London, England
Re: Target property in Viewport
« Reply #13 on: July 23, 2009, 05:26:22 PM »
Where there's a will there's a way  :-)

I explained the majority of the problem in reply #5, but if you need further clarification - just shout at me  :-)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Target property in Viewport
« Reply #14 on: July 23, 2009, 06:28:13 PM »
Here you go.  I think it does what you want.

Code: [Select]
(defun c:Testing (/ Sel MnList SecList tempPt tempSc ActDoc)
   
    (if
        (and
            (setq Sel (entsel "\n Select main viewport: "))
            (setq MnList (cons (cdr (assoc 69 (entget (car Sel)))) (vlax-ename->vla-object (car Sel))))
            (setq Sel (entsel "\n Select second viewport: "))
            (setq SecList (cons (cdr (assoc 69 (entget (car Sel)))) (vlax-ename->vla-object (car Sel))))
        )
        (progn
            (vlax-put
                (cdr SecList)
                'Width
                (vlax-get (cdr MnList) 'Width)
            )
            (vlax-put
                (cdr SecList)
                'Center
                (cons
                    (car (vlax-get (cdr MnList) 'Center))
                    (cdr (vlax-get (cdr SecList) 'Center))
                )
            )
            (vlax-put (setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object))) 'MSpace :vlax-true)
            (setvar 'CVport (car MnList))
            (setq tempPt (getvar 'ViewCtr))
            (setvar 'CVport (car SecList))
            (setq tempSc (vlax-get (cdr SecList) 'CustomScale))
            (vlax-invoke
                (vlax-get-Acad-Object)
                'ZoomCenter
                (cons
                    (car tempPt)
                    (cdr (getvar 'ViewCtr))
                )
                1.
            )
            (vlax-put (cdr SecList) 'CustomScale tempSc)
            (vla-put-MSpace ActDoc :vlax-false)
        )
    )
    (princ)
)

Funny thing I just found out.

(vlax-put ActDoc 'MSpace :vlax-false)  -  will Not work, but
(vla-put-MSpace ActDoc :vlax-false)  -  will.
Tim

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

Please think about donating if this post helped you.