.NET

Reply
Valued Contributor
dynamicscope
Posts: 95
Registered: ‎04-04-2012
Message 1 of 9 (471 Views)
Accepted Solution

Changing 3D View to Top View

471 Views, 8 Replies
08-02-2013 02:39 AM

doc.SendStringToExecute("-view\ntop\n", true, false, false);

 

Well, I know this would change the view.

But I need to do this in the middle of some process. (I tried it, but the next step gets executed before view change is done.)

I am changing the view to use SelectWindowPolygon().

So I need to do this by lines of codes. (So that the view change gets done before the next step.)

 

I found a couple solutions but the codes contain some methods that is not supported in ARX 2007.

 

If anyone can give me something I can start with, it would be very appreciated.

 

FYI, I am using ARX 2007 with C#

 

 

ADN Support Specialist
Posts: 352
Registered: ‎07-24-2007
Message 2 of 9 (441 Views)

Re: Changing 3D View to Top View

08-05-2013 02:50 PM in reply to: dynamicscope

Did you see this http://through-the-interface.typepad.com/through_the_interface/2009/02/smoothly-transitioning-betwee...





Fenton Webb

Developer Technical Services

Autodesk Developer Network


Valued Contributor
dynamicscope
Posts: 95
Registered: ‎04-04-2012
Message 3 of 9 (408 Views)

Re: Changing 3D View to Top View

08-12-2013 04:44 AM in reply to: fenton.webb
Yes, I looked at it. It looks little complicated.
I just hoped if there is any easier way to do it. (Since there is a command to do it.)
But I guess it is worth trying...
:smileyhappy:
ADN Support Specialist
Posts: 352
Registered: ‎07-24-2007
Message 4 of 9 (397 Views)

Re: Changing 3D View to Top View

08-12-2013 08:37 AM in reply to: dynamicscope

Yes, there is a command to do it however the smooth view scrolling is disabled in that command if invoked from a script, so it's not so nice :-(





Fenton Webb

Developer Technical Services

Autodesk Developer Network


Valued Contributor
dynamicscope
Posts: 95
Registered: ‎04-04-2012
Message 5 of 9 (379 Views)

Re: Changing 3D View to Top View

08-13-2013 02:59 AM in reply to: fenton.webb

Actually, I do not quite need the animation effect.

I need to change the view to use Editor.SelectWindowPolygon()

 

Well, I came up with this~~

 

Document doc = Application.DocumentManager.MdiActiveDocument;            
Editor ed = doc.Editor;
Manager gsm = doc.GraphicsManager;
int vp = Convert.ToInt32(Application.GetSystemVariable("CVPORT"));
using (View view = gsm.GetGsView(vp, true))
{
	ViewTableRecord v = new ViewTableRecord();	
	v.SetUcs(view.Position, Vector3d.XAxis, Vector3d.YAxis);
	ed.SetCurrentView(v);
}

 

This quite "LOOKS" acting right, but the result is weird.

If I use Editor.SelectWindowPolygon() (with the same polygon), it catches different objects (compared to the result I get by entering "-view top ", then run the Editor.SelectWindowsPolygon() ).

 

I need to check why this is happening.

 

If anyone knows the reason, any comment would be appreciated.

*Expert Elite*
Posts: 1,982
Registered: ‎04-29-2006
Message 6 of 9 (363 Views)

Re: Changing 3D View to Top View

08-13-2013 10:52 AM in reply to: dynamicscope

Hi,

 

You can synchrously call  the VIEW command P/Invoking acedCmd or using the Tony Tanzillo's wrapper for non-public Editor.RunCommand() method.

 

You can also use the following method.

 

        private void SetViewTop()
        {
            Document doc = AcAp.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            Extents3d extents = db.TileMode ?
                new Extents3d(db.Extmin, db.Extmax) :
                (short)Application.GetSystemVariable("CVPORT") == 1 ?
                    new Extents3d(db.Pextmin, db.Pextmax) :
                    new Extents3d(db.Extmin, db.Extmax);

            using (Transaction tr = db.TransactionManager.StartTransaction())
            using (ViewTableRecord view = ed.GetCurrentView())
            {
                Matrix3d WCS2DCS =
                    Matrix3d.Rotation(-view.ViewTwist, view.ViewDirection, view.Target) *
                    Matrix3d.Displacement(view.Target - Point3d.Origin);

                extents.TransformBy(WCS2DCS.Inverse());

                view.ViewDirection = Vector3d.ZAxis;
                view.Width = extents.MaxPoint.X - extents.MinPoint.X;
                view.Height = extents.MaxPoint.Y - extents.MinPoint.Y;
                view.CenterPoint = new Point2d(
                    (extents.MinPoint.X + extents.MaxPoint.X) / 2.0,
                    (extents.MinPoint.Y + extents.MaxPoint.Y) / 2.0);
                ed.SetCurrentView(view);
                tr.Commit();
            }
        }

 

