cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

Translate the entire conversation x

Smallest Distance Calculation

Aravind_98
6-Contributor

Smallest Distance Calculation

Hi team

 

I have a doubt regarding how to calculate the smallest distance between edges using the toolkit. This is specifically for a sheet metal part.

Does anyone know how to accurately calculate the edge-to-edge distances or if there’s any workaround available for this? Any help or guidance would be greatly appreciated.

I've attached the image for your reference.

4 REPLIES 4
FabianWolf
14-Alexandrite
(To:Aravind_98)

Hello,

 

from the Creo/Toolkit documentation:

 

The function ProSelectionWithOptionsDistanceEval() evaluates the distance between two items. You can evaluate distance between surfaces, edges, entities, vertices, curves, datums, and so on. The initial selection of the item is used to guess the type of geometry. In case of error types PRO_TK_BAD_INPUTS or PRO_TK_BAD_CONTEXT, the output argument p_result is set to -1.0 and all parameters are set to 0.0.
The input arguments option1 and option2 are analogous to Options in the Measure dialog box in Creo Parametric user interface. You can specify PRO_B_TRUE if you want to turn on the following options for the selected items:

 

  • If the selected item is a cylindrical surface, measures the distance from the central axis of the cylindrical surface. Specify PRO_B_FALSE to measure from the surface instead of the axis.
  • If the selected item is an arc, measures the distance from the center of a circle or an arc-shaped curve or edge. Specify PRO_B_FALSE to measure from the edge instead of the center.
  • If the selected item is a planar surface or a plane, extends the selected surface or plane to infinity in both directions only for the purpose of measuring distance. You can now measure the distance normal to the reference entity.
  • If the selected item is linear, extends the selected straight edge or curve to infinity in both directions only for the purpose of measuring distance. You can now measure the distance normal to the reference entity.

The output arguments return the following values:

 

  • p_result—Distance between the two items
  • pnt_1 and pnt_2—Critical point for the first and second selected items. Critical point is the actual point used for measurement.
  • param_1 and param_2—UV parameter of the critical point for the first and second selected items

Hope that helps.

 

Aravind_98
6-Contributor
(To:FabianWolf)

Hi @FabianWolf 


I appreciate your response.

 

I was able to get the surface edges, but now I'm stuck trying to identify nearby edges. In the attached image, there is one rectangular and one circular extrude cut. I want to categorize them—such as identifying which edges belong to the rectangular cut and which to the circular cut—and determine if the edges of the rectangle and circle are closely located within the model.

 

If you know of any workaround or a better approach, please let me know. I've attached my code for your reference please take a look.



static ProError edge_visit(ProEdge p_edge, ProError status, ProAppData app_data)
{
ProError err;
ProEdge p_edge1, p_edge2;
ProSurface p_face1; ProSurface p_face2;
ProMdl mdl;
err = ProMdlCurrentGet(&mdl);
 
err = ProEdgeNeighborsGet(p_edge, &p_edge1, &p_edge2, &p_face1, &p_face2);
 
int id1, id2;
err = ProEdgeIdGet(p_edge1, &id1);
 
int edge_id = 0;
err = ProEdgeIdGet(p_edge, &edge_id);
 
ProModelitem mdl_item;
status = ProModelitemInit(mdl, edge_id, PRO_EDGE, &mdl_item);
 
 
return PRO_TK_NO_ERROR;
}
 
static ProError contour_visit(ProContour p_contour, ProError status, ProAppData app_data)
{
ProError err;
ProContourTraversal p_traversal;
 
EdgeVisitInputData* edge_visit_input = (EdgeVisitInputData*)app_data;
err = ProContourTraversalGet(p_contour, &p_traversal);
if (p_traversal == PRO_CONTOUR_TRAV_INTERNAL)
{
err = ProContourEdgeVisit(edge_visit_input->surface, p_contour, (ProContourEdgeVisitAction)edge_visit, NULL, NULL);
}
 
 
return PRO_TK_NO_ERROR;
}
 
 
ProError action_cb()
{
 
ProError status;
ProSelection* p_sel_arr; int p_count;
double val;
ProSolidBody* bodies;
ProMdl mdl;
int sld_count;
 
status = ProMdlCurrentGet(&mdl);
 
ProSelection* p_select;
int n_select = 0;
status = ProSelect((char*)"surface", 1, NULL, NULL, NULL, NULL, &p_select, &n_select);
if (n_select <= 0) return status;
 
ProModelitem model_item;
ProSurface surface;
status = ProSelectionModelitemGet(p_select[0], &model_item);
status = ProSurfaceInit((ProSolid)model_item.owner, model_item.id, &surface);
 
EdgeVisitInputData edge_visit_input;
edge_visit_input.surface = surface;
status = ProSurfaceContourVisit(surface, (ProSurfaceContourVisitAction)contour_visit, NULL, (ProAppData*)&edge_visit_input);
 
return status;
 
}
FabianWolf
14-Alexandrite
(To:Aravind_98)

I assume your callback function contour_visit is called twice. First call for the contour of the rectangular and second call for the contour of the circular extrude.

I assume your EdgeVisitInputData is a struct that shall be used for gathering data. You can add a member like std::vector<ContourData> contours, that will gather all the edges for each contour. The type ContourData might hold a member int contour_id (optional) and an array like std:vector<ProModelitem> edges, that will hold all edges belonging to the corresponding contour.

Then you have all the edges separated into two lists. Now you can browse the lists via two nested for loops and calculate the distance for each edge out of first list and all the edges out of the second list. Provide a variable that memorizes the shortest distance until the loops are done.

To get the ProSelection input arguments for ProSelectionWithOptionsDistanceEval, use ProSelectionAlloc on basis of the ProModelitems representing the edges. I guess you are just doing this approach in the context of a sheetmetal part, so ProAsmcomppath is not relevant (set NULL). 

 

Hope that helps.

 

Aravind_98
6-Contributor
(To:FabianWolf)

Hi @FabianWolf 

 

Good Morning, hmm I'm not sure okay let me try, i appreciate your response.

 

regards

Aravind

Announcements

Top Tags