Checking the Tangency of All Surfaces in Ansys SpaceClaim

Categories:

The other day we got a tech support request wanting to know to check the tangency of all the surfaces in a model systematically in Ansys SpaceClaim. You can check surface tangency at an edge using the Measure > Dihedral tool. This measures the angle between the surfaces at a given number of points along the edge and returns the maximum and minimum values.  If the surfaces are tangent, then the dihedral is zero. If not, scaled lines will show the dihedral values at the evaluated points.

Checking the Tangency in Ansys SpaceClaim, Figure 1
Ansys

This works great for a few edges, but checking the whole model would be quite tedious. So we turn to SpaceClaim Scripting.  After checking the current scripting API and realizing that the dihedral calculation is not yet available, I wrote my own. You can download the script here. The script checks the dihedral value of each edge and returns the active set of the non-tangent edges. Since we would also have many edges that we already know are not tangent, like 90° angles, the script includes a cutoff angle of 40°.  Only edges with a minimum dihedral below the cutoff angle will be selected.

# Python Script, API Version = V19

#############################################################
# tangency_check.py
# Select the geometry to check and then run the script
# Author: Joe Woodward
#         Chief Engineer - Simulation Support
#         Phoenix Analysis and Design technologies
#  1/31/2023
##############################################################

maximum_angle_cutoff=25  #Curves with a minimum angle larger than this will not be selected.
minimum_angle_cutoff=0 #1e-3  #Curves with a maximum angle smaller than this will not be selected.
numpoints=10  #Number of of curve evaluation points
print_edges=0 #Change to 1 to print max,min dihedral values for all non-tangent edges
#Selecting edges, or rerunning script with edges selected will also print the values.

from math import acos,sqrt,degrees

def angle(v1,v2):
    x1,y1,z1=v1
    x2,y2,z2=v2
    
    lenSq1 = x1*x1 + y1*y1 + z1*z1
    lenSq2 = x2*x2 + y2*y2 + z2*z2
    dot = x1*x2 + y1*y2 + z1*z2    #between [x1, y1, z1] and [x2, y2, z2]
    
    if lenSq1==0 or lenSq2==0:
        #print("Normal has zero length",lenSq1,lenSq2)
        return None
    try:
        rads=dot/sqrt(lenSq1 * lenSq2)
        angle = degrees(acos(rads))
        #print(dot,lenSq1,lenSq2,rads,angle)
    except ValueError:
        rads=round(dot/sqrt(lenSq1 * lenSq2),8)
        angle = degrees(acos(rads))
        #print("AgainAgain",dot,lenSq1,lenSq2,rads,angle)
    except ZeroDivisionError:
          print("ZeroRadians",dot,lenSq1,lenSq2)
        
        
    if angle>90: return 180-angle
    return angle


def dihedral_maxmin(edge,numevals=numpoints,problems=[]):
    angles=[]
    for ratio in [x*1.0/numevals for x in range(numevals+1)]:
        edge_p=edge.EvalProportion(ratio).Point
        edge_faces=edge.Faces
        n1=edge_faces[0].Shape.ProjectPoint(edge_p).Normal
        n2=edge_faces[1].Shape.ProjectPoint(edge_p).Normal
        ang1=angle(n1,n2)
        if ang1==None:
            print("Normal has zero length at ratio %4.2f"%ratio,n1,n2)
            problems.append(edge)
            return None,None
        angles.append(ang1)
    return max(angles),min(angles)

#Algorithm to get the interior curves of the current surface patch
#faces=Selection.CreateByObjects([GetRootPart().Bodies[0].Faces[1].GetConnection(0)])
#otherfaces=faces.GetInverse()
#otheredges=otherfaces.ConvertToEdges()
#edges=otheredges.GetInverse()

#Check current selection for geometry types.
current_selection=Selection.GetActive()
        
if current_selection.FilterFaces().Count!=0:
    current_faces=current_selection.FilterFaces()
    check_edges=current_faces.ConvertToEdges()
elif current_selection.FilterEdges().Count!=0:
    check_edges=current_selection.ConvertToEdges()
    print_edges=1 #If only edges are picked, then print the dihedrals
elif current_selection.FilterBodies().Count!=0:
    current_bodies=current_selection.FilterBodies()
    check_edges=current_bodies.ConvertToEdges()
elif current_selection.FilterComponents().Count!=0:
    check_edges=current_selection.ConvertToEdges()
else:
    bodies=BodySelection.Create(GetRootPart().GetAllBodies())
    all_faces=bodies.ConvertToFaces()
    all_edges=all_faces.ConvertToEdges()
    check_edges=all_faces.ConvertToEdges()

start_count=check_edges.Count 
nontangents=[]
problems=[]