Gilles Chanteau
*Expert Elite*
Posts: 1,982
Registered: ‎04-29-2006
Message 7 of 9 (344 Views)

Re: Changing 3D View to Top View

08-14-2013 11:57 AM in reply to: _gile

I'am glad you solve your probem.

 

Here's a more generic method to set any orthogonal and isometric view and some commands to set these views from the numpad.

 

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;

[assembly: CommandClass(typeof(ViewSample.CommandMethods))]

namespace ViewSample
{
    public class CommandMethods
    {
        enum ViewDirection { Top, Bottom, Front, Back, Left, Right, SeIso, SwIso, NeIso, NwIso }

        private void SetView(ViewDirection vDir)
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            Vector3d viewDir = new Vector3d();
            switch (vDir)
            {
                case ViewDirection.Top:
                    viewDir = Vector3d.ZAxis; break;
                case ViewDirection.Bottom:
                    viewDir = Vector3d.ZAxis.Negate(); break;
                case ViewDirection.Front:
                    viewDir = Vector3d.YAxis.Negate(); break;
                case ViewDirection.Back:
                    viewDir = Vector3d.YAxis; break;
                case ViewDirection.Left:
                    viewDir = Vector3d.XAxis.Negate(); break;
                case ViewDirection.Right:
                    viewDir = Vector3d.XAxis; break;
                case ViewDirection.SeIso:
                    viewDir = new Vector3d(1.0, -1.0, 1.0); break;
                case ViewDirection.SwIso:
                    viewDir = new Vector3d(-1.0, -1.0, 1.0); break;
                case ViewDirection.NeIso:
                    viewDir = new Vector3d(1.0, 1.0, 1.0); break;
                case ViewDirection.NwIso:
                    viewDir = new Vector3d(-1.0, 1.0, 1.0); break;
            }

db.updateext(true); Extents3d extents = db.TileMode ? new Extents3d(db.Extmin, db.Extmax) : (int)Application.GetSystemVariable("CVPORT") == 1 ? new Extents3d(db.Pextmin, db.Pextmax) : new Extents3d(db.Extmin, db.Extmax); using (Transaction tr = db.TransactionManager.StartTransaction()) using (ViewTableRecord view = ed.GetCurrentView()) { Matrix3d viewTransform = Matrix3d.PlaneToWorld(viewDir) .PreMultiplyBy(Matrix3d.Displacement(view.Target - Point3d.Origin)) .PreMultiplyBy(Matrix3d.Rotation(-view.ViewTwist, view.ViewDirection, view.Target)) .Inverse(); extents.TransformBy(viewTransform); view.ViewDirection = viewDir; view.Width = (extents.MaxPoint.X - extents.MinPoint.X) * 1.2; view.Height = (extents.MaxPoint.Y - extents.MinPoint.Y) * 1.2; view.CenterPoint = new Point2d( (extents.MinPoint.X + extents.MaxPoint.X) / 2.0, (extents.MinPoint.Y + extents.MaxPoint.Y) / 2.0); ed.SetCurrentView(view); tr.Commit(); } } [CommandMethod("0")] public void ViewBottom() { SetView(ViewDirection.Bottom); } [CommandMethod("1")] public void ViewSouthWestIso() { SetView(ViewDirection.SwIso); } [CommandMethod("2")] public void ViewFront() { SetView(ViewDirection.Front); } [CommandMethod("3")] public void ViewSeIso() { SetView(ViewDirection.SeIso); } [CommandMethod("4")] public void ViewLeft() { SetView(ViewDirection.Left); } [CommandMethod("5")] public void ViewTop() { SetView(ViewDirection.Top); } [CommandMethod("6")] public void ViewSouthEastIso() { SetView(ViewDirection.Right); } [CommandMethod("7")] public void ViewNorthWestIso() { SetView(ViewDirection.NwIso); } [CommandMethod("8")] public void ViewBack() { SetView(ViewDirection.Back); } [CommandMethod("9")] public void ViewNorthEastIso() { SetView(ViewDirection.NeIso); } } }

 

Gilles Chanteau
Valued Contributor
jaboone
Posts: 85
Registered: ‎12-05-2011
Message 8 of 9 (336 Views)

Re: Changing 3D View to Top View

08-14-2013 12:35 PM in reply to: _gile

There is one command I use all the time to out of 3d and back to my current usc, or back to original world.  This always puts me back on track.

PLAN

Learning as I go
Active Member
Posts: 7
Registered: ‎07-25-2013
Message 9 of 9 (250 Views)

Re: Changing 3D View to Top View

09-16-2013 02:36 AM in reply to: jaboone

Hi! I found the code posted by _gile very interesting; is there a way to set these fixed views on an offscreen device? Device.Add() accepts GraphicsSystem.View objects that are quite different from ViewTableRecord objects so I can't understand how to do the same calculations.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community