{"id":144,"date":"2016-10-05T20:25:18","date_gmt":"2016-10-05T20:25:18","guid":{"rendered":"http:\/\/cadsupport.ru\/en\/?p=144"},"modified":"2017-03-02T14:28:58","modified_gmt":"2017-03-02T14:28:58","slug":"tekla-api-delete-cuts","status":"publish","type":"post","link":"http:\/\/cadsupport.ru\/en\/tekla-api-delete-cuts\/","title":{"rendered":"Tekla API: How to delete cuts with script"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignleft wp-image-1512\" style=\"margin: 10px;\" src=\"http:\/\/cadsupport.ru\/wp-content\/uploads\/2016\/07\/tekla-structures-api-remove-boolean-parts-script-1024x557.jpg\" alt=\"Tekla API, Tekla structures, remove boolean cuts from parts with script\" width=\"394\" height=\"215\" \/><strong>Tekla structures<\/strong>\u00a0include\u00a0<strong>Tekla API<\/strong>, 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&#8217;s maximum size.<\/p>\n<p>It&#8217;s just an example of how complicated task could be easily solved with Tekla API.<\/p>\n<p>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\u00a0ruins 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 &#8211; could \u00a0take a day. Instead of that \u00a0with API list of various issues of such type could be solved in a minutes.<\/p>\n<p><!--more--><\/p>\n<p>Small explanation for listing bellow<\/p>\n<p><strong>Run<\/strong> &#8211; 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.<\/p>\n<p>&nbsp;<\/p>\n<h2>Tekla API Script for remove cuts.<\/h2>\n<p><!-- code formatted by http:\/\/manoli.net\/csharpformat\/ --><\/p>\n<pre class=\"csharpcode\"><span class=\"kwrd\">namespace<\/span> Tekla.Technology.Akit.UserScript\r\n{\r\n    <span class=\"kwrd\">using<\/span> TSM = Tekla.Structures.Model;\r\n    <span class=\"kwrd\">using<\/span> System; \r\n    \r\n    <span class=\"kwrd\">public<\/span> <span class=\"kwrd\">class<\/span> Script\r\n    {\r\n        <span class=\"kwrd\">public<\/span> <span class=\"kwrd\">static<\/span> <span class=\"kwrd\">void<\/span> Run(Tekla.Technology.Akit.IScript akit)\r\n        {\r\n            DeleteCutsLessThan(100);\r\n        }\r\n\r\n\r\n    <span class=\"kwrd\">public<\/span> <span class=\"kwrd\">static<\/span> <span class=\"kwrd\">void<\/span> DeleteCutsLessThan(<span class=\"kwrd\">double<\/span> MaximumAvailableDelta)\r\n    {\r\n            TSM.Model M = <span class=\"kwrd\">new<\/span> TSM.Model();\r\n            Tekla.Structures.Model.UI.ModelObjectSelector selected = <span class=\"kwrd\">new<\/span> Tekla.Structures.Model.UI.ModelObjectSelector();\r\n            Tekla.Structures.Model.ModelObjectEnumerator manyO = (selected.GetSelectedObjects() <span class=\"kwrd\">as<\/span> TSM.ModelObjectEnumerator);\r\n\r\n            while (manyO.MoveNext())\r\n            {\r\n                <span class=\"kwrd\">if<\/span> ((manyO.Current <span class=\"kwrd\">as<\/span> TSM.ContourPlate) != <span class=\"kwrd\">null<\/span>)\r\n                {\r\n                    TSM.ContourPlate plate = manyO.Current <span class=\"kwrd\">as<\/span> TSM.ContourPlate;\r\n                    TSM.ModelObjectEnumerator Children = plate.GetChildren();\r\n                    while (Children.MoveNext())\r\n                    {\r\n                        <span class=\"kwrd\">if<\/span> ((Children.Current <span class=\"kwrd\">as<\/span> TSM.BooleanPart) !=<span class=\"kwrd\">null<\/span>)\r\n                        {\r\n                            TSM.BooleanPart BP = (Children.Current <span class=\"kwrd\">as<\/span> TSM.BooleanPart);\r\n\r\n                            <span class=\"kwrd\">if<\/span> ((BP.OperativePart <span class=\"kwrd\">as<\/span> TSM.ContourPlate)!=<span class=\"kwrd\">null<\/span>)\r\n                            {\r\n                                TSM.ContourPlate CP = BP.OperativePart <span class=\"kwrd\">as<\/span> TSM.ContourPlate;\r\n                                TSM.ContourPoint BasePoint = CP.Contour.ContourPoints[0] <span class=\"kwrd\">as<\/span> TSM.ContourPoint;\r\n                                <span class=\"kwrd\">double<\/span> delta = 0; \r\n\r\n                                <span class=\"kwrd\">for<\/span> (<span class=\"kwrd\">int<\/span> i=1; i&lt;CP.Contour.ContourPoints.Count; i++)\r\n                                {\r\n                                    <span class=\"kwrd\">double<\/span> GP = TwoContoutPointDistance(BasePoint, CP.Contour.ContourPoints[i] <span class=\"kwrd\">as<\/span> TSM.ContourPoint);\r\n                                    <span class=\"kwrd\">if<\/span> (delta &lt; GP)\r\n                                        delta = GP;\r\n                                }\r\n\r\n                                <span class=\"kwrd\">if<\/span> (delta &lt; MaximumAvailableDelta)\r\n                                {\r\n                                    BP.OperativePart.Delete();\r\n                                    BP.Delete();\r\n                                }\r\n                            }\r\n                        }\r\n                    }\r\n                }\r\n           }            \r\n            M.CommitChanges();\r\n    }\r\n\r\n    <span class=\"kwrd\">private<\/span> <span class=\"kwrd\">static<\/span> <span class=\"kwrd\">double<\/span> TwoContoutPointDistance(TSM.ContourPoint Base, TSM.ContourPoint Check)\r\n        {\r\n            <span class=\"kwrd\">double<\/span> xx = Check.X - Base.X;\r\n            <span class=\"kwrd\">double<\/span> yy = Check.Y - Base.Y;\r\n            <span class=\"kwrd\">double<\/span> zz = Check.Z - Base.Z;\r\n            <span class=\"kwrd\">double<\/span> GP = xx*xx + yy*yy + zz*zz;\r\n            <span class=\"kwrd\">return<\/span> Math.Sqrt(GP);\r\n        }\r\n    }\r\n}\r\n<\/pre>\n<h2>PS<\/h2>\n<p>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?<\/p>\n<p>Just use bolts, to be more exact &#8211; bolt holes. Of course replacement of round plate\u00a0cuts with bolt holes, also could be done as extension of solution above. You could create it by yourself, or <a href=\"mailto:don_jad@mail.ru\">mail me.\u00a0<\/a><br \/>\n<a href=\"http:\/\/cadsupport.ru\/wp-content\/uploads\/2016\/07\/tekla-structures-bolts-instead-cuts-to-emulate-holes.jpg\"  rel=\"lightbox[144] attachment wp-att-1515\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-1515 size-large aligncenter\" src=\"http:\/\/cadsupport.ru\/wp-content\/uploads\/2016\/07\/tekla-structures-bolts-instead-cuts-to-emulate-holes-1024x611.jpg\" alt=\"Replace plate holes with bolt holes by Tekla API script\" width=\"474\" height=\"283\" \/><\/a><\/p>\n<h2>More about Tekla<\/h2>\n<ul>\n<li><a href=\"http:\/\/cadsupport.ru\/en\/work-tekla-structures-macro-scripts\/\">Working with Tekla macro scripts<\/a><\/li>\n<li><a href=\"http:\/\/cadsupport.ru\/en\/how-to-use-tekla-macro-script-with-tekla-api\/\">How to use Tekla structures scripts with your application through OpenAPI<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Tekla structures\u00a0include\u00a0Tekla 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&#8217;s maximum size. It&#8217;s just an example of how complicated task could be easily solved with Tekla API. Try to imagine a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,5],"tags":[8,17,26,21,14,25],"class_list":["post-144","post","type-post","status-publish","format-standard","hentry","category-programing","category-tekla","tag-c","tag-programming","tag-script","tag-tekla-script","tag-tekla-structures","tag-teklaapi"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Tekla API: How to delete cuts with script - CadSupport<\/title>\n<meta name=\"description\" content=\"Listing of Tekla Structures script which is based on Tekla API and C# and give a clue of how to delete cuts from tekla parts filter by it&#039;s size.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/cadsupport.ru\/en\/tekla-api-delete-cuts\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Tekla API: How to delete cuts with script - CadSupport\" \/>\n<meta property=\"og:description\" content=\"Listing of Tekla Structures script which is based on Tekla API and C# and give a clue of how to delete cuts from tekla parts filter by it&#039;s size.\" \/>\n<meta property=\"og:url\" content=\"http:\/\/cadsupport.ru\/en\/tekla-api-delete-cuts\/\" \/>\n<meta property=\"og:site_name\" content=\"CadSupport\" \/>\n<meta property=\"article:published_time\" content=\"2016-10-05T20:25:18+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-03-02T14:28:58+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/cadsupport.ru\/wp-content\/uploads\/2016\/07\/tekla-structures-api-remove-boolean-parts-script-1024x557.jpg\" \/>\n<meta name=\"author\" content=\"DonJad\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DonJad\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"http:\/\/cadsupport.ru\/en\/tekla-api-delete-cuts\/\",\"url\":\"http:\/\/cadsupport.ru\/en\/tekla-api-delete-cuts\/\",\"name\":\"Tekla API: How to delete cuts with script - CadSupport\",\"isPartOf\":{\"@id\":\"http:\/\/cadsupport.ru\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\/\/cadsupport.ru\/en\/tekla-api-delete-cuts\/#primaryimage\"},\"image\":{\"@id\":\"http:\/\/cadsupport.ru\/en\/tekla-api-delete-cuts\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/cadsupport.ru\/wp-content\/uploads\/2016\/07\/tekla-structures-api-remove-boolean-parts-script-1024x557.jpg\",\"datePublished\":\"2016-10-05T20:25:18+00:00\",\"dateModified\":\"2017-03-02T14:28:58+00:00\",\"author\":{\"@id\":\"http:\/\/cadsupport.ru\/en\/#\/schema\/person\/b57bc479c7822ae8efbc5a5b624a3b8a\"},\"description\":\"Listing of Tekla Structures script which is based on Tekla API and C# and give a clue of how to delete cuts from tekla parts filter by it's size.\",\"breadcrumb\":{\"@id\":\"http:\/\/cadsupport.ru\/en\/tekla-api-delete-cuts\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/cadsupport.ru\/en\/tekla-api-delete-cuts\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/cadsupport.ru\/en\/tekla-api-delete-cuts\/#primaryimage\",\"url\":\"http:\/\/cadsupport.ru\/wp-content\/uploads\/2016\/07\/tekla-structures-api-remove-boolean-parts-script-1024x557.jpg\",\"contentUrl\":\"http:\/\/cadsupport.ru\/wp-content\/uploads\/2016\/07\/tekla-structures-api-remove-boolean-parts-script-1024x557.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/cadsupport.ru\/en\/tekla-api-delete-cuts\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/cadsupport.ru\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Tekla API: How to delete cuts with script\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/cadsupport.ru\/en\/#website\",\"url\":\"http:\/\/cadsupport.ru\/en\/\",\"name\":\"CadSupport\",\"description\":\"smart solutions for engineering duties\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/cadsupport.ru\/en\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"http:\/\/cadsupport.ru\/en\/#\/schema\/person\/b57bc479c7822ae8efbc5a5b624a3b8a\",\"name\":\"DonJad\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/cadsupport.ru\/en\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/b22cdec01f0612764c8b311b89954151bfb042524440d622849757864e132a55?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/b22cdec01f0612764c8b311b89954151bfb042524440d622849757864e132a55?s=96&d=mm&r=g\",\"caption\":\"DonJad\"},\"url\":\"http:\/\/cadsupport.ru\/en\/author\/donjad\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Tekla API: How to delete cuts with script - CadSupport","description":"Listing of Tekla Structures script which is based on Tekla API and C# and give a clue of how to delete cuts from tekla parts filter by it's size.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/cadsupport.ru\/en\/tekla-api-delete-cuts\/","og_locale":"en_US","og_type":"article","og_title":"Tekla API: How to delete cuts with script - CadSupport","og_description":"Listing of Tekla Structures script which is based on Tekla API and C# and give a clue of how to delete cuts from tekla parts filter by it's size.","og_url":"http:\/\/cadsupport.ru\/en\/tekla-api-delete-cuts\/","og_site_name":"CadSupport","article_published_time":"2016-10-05T20:25:18+00:00","article_modified_time":"2017-03-02T14:28:58+00:00","og_image":[{"url":"http:\/\/cadsupport.ru\/wp-content\/uploads\/2016\/07\/tekla-structures-api-remove-boolean-parts-script-1024x557.jpg"}],"author":"DonJad","twitter_card":"summary_large_image","twitter_misc":{"Written by":"DonJad","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"http:\/\/cadsupport.ru\/en\/tekla-api-delete-cuts\/","url":"http:\/\/cadsupport.ru\/en\/tekla-api-delete-cuts\/","name":"Tekla API: How to delete cuts with script - CadSupport","isPartOf":{"@id":"http:\/\/cadsupport.ru\/en\/#website"},"primaryImageOfPage":{"@id":"http:\/\/cadsupport.ru\/en\/tekla-api-delete-cuts\/#primaryimage"},"image":{"@id":"http:\/\/cadsupport.ru\/en\/tekla-api-delete-cuts\/#primaryimage"},"thumbnailUrl":"http:\/\/cadsupport.ru\/wp-content\/uploads\/2016\/07\/tekla-structures-api-remove-boolean-parts-script-1024x557.jpg","datePublished":"2016-10-05T20:25:18+00:00","dateModified":"2017-03-02T14:28:58+00:00","author":{"@id":"http:\/\/cadsupport.ru\/en\/#\/schema\/person\/b57bc479c7822ae8efbc5a5b624a3b8a"},"description":"Listing of Tekla Structures script which is based on Tekla API and C# and give a clue of how to delete cuts from tekla parts filter by it's size.","breadcrumb":{"@id":"http:\/\/cadsupport.ru\/en\/tekla-api-delete-cuts\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/cadsupport.ru\/en\/tekla-api-delete-cuts\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/cadsupport.ru\/en\/tekla-api-delete-cuts\/#primaryimage","url":"http:\/\/cadsupport.ru\/wp-content\/uploads\/2016\/07\/tekla-structures-api-remove-boolean-parts-script-1024x557.jpg","contentUrl":"http:\/\/cadsupport.ru\/wp-content\/uploads\/2016\/07\/tekla-structures-api-remove-boolean-parts-script-1024x557.jpg"},{"@type":"BreadcrumbList","@id":"http:\/\/cadsupport.ru\/en\/tekla-api-delete-cuts\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/cadsupport.ru\/en\/"},{"@type":"ListItem","position":2,"name":"Tekla API: How to delete cuts with script"}]},{"@type":"WebSite","@id":"http:\/\/cadsupport.ru\/en\/#website","url":"http:\/\/cadsupport.ru\/en\/","name":"CadSupport","description":"smart solutions for engineering duties","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/cadsupport.ru\/en\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"http:\/\/cadsupport.ru\/en\/#\/schema\/person\/b57bc479c7822ae8efbc5a5b624a3b8a","name":"DonJad","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/cadsupport.ru\/en\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/b22cdec01f0612764c8b311b89954151bfb042524440d622849757864e132a55?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b22cdec01f0612764c8b311b89954151bfb042524440d622849757864e132a55?s=96&d=mm&r=g","caption":"DonJad"},"url":"http:\/\/cadsupport.ru\/en\/author\/donjad\/"}]}},"_links":{"self":[{"href":"http:\/\/cadsupport.ru\/en\/wp-json\/wp\/v2\/posts\/144","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/cadsupport.ru\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/cadsupport.ru\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/cadsupport.ru\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/cadsupport.ru\/en\/wp-json\/wp\/v2\/comments?post=144"}],"version-history":[{"count":11,"href":"http:\/\/cadsupport.ru\/en\/wp-json\/wp\/v2\/posts\/144\/revisions"}],"predecessor-version":[{"id":204,"href":"http:\/\/cadsupport.ru\/en\/wp-json\/wp\/v2\/posts\/144\/revisions\/204"}],"wp:attachment":[{"href":"http:\/\/cadsupport.ru\/en\/wp-json\/wp\/v2\/media?parent=144"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/cadsupport.ru\/en\/wp-json\/wp\/v2\/categories?post=144"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/cadsupport.ru\/en\/wp-json\/wp\/v2\/tags?post=144"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}