for edge in check_edges.Edges:
    #esel=EdgeSelection.Create(edge) #Uncomment these lines to see the lines
    #esel.SetActive()                            #as they are checked.
    edge_dihedral_max,edge_dihedral_min=dihedral_maxmin(edge,problems=problems)
    if edge_dihedral_max==None:
        continue
    if edge_dihedral_min>=maximum_angle_cutoff:continue

    if edge_dihedral_max<=minimum_angle_cutoff:continue

    if print_edges==1:
        print(edge_dihedral_max,edge_dihedral_min)
    nontangents.append(edge)
    
nontangent_selection=EdgeSelection.Create(nontangents)
nontangent_selection.SetActive()

print("%d edges processed. %d edges have dihedrals between %f and %f degrees."%(start_count,len(nontangents),minimum_angle_cutoff,maximum_angle_cutoff))
if print_edges==0:
    print("NonTangent edges are now selected. Rerun the script to print the maximum,minimum dihedrals for those edges.")

if len(problems)>0:
    print("The script had problems with %d edges. They should now be highlighted in blue."%len(problems))
    problemSelection=EdgeSelection.Create(problems)
    problemSelection.SetActiveSecondary()

Here is the file for download:

I was writing this for the customer in Ansys SpaceClaim 2020R2, which does not import numpy, so I had to write my own angle calculation function. I am happy to report, though, that SpaceClaim 2023R1 does import numpy, so now all of its amazing functions can be used.

Video Showing how to Check Tangency in Ansys SpaceClaim

Here is a quick video explaining the script and how to attach the script to your Toolbar for quick use whenever it’s needed.

Categories

Get Your Ansys Products & Support from the Engineers who Contribute to this Blog.

Technical Expertise to Enable your Additive Manufacturing Success.

PADT’s Pulse Newsletter

Keep up to date on what is going on at PADT by subscribing to our newsletter.


By submitting this form, you are consenting to receive marketing emails from: . You can revoke your consent to receive emails at any time by using the SafeUnsubscribe® link, found at the bottom of every email. Emails are serviced by Constant Contact

Share this post:

Upcoming Events

09/27/2023

2023 AZ Bio Awards

09/26/2023

Experience Stratasys Truck Tour - Houston

09/22/2023

AIAA Rocky Mountain Section Technical Symposium 2023

09/22/2023

Experience Stratasys Truck Tour - Dallas, TX

09/21/2023

Accelerating the Energy Transition through Simulation

09/20/2023

3D Printing vs. CNC Machining - Webinar

09/13/2023

Maxwell Updates in Ansys 2023 R2 - Webinar

09/12/2023

Sandia Science & Technology Park 25th Anniversary

09/12/2023

Experience Stratasys Truck Tour - Tempe, AZ

09/08/2023

26th Annual New Mexico Flying 40 Awards

09/08/2023

New Mexico Tech Summit

09/07/2023

New Mexico Tech Summit

08/30/2023

Structures Updates in Ansys 2023 R2 (1) - Mechanical, Post & Graphics

08/23/2023

Improved Injection Molding with Additive - Webinar

08/22/2023

SPIE Optics & Photonics Exhibition 2023

08/16/2023

Fluids Updates in Ansys 2023 R2 - Webinar

08/04/2023

Experience Stratasys Truck Tour - Salt Lake City, Utah

08/01/2023

Experience Stratasys Truck Tour - Denver Colorado

07/26/2023

Solving Supply Chain Issues with Additive - Webinar

07/25/2023

Arizona Tech Leadership Golf Tournament

07/24/2023

Arizona Tech CEO Leadership Retreat

07/19/2023

System Automation & Optimization Updates in Ansys 2023 R1 - Webinar

07/13/2023

2023 AEROSPACE, AVIATION, DEFENSE AND MANUFACTURING CONFERENCE

07/12/2023

Materials Updates in Ansys Granta 2023 R1 - Webinar

06/30/2023

Turbo Expo 2023

06/29/2023

Turbo Expo 2023

06/28/2023

Turbo Expo 2023

06/28/2023

Revolutionize Packaging Design with Additive - Webinar

06/27/2023

Turbo Expo 2023

06/27/2023

2023 E-MOBILITY AND CLEAN ENERGY SUMMIT

06/26/2023

Turbo Expo 2023

06/21/2023

Optics Updates in Ansys 2023 R1 - Webinar

06/07/2023

LS-DYNA Updates in Ansys 2023 R1 - Webinar

05/31/2023

Driving Automotive Innovation with Additive - Webinar

05/24/2023

Hill Air Force Base Tech Expo

05/24/2023

Structural Updates in Ansys 2023 R1 (3) – Structural Optimization & Ex

05/23/2023

CROSSTALK 2023: Emerging Opportunities for Advanced Manufacturing Smal

05/10/2023

