Is there any automatic way to imprint washers/bolt heads on a face in Discovery?
For instance, let's assume that we've got a wind blade bearing and the idea is to automatically make an imprint of the bolts holes by an edge offset. That offset is given by a ratio of the hole radius. Image below gives an overview of the final target:
Best Answer
-
Below a script developed by @Pierre Thieffry to make that imprint on a selection of faces.
import math offset_value=1.1 # Size for edge offset (radius*offset_value) max_radius=60 # in mm, will avoid offsets for any circular edge with higher radius # For face selection AllEdges=[] CircularEdges=[] EdgeFaces={} EdgeRadius={} # Get face selection selected_faces=Selection.GetActive().GetItems[IDesignFace]() # Loop over faces to find circular edges if len(selected_faces)!=0: for face in selected_faces: for edge in face.Edges: try: # Radius will exist only for circular edges radius = MeasureHelper.ArcRadius(EdgeSelection.Create(edge))*1e3 if radius<=max_radius: AllEdges.append(edge) EdgeFaces[edge]=face except: radius = 0 else: pass # Now loop over circular edges if len(AllEdges)>0: for i in range(len(AllEdges)): edge = AllEdges[i] try: radius = MeasureHelper.ArcRadius(EdgeSelection.Create(edge))*1e3 current_face=EdgeFaces[edge] face_sel=FaceSelection.Create(current_face) edge_selection=EdgeSelection.Create(edge) # Compute Offset offset = float(offset_value)*radius # Create imprint direction= MoveImprintEdges.GetImprintDirection(edge_selection,face_sel, False) options = MoveImprintEdgeOptions() result = MoveImprintEdges.Execute(edge_selection, direction, MM(-offset), options, None) # Look at newly created faces to identify which face should be imprinted (when multiple circular edges are on the same face) for check_face in result.CreatedFaces: # Face we look for does not contain current edge if edge not in check_face.Edges: new_base_face=check_face # As face change after imprint, need to update association between edges and faces for edge, face in EdgeFaces.items(): if face==current_face: EdgeFaces[edge]=new_base_face i = i + 1 except: print('Issue with Imprints - check for possible overlaps')
1
Answers
-
This is a great example. I have a few suggestions to make the code more robust if anybody wants to utilize this script at a large scale.
-> You can determine if an edge is a circle or not with: str(E.Shape.Geometry.GetType()).endswith('Circle'). This would be faster than a try/except most likely if you have lots of non-circle edges.
-> You can use the built in functions for unit conversions like "MM", "IN" instead of the factors like 1E3
-> It would be better to group all the imprints that are along the same face into a single imprint operation. Currently the script does each one-by-one, but I think you can imprint multiple edges. Create a block that first identifies the imprints, then group them by face, and do all the edges for that face in a single imprint. This is only for speed with larger models.
1