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); } } }
Solved! Go to Solution.
Solved by tyronebk. Go to Solution.
Solved by Civil3DReminders_com. Go to Solution.
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.
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" ) ); } } }
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.
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?