Jump to content

Rotate View in Viewports


SteveK

Recommended Posts

Good afternoon,

 

I'm wanting to rotate a view within a viewport with a lisp. The viewport will be at differing centers and possibly differing scales. I'm wanting to keep the scale intact.

 

If I can get help will this part then all I want to add to the program (which I can do) is user input for 2 points within modelspace which will serve as my angle.

 

I thought it would have something to do with a ucs variable but I can't find it.

 

Thankyou

Link to comment
Share on other sites

Hey, thanks for the direction. I had a look through aspace.lsp, and I find it pretty hard to understand it (specifically the alignspace function). I could be wrong but it seems the command that affects the rotation is acet-ucs-cmd but what's that do?!

As an aside: why do us users never use acet- functions? Why is it only inhouse use? No help files..

It's the first time I've seen the trans function which sounds useful.

 

I also had a look in mvsetup.lsp, specifically the Align viewport geometry section, but it's a bit of a cop-out, it just uses the dview command.

 

Any other help with viewport rotation would be greatly appreciated..

Link to comment
Share on other sites

acet-* functions are the Express tools functions.

 

Some can be useful - such as acet-sys-shift-down, to detect for a shift keypress for example, - but they have obvious limitations, as not all machines have ET loaded. Also, it has been argued that some are badly written.

 

To get more info on them see here:

 

http://www.afralisp.net/lisp/acet-utils.htm

A whole list of them

 

More undocumented stuff.

More Swamp stuff

And some more

Link to comment
Share on other sites

Here's a little routine made with the help of people on this forum. It's doesn't rotate a viewport the way you would like though (in fact, this routine doesn't work reliably when the view is rotated from the WCS). It might contain elements you might find usefull though.

What the routine does, it starts with a viewport, unlocks it, rotates the ucs 180deg around Y-axis, sets the view to that UCS, then returns the view back to its original position (i.e. same view center and scale), and locks the viewport again.