Signal & Power Integrity Updates in Ansys 2023 R1 - Webinar

04/26/2023

Additive Manufacturing Updates in Ansys 2023 R1 - Webinar

04/20/2023

38th Space Symposium Arizona Space Industry

More Info

04/19/2023

38th Space Symposium
Arizona Space Industry

04/19/2023

Additive Aids for Manufacturing - Webinar

04/18/2023

38th Space Symposium
Arizona Space Industry

04/17/2023

38th Space Symposium

04/13/2023

Venture Madness 2023

04/12/2023

Fluid Meshing & GPU-Solver Updates in Ansys 2023 R1 - Webinar

03/29/2023

8th Thermal and Fluids Engineering Conference

03/29/2023

Structural Updates in Ansys 2023 R1 - Composites, Fracture & MAPDL

03/28/2023

8th Thermal and Fluids Engineering Conference

03/27/2023

8th Thermal and Fluids Engineering Conference

03/26/2023

8TH Thermal and Fluids Engineering Conference

03/24/2023

Arizona BioPreneur Conference | Spring 2023

03/22/2023

2023 Arizona MedTech Conference

03/22/2023

Optimize Jigs & Fixtures with Additive - Webinar

03/15/2023

3D Design Updates in Ansys 2023 R1 - Webinar

03/08/2023

Competitive Advantages of 1D/3D Coupled Simulation - Webinar

03/01/2023

High Frequency Updates in Ansys 2023 R1 - Webinar

02/22/2023

Additive Advantages in Aerospace - Webinar

02/15/2023

Structural Updates in Ansys 2023 R1 (1) - Webinar

02/09/2023

IME 2023: MD&M | WestPack | ATX | D&M | Plastek

02/08/2023

IME 2023 MD&M | WestPack | ATX | D&M | Plastek

02/07/2023

IME 2023 MD&M | WestPack | ATX | D&M | Plastek

01/27/2023

Arizona Photonics Days, 2023

01/26/2023

Arizona Photonics Days, 2023

01/26/2023

TIPE 3D Printing | 2023

01/26/2023

Venture Cafe Phoenix Talent Night - Job Fari

01/26/2023

VFS 2023 Autonomous/Electric VTOL Symposium

01/25/2023

Arizona Photonics Days, 2023

01/25/2023

Building A.M.- Utah: Kickoff!

01/25/2023

TIPE 3D Printing | 2023

01/25/2023

VFS 2023 Autonomous/Electric VTOL Symposium

01/24/2023

VFS 2023 Autonomous/Electric VTOL Symposium

01/24/2023

TIPE 3D Printing | 2023

01/18/2023

2023 AZ Tech Council Golf Tournament

12/21/2022

Simulation Best Practices for 5G Technology - Webinar

12/14/2022

Digital Twins Updates in Ansys 2022 R2 - Webinar

12/08/2022

Tech the Halls - AZ Tech Council Holiday Mixer

12/07/2022

Electric Vehicle and Other Infrastructure Update Panel

11/30/2022

SPEOS Updates in Ansys 2022 R2 - Webinar

11/23/2022

Simulation Best Practices for Electronics Reliability - Webinar

11/16/2022

Discovery Updates in Ansys 2022 R2

11/10/2022

VentureCafe Phoenix Panel: Venture Capital in AZ

11/08/2022

2022 GOVERNOR’S CELEBRATION OF INNOVATION AWARDS + TECH SHOWCASE

11/03/2022

VentureCafe Phoenix Panel: Angel Investment in AZ

11/02/2022

High & Low Frequency Electromagnetics Updates in Ansys 2022 R2

10/26/2022

Simulation Best Practices For Chip-Package-System Design & Development

10/20/2022

Nerdtoberfest 2022

10/19/2022

2022 Southern Arizona Tech + Business Expo

10/19/2022

LS-DYNA Updates in Ansys 2022 R2 - Webinar

10/17/2022

Experience Stratasys Truck Tour - Clearfield Utah

10/14/2022

ASU School of Manufacturing Systems and Networks - Formal Opening Cele

10/14/2022

Experience Stratasys Truck Tour - Midvale Utah

10/12/2022

Experience Stratasys Truck Tour - Littleton Colorado

10/06/2022

Fluids Updates in Ansys 2022 R2 - Webinar

10/05/2022

Experience Stratasys Truck Tour - Colorado Springs

09/29/2022

White Hat Life Science Investor Conference - 2022

09/28/2022

2022 AZBio Awards

09/28/2022

Simulation Best Practices for Rotating Machinery Design & Development

09/21/2022

ExperienceIT NM 2022

Search in PADT site

Contact Us

Most of our customers receive their support over the phone or via email. Customers who are close by can also set up a face-to-face appointment with one of our engineers.

For most locations, simply contact us: