Author Topic: Rotating an existing Viewport in Paperspace  (Read 2748 times)

0 Members and 1 Guest are viewing this topic.

kyle

  • Guest
Rotating an existing Viewport in Paperspace
« on: March 07, 2016, 09:27:35 PM »
Hello all,  :-)
I am having a slight problem in my C# NET code and I am hoping someone can point me in the right direction.
So far I have successfully written code to take a polyline from modelspace and use it to create a clipped viewport of the area in a new layout.
My problem arises when I try to rotate this viewport afterwards (if it is taller than it is wide).

Here is a snippet of the code after I have opened the viewport for write within the transaction...
note: 'pl' is a polyline in paper space that has been scaled from the original polyline in modelspace

Code - C#: [Select]
  1.                 acVport.ViewDirection = new Vector3d(0, 0, 1);
  2.                 acVport.CenterPoint = new Point3d(centerPoint.X, centerPoint.Y, 0);
  3.                 acVport.CustomScale = 0.01;
  4.                 pl.TransformBy(Matrix3d.Displacement(pSpaceDisplacementVector));
  5.                 acBlkTblRec.AppendEntity(pl);
  6.                 acTrans.AddNewlyCreatedDBObject(pl, true);
  7.  
  8.                 acVport.NonRectClipEntityId = pl.ObjectId;
  9.                 acVport.NonRectClipOn = true;
  10.                 acVport.ViewCenter = new Point2d(modelCenter.X, modelCenter.Y);
  11.  
  12.                 bool landscapeOriented = (acVport.Bounds.Value.MaxPoint.X - acVport.Bounds.Value.MinPoint.X) >= (acVport.Bounds.Value.MaxPoint.Y - acVport.Bounds.Value.MinPoint.Y);
  13.                 if (!landscapeOriented)
  14.                 {
  15.                     acDoc.Editor.WriteMessage("Rotating Viewport... (90 deg CC)\n");
  16.                     Matrix3d acMat3d = Matrix3d.Rotation(Math.PI / 2.0, Vector3d.ZAxis, acVport.Bounds.Value.MinPoint);
  17.                     acVport.TransformBy(acMat3d);
  18.                 }
  19.  

after this, the transaction commits and everything works as expected except for the final transformation (the 90 degree rotation). The editor does spit out the message "Rotating Viewport... (90 deg CC)", so I know the block is being executed. Does anyone know why this transformation is not actually happening to the paper-space viewport? Any advice is greatly appreciated!

EDIT: I realize that I need to transform the polyline that acts as the non-rectangular clip, but I am not sure how to apply this transformation without messing up the viewport. (I want to rotate them both at the same time, so that NORTH appears WEST in paperspace). I also tried to use acVport.SetUcs() to change the x and y axes but the ucs was not changed.
« Last Edit: March 08, 2016, 12:10:29 PM by kyle »

kyle

  • Guest
Re: A problem with transforming an existing Viewport in paperspace
« Reply #1 on: March 08, 2016, 12:04:03 PM »
My problem was solved by the user gile in the Autocad Developer Network Open NET forum...

Solution was simple:

"Did you try to change the Viewport.TwistAngle value ?"

Code - C#: [Select]
  1. double rotation = -Math.PI / 2.0;
  2. viewport.TwistAngle += rotation;
  3. viewport.ViewCenter = viewport.ViewCenter.TransformBy(Matrix2d.Rotation(rotation, Point2d.Origin));

Thanks, gile!

Jeff H

  • Needs a day job
  • Posts: 6151
Re: Rotating an existing Viewport in Paperspace
« Reply #2 on: March 08, 2016, 04:48:39 PM »
Welcome Kyle!

Gile has a habit of posting really good stuff.

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Rotating an existing Viewport in Paperspace
« Reply #3 on: March 10, 2016, 08:28:36 AM »
Gile has a habit of posting really good stuff.


I personally think that Gile should write a Programming AutoCAD with C# book.
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

ChrisCarlson

  • Guest
Re: Rotating an existing Viewport in Paperspace
« Reply #4 on: March 10, 2016, 08:50:01 AM »
Gile has a habit of posting really good stuff.


I personally think that Gile should write a Programming AutoCAD with C# book.

I'd brush up on my french for that one