We use this for detailing mirrored components:

 

 
(defun C:VPF (/ vc vs ve)
(initerror)
(setvar "cmdecho" 0)
(command "undo" "mark")
(command "_.undo" "_begin")
(command "UCS" "world")
(setq vc (getvar "VIEWCTR")
vs (getvar "VIEWSIZE")
ve (trans '(0 0 1) 0 1))
(command "_.VPORTS" "_L" "_OFF" "_ALL" "")
(command "_.UCS" "_Y" 180
"_.PLAN" "_C"
"_.ZOOM" "_C" (trans vc ve 1) vs)
(command "_.VPORTS" "_L" "_ON" "_ALL" "")
(command "_.undo" "_end")
(setvar "cmdecho" 1)
(princ)
)

Link to comment
Share on other sites

Good afternoon,

 

I'm wanting to rotate a viewport with a lisp. The viewport will be at differing centers and possibly differing scales. I'm wanting to keep both of these values intact.

 

If I can get help will this part then all I want to add to the program (which I can do) is user input for 2 points within modelspace which will serve as my angle.

 

I thought it would have something to do with a ucs variable but I can't find it.

 

Thankyou

 

In the title you say Rotate view in viewports.. but in the post content you say Rotate viewports... I understand the view as the way the objects appear to our eyes... and the viewport is the object that allows us to see those objects... So I think you said one thing in the title and another different in your post content.

 

For the case of rotating the view I use a lisp that I think I renamed to DVA.lsp (dview -- align) to align the view of a viewport to a selected line. (attached)

 

For the other case, I guess we all know that If you rotate the viewport the view remains, then a lisp would be necessary for kind of lock the viewport and allow it to rotate the viewport object itself. There must be some sort of similar ways to do that by copying the viewport polyline and apply a mview - object to fint the same viewport but rotated , i think I've seen some routines around to match a viewport scale and rotation to another, but I didn´t even download it... I considered it useless. that's maybe what this case requires.

Dva.lsp

Link to comment
Share on other sites

I guess we all know that If you rotate the viewport the view remains, then a lisp would be necessary for kind of lock the viewport and allow it to rotate the viewport object itself.

 

In AutoCAD 2010 you now get the option to rotate a viewport, and have the view come with it:

http://autodesk.blogs.com/between_the_lines/2009/05/autocad-2010-rotate-layout-view-with-viewport-like-a-ninja.html

 

It might just do the trick, but it would make for a messy Layout with rectangular viewports rotated at funny angles. I've kept this functionality quiet in this office, too afraid to think what our drawings will end up looking like when people find out about it.

Link to comment
Share on other sites

In AutoCAD 2010 you now get the option to rotate a viewport, and have the view come with it:

http://autodesk.blogs.com/between_the_lines/2009/05/autocad-2010-rotate-layout-view-with-viewport-like-a-ninja.html

 

It might just do the trick, but it would make for a messy Layout with rectangular viewports rotated at funny angles. I've kept this functionality quiet in this office, too afraid to think what our drawings will end up looking like when people find out about it.

 

 

Orale!!!

 

All done then

Link to comment
Share on other sites

Hey DVDM thanks for the help. That lisp really stuffs up my viewport hehe. It flips everything inside out. :D And I'm back to being confused about the trans function..

 

And thanks for the tips Lee. (I can't view the swamp attachment can everything else).

 

Gilsoto, sorry I'll fix up the post. I mean the view.

 

Anyways I've had a go making something:

;|
Purpose:
First it asks the User to select the viewport, then asks User for two points within the viewport.
It then centers the viewport between those two points
and rotates the view so as to have an imaginary line between the two points as the horizontal plane.
It keeps the same scale as before.
|;
(defun c:r1 (/ doc app en obj
        scl pt1 pt2 mid_pt ang)
 (vl-load-com)

 (If (OR (= (getvar "TILEMODE") 1)
     (NOT (= (getvar "CVPORT") 1)))
   (Progn
     (princ "Must be in paperspace first.\n")
     (exit)))

 (setq doc (vla-get-activedocument
         (setq app (vlax-get-acad-object)))
   en (car(entsel "Select Viewport...\n")))

 (If (eq (cdr(assoc 0 (entget en))) "VIEWPORT")
   (Progn
     
     (setq obj (vlax-ename->vla-object en)
       scl (vla-get-CustomScale obj))
     (vla-put-Displaylocked obj :vlax-false)
     (vla-put-MSpace doc :vlax-true)
     (setvar "CVPORT" (cdr (assoc 69 (entget en))))
     (setq pt1 (getpoint "Pick First Point: \n")
       pt2 (getpoint "Pick Second Point: \n")
       mid_pt (list (/ (+ (car pt1) (car pt2)) 2)
            (/ (+ (cadr pt1) (cadr pt2)) 2)
            0.)
       ang (* (angle pt1 pt2) (/ 180 pi) -1)
       )
     (command "_.DVIEW" "" "_TW" ang "")
     (vla-ZoomCenter app
   (vlax-3D-point mid_pt) 1.)
     (vla-put-CustomScale obj scl)
     (vla-put-MSpace doc :vlax-false)
     (vla-put-Displaylocked obj :vlax-true)
     
     )(princ "Selection not a viewport.\n"))

 (princ)
 )

As you've noticed I went the easy path and went with dview. :cry: So it's a bit of a cheap way to go about it but for the moment it seems to work alright. By all means post improvements, and if you find use for it please comment.

Link to comment
Share on other sites

The trans function is a pretty useful bit of kit :)

 

You can convert any point/displacement vector to any UCS/OCS/WCS.

 

For example, the entmake methods use points in WCS, hence, if prompting for a user to select a point, you can allow for the user not being in WCS by using trans:

 

(defun c:test (/ pt)
 (if (setq pt (getpoint "\nSelect a Point: "))  ;; Point in UCS

   (progn

     (setq pt (trans pt 1 0))  ;; TRANSlate the point to WCS

     (entmake
       (list
         (cons 0 "CIRCLE")
         (cons 10 pt)
         (cons 40 1)))))

 (princ))

But, you can also use an entity name (for translating between OCS/WCS), and an extrusion vector (normal to the plane).

 

Interesting stuff.

Link to comment
Share on other sites

I think I might be struggling getting UCS and WCS and not the trans function. Can you give a simple example of when you might use the above entmake? I'm guessing working in 3D you'd have differing UCS to WCS but all I ever change the UCS for is in viewports and that is only scale and rotation.

Thanks

Link to comment
Share on other sites

Ok, simple example, comment out the line in the above code that uses trans.

 

Set UCS to World, View to Top (standard x-y plane).

 

Use "test" to draw your circle, all is normal.

 

Now, rotate the UCS about the Z-Axis by 45deg (UCS>Z>45)

 

And use Test to draw your circle.

 

Report back on results of before and after commenting the trans :)

Link to comment
Share on other sites

Ok I see what you mean; With the trans function commented out, if I click a point along a 45-degree Y-axis it will appear along a vertical Y-axis because the UCS y-axis is vertical. (sorry I'm stating the obvious).

Thanks.

 

 

The main thread question is still open if anyone knows a better way than using a standard command (eg dview).

It's not so much to solve this particular problem (cause dview does the job), but more so to open up other ways of manipulating viewports.

Link to comment
Share on other sites

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