Author Topic: Synchronize viewports  (Read 4300 times)

0 Members and 1 Guest are viewing this topic.

Jeff H

  • Needs a day job
  • Posts: 6150
Synchronize viewports
« on: September 17, 2010, 06:30:55 AM »
I am not fimiliar at all with lisp and I need to do something very similiar to the Express Tools Synchronize Viewports
I have an idea how to do it but if it is not much trouble could someone briefly explain the logic they used

I removed the code since I do not own it

« Last Edit: September 17, 2010, 10:26:15 AM by fro2001 »

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Synchronize viewports
« Reply #1 on: September 17, 2010, 11:28:51 AM »
Here you go.  Don't usually do this, but just felt like coding.  Didn't see an easy way with just Lisp, so went the ActiveX route.  I'm not sure you could go just Lisp route, as you might have to use ' command ' calls.

Code: [Select]
(defun c:Test ( / AcObj ActDoc Sel MsVp ss cnt Pt Sc Ent Obj )
   
    (vl-load-com)
    (setq AcObj (vlax-get-Acad-Object))
    (setq ActDoc (vla-get-ActiveDocument AcObj))
    (vla-EndUndoMark ActDoc)
    (vla-StartUndoMark ActDoc)
    (if
        (and
            (equal (getvar 'CVport) 1)
            (setq Sel (entsel "\n Select master viewport: "))
            (setq MsVp (vlax-ename->vla-object (car Sel)))
            (= (vla-get-ObjectName MsVp) "AcDbViewport")
            (setq ss (ssget (list '(0 . "VIEWPORT") (cons 410 (getvar 'CTab)))))
            (setq cnt -1)
        )
        (progn
            (setq Pt (vlax-get MsVp 'Center))
            (vla-put-MSpace ActDoc :vlax-true)
            (vla-put-ActivePViewport ActDoc MsVp)
            (setq Pt (trans (trans Pt 3 2) 2 0))
            (setq Sc (vla-get-CustomScale MsVp))
            (while (setq Ent (ssname ss (setq cnt (1+ cnt))))
                (setq Obj (vlax-ename->vla-object Ent))
                (vla-put-ActivePViewport ActDoc Obj)
                (vlax-invoke AcObj 'ZoomCenter Pt 1.0)
                (vla-put-CustomScale Obj Sc)
            )
            (vla-put-MSpace ActDoc :vlax-false)
        )
    )
    (vla-EndUndoMark ActDoc)
    (princ)
)
Tim

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

Please think about donating if this post helped you.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Synchronize viewports
« Reply #2 on: September 18, 2010, 03:22:56 PM »
Thank you so much T.Willey
And I must apologize!
When I first posted it I inserted the lisp code from the vpsync.lsp in the Express folder. And thought maybe someone could look at it real quick and in a couple of sentences explain the logic they used.
But right after I posted it I thought I probably should not have posted the code for legal reasons.
So I removed the code.
But now that I look back at my post I see how it implies that I was asking to write the code for me and I should have explained my post better. I wanted to let you know I did not mean that and I greatly appreciate you taking the time to post the code.

I should have added that I am coding in .NET and was wondering could this logic be explained quickly or if not please reply back it would be to much trouble.

Again thank you and I am sorry

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Synchronize viewports
« Reply #3 on: September 20, 2010, 11:18:29 AM »
No problem.

If you want the logic I used; it is:

Grab the master viewport
Grab the others viewports to adjust
Grab the center point of the master viewport, and translate that from paper space to model space ( which I had to make the viewport active to do it )
Grab the scale of the master viewport
Go into each viewport ( as that is the only way to do it with lisp ) and set the center point and scale ( where the scale is the zoom factor )

As for .Net, I would assume that it could be done, but I have not looked into it at all.
Tim

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

Please think about donating if this post helped you.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Synchronize viewports
« Reply #4 on: September 20, 2010, 12:22:08 PM »
Thanks alot T.Willey I have been looking at LISP and if I am understanding it correctly it seems that translating is alot eaiser in LISP or that the calls to ActiveX are doing all the grunt work for you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Synchronize viewports
« Reply #5 on: September 20, 2010, 12:28:26 PM »
The grunt work is done by the ' trans ' function, as that is really the only grunt work done in the code.  The ActiveX calls are just to zoom without the zoom command, and to put the scale factor of the viewport, which is already known.

Now that I think of it, this code will only sync viewports that have the same view direction.   Didn't think about that before, as I don't usually have different viewports on a sheet anymore.  That might take some code, but not sure.  You might have to change the UCS of the viewports, and then zoom in on them to have them match.
Tim

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

Please think about donating if this post helped you.