// NX 9.0.3.4 // Journal created by Steph on Fri Feb 10 23:57:55 2017 Eastern Standard Time // using System; using System.Collections.Generic; using NXOpen; using NXOpen.BlockStyler; using NXOpen.CAM; using NXOpen.UF; public class NXJournal { public static void Main(string[] args) { Session theSession = Session.GetSession(); UI theUI = UI.GetUI(); UFSession theUfSession = UFSession.GetUFSession(); // ---------------------------------------------- // Menu: Tools->Journal->Stop Recording // ---------------------------------------------- //get all faces Part workPart = theSession.Parts.Work; List faceList = new List(); foreach (Body body in workPart.Bodies) { faceList.AddRange(body.GetFaces()); } List faceTagList = faceList.ConvertAll(face => (face.Tag)); //WCS Tag wcs = Tag.Null; theUfSession.Csys.AskWcs(out wcs); Tag mtxId = Tag.Null; double[] origin = new double[3]; theUfSession.Csys.AskCsysInfo(wcs, out mtxId, origin); double[] mtx33 = new double[9]; theUfSession.Csys.AskMatrixValues(mtxId, mtx33); double[] mtx44 = new double[] { mtx33[0],mtx33[3],mtx33[6],origin[0], mtx33[1],mtx33[4],mtx33[7],origin[1], mtx33[2],mtx33[5],mtx33[8],origin[2], 0,0,0,1 }; double[] mtx44Invert = new double[16]; theUfSession.Mtx4.Invert(mtx44, mtx44Invert); //cal ListingWindow lw = theSession.ListingWindow; lw.Open(); string str = "number of faces:" + faceTagList.Count.ToString() ; lw.WriteLine(str); lw.WriteLine("starting time:" + DateTime.Now.ToString("yyyy - MM - dd HH:mm:ss:fff")); double[] xyzMinW = new double[] { 10000, 10000, 10000 }; double[] xyzMaxW = new double[] { -10000, -10000, -10000 }; double[] minCorner = new double[3]; double[] distances = new double[3]; double[,] directions = new double[3, 3]; foreach (Tag face in faceTagList) { theUfSession.Modl.AskBoundingBoxAligned(face, Tag.Null, false, minCorner, directions, distances); theUfSession.Mtx4.Vec3Multiply(minCorner, mtx44Invert, minCorner); for (int i = 0; i < 3; i++) { xyzMinW[i] = Math.Min(minCorner[i], xyzMinW[i]); } for (int i = 0; i < 3; i++) { xyzMaxW[i] = Math.Max(minCorner[i] + distances[i], xyzMaxW[i]); } } lw.WriteLine(DateTime.Now.ToString("ending time:" + "yyyy - MM - dd HH:mm:ss:fff")); //length double[] length = new double[] { Math.Abs(xyzMaxW[0]-xyzMinW[0]), Math.Abs(xyzMaxW[1]-xyzMinW[1]), Math.Abs(xyzMaxW[2]-xyzMinW[2]) }; string[] lengthStr = new string[] { length[0].ToString(), length[1].ToString(), length[2].ToString() }; //create a box Tag featureTag = Tag.Null; double[] xyzMin = new double[3]; theUfSession.Mtx4.Vec3Multiply(xyzMinW, mtx44, xyzMin); theUfSession.Modl.CreateBlock1(FeatureSigns.Nullsign, xyzMin, lengthStr, out featureTag); Tag box = Tag.Null; theUfSession.Modl.AskFeatBody(featureTag, out box); theUfSession.Obj.SetTranslucency(box, 80); } public static int GetUnloadOption(string dummy) { return (int)Session.LibraryUnloadOption.Immediately; } }