Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

View Frame Rotation (C3D .NET API)

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
chriskroll
902 Views, 5 Replies

View Frame Rotation (C3D .NET API)

I am trying to get the rotation of each view frame in a group.  I can't find any "rotation" or "transform" properties that are exposed in the ViewFrame class.  Is there any way that I can do this?

 

Thank you

 

Here is the code I am using to get information about the viewframes.  I also included the test files I am using.

 

[CommandMethod("ListViewFrames")]
        public void listVFrames()
        {
            CivilDocument cdoc = CivilApplication.ActiveDocument;
            
            // Get editor for command line output
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            // Document Database
            Database acDB = doc.Database;


            ObjectIdCollection FGGIDs = cdoc.GetViewFrameGroupIds();

            ed.WriteMessage("Object Class: " + FGGIDs[0].ObjectClass.DxfName + " ::: ");

            using (Transaction trans = acDB.TransactionManager.StartTransaction())
            {
                ViewFrameGroup vfg = trans.GetObject(FGGIDs[0], OpenMode.ForRead) as ViewFrameGroup;
                ObjectIdCollection vFrameIDs = vfg.GetViewFrameIds();

                ed.WriteMessage("\nFrame Count: " + vFrameIDs.Count);

                foreach (ObjectId vfID in vFrameIDs)
                {
                    ViewFrame vf = trans.GetObject(vfID, OpenMode.ForWrite) as ViewFrame;
                    
                    ed.WriteMessage("\nName: " + vf.Name + " Display Name: " + vf.DisplayName);
                }
            }
            
        }

 

Tags (2)
5 REPLIES 5
Message 2 of 6

I'd explode the view frames and then examine the long line in the collected exploded items to figure out the rotation. I'd do this outside of transaction that was committed to not affect the one in the drawing.

Civil Reminders
http://blog.civil3dreminders.com/
http://www.CivilReminders.com/
Alumni
Message 3 of 6

As Chris mentioned, something like this should work. It is very simplistic and is only guaranteed to work for the sample drawing provided. You will want to make it more robust (creating a new style for the viewframes so you know exactly what objects will be created, checking the type of each of the object you are exploding, exiting out of the loops once you find the correct line, etc). Since you weren't commiting the transaction anyway, I didn't bother starting a second transaction.

 

[CommandMethod( "ListViewFrames" )]
public void listVFrames()
{
  var cdoc = CivilApplication.ActiveDocument;
  var doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
  var ed = doc.Editor;
  var acDB = doc.Database;

  var FGGIDs = cdoc.GetViewFrameGroupIds();

  ed.WriteMessage( "Object Class: {0} ::: ", FGGIDs[0].ObjectClass.DxfName );

  using ( var trans = acDB.TransactionManager.StartTransaction() )
  {
    var vfg = trans.GetObject( FGGIDs[0], OpenMode.ForRead ) as ViewFrameGroup;
    var vFrameIDs = vfg.GetViewFrameIds();

    ed.WriteMessage( "{0}Frame Count: {1}", System.Environment.NewLine, vFrameIDs.Count );

    foreach ( ObjectId vfID in vFrameIDs )
    {
      var vf = (ViewFrame)trans.GetObject( vfID, OpenMode.ForWrite );
      var expSet = new DBObjectCollection();
      vf.Explode( expSet ); // explode to block
      var rot = double.NaN;
      foreach ( Entity ent in expSet )
      {
        var expSet1 = new DBObjectCollection();
        ent.Explode( expSet1 ); // explode to polyline
        foreach ( Entity ent1 in expSet1 )
        {
          var expSet2 = new DBObjectCollection();
          ent1.Explode( expSet2 ); // explode to lines
          foreach ( Entity ent2 in expSet2 )
          {
            if ( typeof( Line ) == ent2.GetType() )
            {
              var l = (Line)ent2; // the first line is the top line of frame drawn left to right
              rot = l.Angle;
              break; // break after the first line
            }
          }
        }
      }
      ed.WriteMessage( "{0}Name: {1} Display Name: {2} Rotation: {3}", System.Environment.NewLine, vf.Name, vf.DisplayName, rot.ToString( "F6" ) );
    }
  }
}

 

Message 4 of 6
joantopo
in reply to: tyronebk

good snippet code.

I´m doing my own command for Civil 3D 2015:

 

http://www.mediafire.com/download/aq9gbtwwfenzixg/PaginasEje_C3D+2015.dll

 

command: paginasEje.

 

But it has different criteria. However, I understood criteria of Civil 3D to create viewframes and perhaps I will include it.

Autocad C3D 2019 SP3, 2020 & 2021
Intel I9 9900K with frontal watercooler alphacool eisbaer 360 (original fans mounted in pull)- 3 fans Corsair 120 ML PRO in push.
MOBO Gygabyte Z390 Aorus Master- Corsair RGB Vengeance 64GB RAM (4x16) CL16
Nvidia Quadro RTX 4000
Samsung 970 EVO PLUS 1TB (unit C). Samsung 970 PRO 512GB (for data)
Power Supply: Corsair TX850M PLUS


Descubre mi programa VisorNET para Civil 3D:
https://apps.autodesk.com/CIV3D/es/Detail/Index?id=appstore.exchange.autodesk.com%3avisornet_windows32and64%3aes
Message 5 of 6
chriskroll
in reply to: tyronebk

Thank you, this will work for my current problem.

Message 6 of 6
keith_sowinski
in reply to: tyronebk

I tried this using Civil 3D 2020.  When I explode the view frame object, it results in a line that follows the z axis and is nowhere near the original view frame.  However, when using the explode command, I get expected results.  

 

Is your code working as expected in more recent versions of Civil 3D?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


 

Autodesk Design & Make Report