Quantcast
Channel: NX Journaling - Journaling / NXOpen API
Viewing all articles
Browse latest Browse all 787

"LookAt", a Journal to Orient View to the Nearest uv Orientation of the Face

$
0
0

This is a Journal that snaps the model view to the NEAREST uv orientation of the planar face.
It is useful when you look at a face that is not in the absolute XYZ orientation.

"Selecting a face then F8" works the same ,but this journal may reduce some keystrokes or mouse clicks.

This is written in c#, not vb.

//This is a journal to snap the model view to the nearest uv orientation of the user selected planar face.//This is useful when the face is not in the absolute XYZ orientation. //2017-7-8 kam 
 
usingSystem;usingNXOpen;usingNXOpen.UF;usingMiniSnap; 
publicclass LookAt
{static Session _theSession = Session.GetSession();static UFSession _theUFSession = UFSession.GetUFSession();static Part _workPart = _theSession.Parts.Work; 
    publicstaticvoid Main(string[] args)//  Program entry point{
        Face face1=MySelect.SelectAPlanarFace("Select a planar face");if(face1!=null){
            UFModl ufmodl = _theUFSession.Modl; 
            //Get surface normal pointing out of the solid. : dirint faceType;double[] facePt =newdouble[3];double[] faceDir =newdouble[3];double[] bbox =newdouble[6];double faceRadius;double faceRadData;int normDirection;
	        ufmodl.AskFaceData(face1.Tag, out faceType, facePt, faceDir, bbox, out faceRadius, out faceRadData, out normDirection);
            Vector dir = faceDir; 
            //Get the range of the surface parameters.double[] uvminmax =newdouble[4];
	        ufmodl.AskFaceUvMinmax(face1.Tag, uvminmax);double umin = uvminmax[0];double vmin = uvminmax[2]; 
            //Get  u,v vector of the surface.
            NXOpen.UF.ModlSrfValue surfaceValue =new NXOpen.UF.ModlSrfValue();int mode = NXOpen.UF.UFConstants.UF_MODL_EVAL_UNIT_NORMAL;
            ufmodl.EvaluateFace(face1.Tag, mode, newdouble[]{umin , vmin}, out surfaceValue);
            Vector u = surfaceValue.srf_du; 
            //review v-direction so that u,v,dir make up right-handed c-sys.
            Vector v = Vector.Cross(dir, u); 
            // "ufmodl.AskFaceProps"  does not return correct u,v direction. IR has been issued already.//"surfaceValue.srf_unormal" does not always point out of the solid. 
            //Get orientation of the work view.
            Orientation oriview =new Orientation(_workPart.ModelingViews.WorkView.Matrix); 
            //among 4 c-sys (u,v),(v,-u),(-u,-v),(-v,u), select the nearest one to the view. : orifacedouble a0 = u * oriview.AxisX+ v * oriview.AxisY;double a1 = v * oriview.AxisX- u * oriview.AxisY;double a2 =-u * oriview.AxisX- v * oriview.AxisY;double a3 =-v * oriview.AxisX+ u * oriview.AxisY;
            Orientation oriface;if((a0 > a1)&&(a0 > a2)&&(a0 > a3))
                oriface =new Orientation(u,v);elseif((a1 > a2)&&(a1 > a3))
                oriface =new Orientation(v,-u);elseif(a2 > a3)
                oriface =new Orientation(-u,-v);else
                oriface =new Orientation(-v,u); 
            _workPart.ModelingViews.WorkView.Orient(oriface);}} 
    publicstaticint GetUnloadOption(string dummy){return(int)Session.LibraryUnloadOption.Immediately;}} 
publicclass MySelect
{publicstatic Face SelectAPlanarFace(string prompt){
        Selection.MaskTriple[] masks =new Selection.MaskTriple[1];
        masks[0].Type= UFConstants.UF_solid_type;
        masks[0].SolidBodySubtype= UFConstants.UF_UI_SEL_FEATURE_PLANAR_FACE;
        TaggedObject selObj =null;
        Point3d cursor;
        Selection.Response resp = UI.GetUI().SelectionManager.SelectTaggedObject(
            prompt, //message"Select a planar face", //title
            Selection.SelectionScope.AnyInAssembly, //scope
            Selection.SelectionAction.ClearAndEnableSpecific, //actionfalse, //includeFeaturesfalse, //keepHighlighted
            masks, //maskArray  out selObj,
            out cursor);return(Face)selObj;}}

Viewing all articles
Browse latest Browse all 787

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>