Tekla API: How to delete cuts with script

Tekla API, Tekla structures, remove boolean cuts from parts with scriptTekla structures include Tekla API, and we could use it for various cases which could impact engineering process at different stages. Here provided smart solution which allows to delete polygon cuts from plates filter by it’s maximum size.

It’s just an example of how complicated task could be easily solved with Tekla API.

Try to imagine a thousands of plates with various tiny holes spreader through these. These should be drilled by CNC machine tool, but each hole done as a tiny rounded plate, which ruins our plans for automatic drill. Hence we need to remove these, but there is no way to delete it all at once. Cause at the same time major holes also done by plate cuts. Clearing these plates from holes one by one manually – could  take a day. Instead of that  with API list of various issues of such type could be solved in a minutes.

Small explanation for listing bellow

Run – is a main function of a script. There we place what ever we want to be executed. In this case we call function which delete cuts from selected parts with size less argument. Function provided below as a part of same script.

 

Tekla API Script for remove cuts.

namespace Tekla.Technology.Akit.UserScript
{
    using TSM = Tekla.Structures.Model;
    using System; 
    
    public class Script
    {
        public static void Run(Tekla.Technology.Akit.IScript akit)
        {
            DeleteCutsLessThan(100);
        }


    public static void DeleteCutsLessThan(double MaximumAvailableDelta)
    {
            TSM.Model M = new TSM.Model();
            Tekla.Structures.Model.UI.ModelObjectSelector selected = new Tekla.Structures.Model.UI.ModelObjectSelector();
            Tekla.Structures.Model.ModelObjectEnumerator manyO = (selected.GetSelectedObjects() as TSM.ModelObjectEnumerator);

            while (manyO.MoveNext())
            {
                if ((manyO.Current as TSM.ContourPlate) != null)
                {
                    TSM.ContourPlate plate = manyO.Current as TSM.ContourPlate;
                    TSM.ModelObjectEnumerator Children = plate.GetChildren();
                    while (Children.MoveNext())
                    {
                        if ((Children.Current as TSM.BooleanPart) !=null)
                        {
                            TSM.BooleanPart BP = (Children.Current as TSM.BooleanPart);

                            if ((BP.OperativePart as TSM.ContourPlate)!=null)
                            {
                                TSM.ContourPlate CP = BP.OperativePart as TSM.ContourPlate;
                                TSM.ContourPoint BasePoint = CP.Contour.ContourPoints[0] as TSM.ContourPoint;
                                double delta = 0; 

                                for (int i=1; i<CP.Contour.ContourPoints.Count; i++)
                                {
                                    double GP = TwoContoutPointDistance(BasePoint, CP.Contour.ContourPoints[i] as TSM.ContourPoint);
                                    if (delta < GP)
                                        delta = GP;
                                }

                                if (delta < MaximumAvailableDelta)
                                {
                                    BP.OperativePart.Delete();
                                    BP.Delete();
                                }
                            }
                        }
                    }
                }
           }            
            M.CommitChanges();
    }

    private static double TwoContoutPointDistance(TSM.ContourPoint Base, TSM.ContourPoint Check)
        {
            double xx = Check.X - Base.X;
            double yy = Check.Y - Base.Y;
            double zz = Check.Z - Base.Z;
            double GP = xx*xx + yy*yy + zz*zz;
            return Math.Sqrt(GP);
        }
    }
}

PS

For this particular example we actually provide solution for half of task and main question is still open. How to properly create small holes if we keep CNC in mind?

Just use bolts, to be more exact – bolt holes. Of course replacement of round plate cuts with bolt holes, also could be done as extension of solution above. You could create it by yourself, or mail me. 
Replace plate holes with bolt holes by Tekla API script

More about Tekla

One thought on “Tekla API: How to delete cuts with script

Leave a Reply

Name *
Email *
Website