static void UFInitParams(ref UFFacet.Parameters __params) { (__params).version = UF_FACET_PARAM_VERSION_CURR; (__params).max_facet_edges = 3; (__params).specify_surface_tolerance = false; (__params).surface_dist_tolerance = 0.0; (__params).surface_angular_tolerance = 0.0; (__params).specify_curve_tolerance = false; (__params).curve_dist_tolerance = 0.0; (__params).curve_angular_tolerance = 0.0; (__params).curve_max_length = 1000.0; (__params).specify_convex_facets = true; (__params).specify_max_facet_size = false; (__params).max_facet_size = 0.0; (__params).number_storage_type = 1; (__params).specify_parameters = false; (__params).specify_view_direction = false; (__params).silh_view_direction = new double[3]; (__params).silh_view_direction[0] = 0.0; (__params).silh_view_direction[1] = 0.0; (__params).silh_view_direction[2] = 1.0; (__params).silh_chord_tolerance = 0.0; (__params).store_face_tags = false; }
public int Execute() { Tag UFPart; string part_name = "EX_Modl_CreateBlend"; int units = 2; string name; theUfSession.Part.New(part_name, units, out UFPart); theUfSession.Part.AskPartName(UFPart, out name); w.WriteLine("Loaded: " + name); Tag block_tag; Tag[] list1; double[] corner_point = new double[3]; string[] edge_lengths = { "1.0", "2.0", "3.0" }; Tag block_feature_tag; UFFacet.Parameters faceting_params = new UFFacet.Parameters(); int ecount; Tag blend1; Tag[] list2; double[] pt1 = { 0.0, 0.0, 0.0 }; double[] pt2 = { 0.0, 0.0, 0.0 }; int allow_smooth = 0; int allow_cliff = 0; int allow_notch = 0; double vrb_tol = 0.0; /* First create a UFPart in which we will initially create a * block.*/ theUfSession.Assem.SetWorkPart(UFPart); corner_point[0] = 0.0; corner_point[1] = 0.0; corner_point[2] = 0.0; theUfSession.Modl.CreateBlock1(FeatureSigns.Nullsign, corner_point, edge_lengths, out block_feature_tag); theUfSession.Modl.AskFeatBody(block_feature_tag, out block_tag); /* Get the edges of the body. Get the count of the edge list. * This will be used to get the four 'vertical' corners of the block for * blending. Check return codes. */ theUfSession.Modl.AskBodyEdges(block_tag, out list1); theUfSession.Modl.AskListCount(list1, out ecount); ArrayList arr_list2 = new ArrayList(); for (int i = 0; i < ecount; i++) { Tag edge; /* edge object */ int vcount; /* count of vertices in edge */ /* Get the edge (list item) and check return code. */ theUfSession.Modl.AskListItem(list1, i, out edge); /* Get the edge vertices. Check return code. */ theUfSession.Modl.AskEdgeVerts(edge, pt1, pt2, out vcount); if (System.Math.Abs(System.Math.Abs(pt1[2] - pt2[2]) - 3.0) < 0.001) { arr_list2.Add(edge); } } list2 = (Tag [])arr_list2.ToArray(typeof(Tag)); theUfSession.Modl.CreateBlend("0.009246", list2, allow_smooth, allow_cliff, allow_notch, vrb_tol, out blend1); theUfSession.Part.Save(); return(0); }
static List <Snap.Position> GetFacePoints(Snap.NX.Face face, ProbeData data, double max_facet_size = 1) { var mark = Snap.Globals.SetUndoMark(Globals.MarkVisibility.Visible, "GetFacePoints"); var positions = new List <Snap.Position>(); #region old code var parameters = new UFFacet.Parameters(); var ufSession = NXOpen.UF.UFSession.GetUFSession(); var facet = ufSession.Facet; facet.AskDefaultParameters(out parameters); parameters.max_facet_edges = 3; parameters.specify_max_facet_size = true; parameters.max_facet_size = 1; NXOpen.Tag facet_model = NXOpen.Tag.Null; facet.FacetSolid(face.NXOpenTag, ref parameters, out facet_model); if (facet_model == NXOpen.Tag.Null) { return(positions); } NXOpen.Tag solid = NXOpen.Tag.Null; facet.AskSolidOfModel(facet_model, out solid); if (solid != face.NXOpenTag) { return(positions); } int facet_id = NXOpen.UF.UFConstants.UF_FACET_NULL_FACET_ID; bool isWhile = true; while (isWhile) { facet.CycleFacets(facet_model, ref facet_id); if (facet_id != NXOpen.UF.UFConstants.UF_FACET_NULL_FACET_ID) { int num_vertices = 0; facet.AskNumVertsInFacet(facet_model, facet_id, out num_vertices); if (num_vertices == 3) { var vertices = new double[num_vertices, 3]; facet.AskVerticesOfFacet(facet_model, facet_id, out num_vertices, vertices); for (int i = 0; i < num_vertices; i++) { int pt_status = 0; var position = new Snap.Position(vertices[i, 0], vertices[i, 1], vertices[i, 2]); ufSession.Modl.AskPointContainment(position.Array, face.NXOpenTag, out pt_status); if (0x1 == pt_status || 0x3 == pt_status) { positions.Add(position); } } } } else { isWhile = false; } } ufSession.Obj.DeleteObject(facet_model); positions = positions.Distinct().ToList(); #endregion var edges = face.EdgeCurves.ToList(); //过滤小于探球半径的点 foreach (var item in positions.ToList()) { if (IsLessthanProbeR(edges, item, data)) { positions.Remove(item); } } Snap.Globals.UndoToMark(mark, null); return(positions); }
/// <summary> /// 获取面上所有的测量点 /// </summary> public static List <Snap.Position> GetFacePoints(Snap.NX.Face face, double max_facet_size = 1) { //var mark = Snap.Globals.SetUndoMark(Globals.MarkVisibility.Invisible, "GetFacePoints"); var positions = new List <Snap.Position>(); try { #region old code var parameters = new UFFacet.Parameters(); var ufSession = NXOpen.UF.UFSession.GetUFSession(); var facet = ufSession.Facet; facet.AskDefaultParameters(out parameters); parameters.max_facet_edges = 3; parameters.specify_max_facet_size = true; parameters.max_facet_size = max_facet_size; NXOpen.Tag facet_model = NXOpen.Tag.Null; facet.FacetSolid(face.NXOpenTag, ref parameters, out facet_model); if (facet_model == NXOpen.Tag.Null) { return(positions); } NXOpen.Tag solid = NXOpen.Tag.Null; facet.AskSolidOfModel(facet_model, out solid); if (solid != face.NXOpenTag) { return(positions); } int facet_id = NXOpen.UF.UFConstants.UF_FACET_NULL_FACET_ID; bool isWhile = true; while (isWhile) { facet.CycleFacets(facet_model, ref facet_id); if (facet_id != NXOpen.UF.UFConstants.UF_FACET_NULL_FACET_ID) { int num_vertices = 0; facet.AskNumVertsInFacet(facet_model, facet_id, out num_vertices); if (num_vertices == 3) { var vertices = new double[num_vertices, 3]; facet.AskVerticesOfFacet(facet_model, facet_id, out num_vertices, vertices); for (int i = 0; i < num_vertices; i++) { int pt_status = 0; var position = new Snap.Position(vertices[i, 0], vertices[i, 1], vertices[i, 2]); //if (isRoundInt&&face.ObjectSubType==Snap.NX.ObjectTypes.SubType.FacePlane) //{ // position = new Snap.Position(System.Math.Round(position.X, 2), System.Math.Round(position.Y, 2), System.Math.Round(position.Z, 2)); //} ufSession.Modl.AskPointContainment(position.Array, face.NXOpenTag, out pt_status); if (0x1 == pt_status || 0x3 == pt_status) { positions.Add(position); } } } } else { isWhile = false; } } ufSession.Obj.DeleteObject(facet_model); positions = positions.Distinct().ToList(); #endregion } catch (Exception ex) { Console.WriteLine(ex.Message); //Snap.Globals.UndoToMark(mark, null); } return(positions); }
static int example1(out Tag new_faceted_model) { //int ifail; double[] corner_point = new double[3]; string[] edge_lengths = { "10", "30", "40" }; Tag block_feature_tag; Tag block_tag; Tag faceted_model; bool up_to_date = true; Tag blend_feature; //UfList edge_list; // = null; Tag[] edge_list; Tag tag_of_solid; int i; Tag[] facet_models; int n_facet_models; UFFacet.Parameters faceting_params = new UFFacet.Parameters(); new_faceted_model = Tag.Null; corner_point[0] = 0.0; corner_point[1] = 0.0; corner_point[2] = 0.0; theUfSession.Modl.CreateBlock1(FeatureSigns.Nullsign, corner_point, edge_lengths, out block_feature_tag); theUfSession.Modl.AskFeatBody(block_feature_tag, out block_tag); UFInitParams(ref faceting_params); theUfSession.Facet.AskDefaultParameters(out faceting_params); theUfSession.Facet.FacetSolid(block_tag, ref faceting_params, out faceted_model); if (faceted_model != Tag.Null) { theUfSession.Facet.AskSolidOfModel(faceted_model, out tag_of_solid); if (block_tag != tag_of_solid) { w.WriteLine("**ERR: Failed find solid from facet model\n"); return(1); } theUfSession.Facet.AskModelsOfSolid(block_tag, out n_facet_models, out facet_models); /* * Just check that the association between the solid and * the new faceted model has been established. */ for (i = 0; i < n_facet_models; i++) { if (facet_models[i] == faceted_model) { w.WriteLine("Faceted model is attached to solid\n"); } } //UF_free( facet_models ); /* * Now blend all of the edges of the block. */ theUfSession.Modl.AskBodyEdges(block_tag, out edge_list); theUfSession.Modl.CreateBlend("2.0", edge_list, 0, 0, 0, 0.0, out blend_feature); /**************************************/ //This method is not mapped...// /**************************************/ //UF_MODL_delete_list( &edge_list ); theUfSession.Modl.Update(); theUfSession.Facet.IsModelUpToDate(faceted_model, out up_to_date); if (up_to_date) { w.WriteLine("**ERR: Faceted model is up to date\n"); return(1); } theUfSession.Facet.AskModelParameters(faceted_model, out faceting_params); /* * Set the number of sides for facets to four and use that * when refaceting the solid. */ faceting_params.max_facet_edges = 4; theUfSession.Facet.UpdateModel(faceted_model, ref faceting_params); theUfSession.Facet.IsModelUpToDate(faceted_model, out up_to_date); if (!up_to_date) { w.WriteLine("**ERR: Model is not up to date\n"); return(1); } /* * Finally, disassociate the faceted model from * the generating solid. */ theUfSession.Facet.DisassocFromSolid(faceted_model); new_faceted_model = faceted_model; } else { return(1); } return(0); }