{"id":5,"date":"2015-11-03T19:11:09","date_gmt":"2015-11-03T19:11:09","guid":{"rendered":"http:\/\/o-calcpro.com\/wiki\/?p=5"},"modified":"2015-11-18T16:41:26","modified_gmt":"2015-11-18T16:41:26","slug":"batch-pole-operations-in-scripts-and-plugins","status":"publish","type":"post","link":"http:\/\/o-calcpro.com\/wiki\/2015\/11\/03\/batch-pole-operations-in-scripts-and-plugins\/","title":{"rendered":"Batch Pole Operations in Scripts and Plugins"},"content":{"rendered":"<p>When creating O-Calc scripts and plugins it is often the case that the developer \/ user would like to be able to perform operations on a large number of poles in a batch operation, perhaps as an un-attended operation. The O-Calc scripting and plugins API provides a convenient way to allow this to be done while hiding the considerable complexity of managing the multiple calculation threads and processing various pole versions and LoadCases.<\/p>\n<p>In the following simple &#8220;hello world&#8221; type example is presented a script that opens all of the poles selected and displays the pole number in a message box:<\/p>\n<div id=\"ig-sh-1\" class=\"syntax_hilite\">\n\n\t\t<div class=\"toolbar\">\n\n\t\t<div class=\"view-different-container\">\n\t\t\t\t\t\t<a href=\"#\" class=\"view-different\">&lt; View <span>plain text<\/span> &gt;<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t<div class=\"language-name\">C#<\/div>\n\n\t\t\n\t\t<br clear=\"both\">\n\n\t<\/div>\n\t\n\t<div class=\"code\">\n\t\t<ol class=\"csharp\" style=\"font-family:monospace\"><li><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #0600FF;font-weight: bold\">using<\/span> <span style=\"color: #008080\">System<\/span><span style=\"color: #008000\">;<\/span><\/div><\/li>\n<li><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #0600FF;font-weight: bold\">using<\/span> <span style=\"color: #008080\">System.Collections.Generic<\/span><span style=\"color: #008000\">;<\/span><\/div><\/li>\n<li><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #0600FF;font-weight: bold\">using<\/span> <span style=\"color: #008080\">System.Diagnostics<\/span><span style=\"color: #008000\">;<\/span><\/div><\/li>\n<li><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #0600FF;font-weight: bold\">using<\/span> <span style=\"color: #008080\">System.Windows.Forms<\/span><span style=\"color: #008000\">;<\/span><\/div><\/li>\n<li><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #0600FF;font-weight: bold\">using<\/span> <span style=\"color: #008080\">PPL_Lib<\/span><span style=\"color: #008000\">;<\/span><\/div><\/li>\n<li><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #0600FF;font-weight: bold\">public<\/span> <span style=\"color: #6666cc;font-weight: bold\">class<\/span> Script<\/div><\/li>\n<li><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #008000\">&#123;<\/span><\/div><\/li>\n<li><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; PPLMain cPPLMain <span style=\"color: #008000\">=<\/span> <span style=\"color: #0600FF;font-weight: bold\">null<\/span><span style=\"color: #008000\">;<\/span><\/div><\/li>\n<li><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; <span style=\"color: #0600FF;font-weight: bold\">public<\/span> <span style=\"color: #6666cc;font-weight: bold\">void<\/span> Execute<span style=\"color: #008000\">&#040;<\/span>PPLMain pPPLMain<span style=\"color: #008000\">&#041;<\/span><\/div><\/li>\n<li><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; <span style=\"color: #008000\">&#123;<\/span><\/div><\/li>\n<li><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; &nbsp; &nbsp; cPPLMain <span style=\"color: #008000\">=<\/span> pPPLMain<span style=\"color: #008000\">;<\/span><\/div><\/li>\n<li><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; &nbsp; &nbsp; <span style=\"color: #0600FF;font-weight: bold\">using<\/span> <span style=\"color: #008000\">&#040;<\/span>BatchPoleHelper helper <span style=\"color: #008000\">=<\/span> <span style=\"color: #008000\">new<\/span> BatchPoleHelper<span style=\"color: #008000\">&#040;<\/span>cPPLMain, <span style=\"color: #666666\">&quot;Batch Demo&quot;<\/span><span style=\"color: #008000\">&#041;<\/span><span style=\"color: #008000\">&#041;<\/span><\/div><\/li>\n<li><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; &nbsp; &nbsp; <span style=\"color: #008000\">&#123;<\/span><\/div><\/li>\n<li><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; helper<span style=\"color: #008000\">.<\/span><span style=\"color: #0000FF\">PoleReadyForBatchProcessing<\/span> <span style=\"color: #008000\">+=<\/span> helper_PoleReadyForBatchProcessing<span style=\"color: #008000\">;<\/span><\/div><\/li>\n<li><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cPPLMain<span style=\"color: #008000\">.<\/span><span style=\"color: #0000FF\">SetToolFormPosition<\/span><span style=\"color: #008000\">&#040;<\/span>helper<span style=\"color: #008000\">&#041;<\/span><span style=\"color: #008000\">;<\/span><\/div><\/li>\n<li><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; helper<span style=\"color: #008000\">.<\/span><span style=\"color: #0000FF\">ShowDialog<\/span><span style=\"color: #008000\">&#040;<\/span><span style=\"color: #008000\">&#041;<\/span><span style=\"color: #008000\">;<\/span><\/div><\/li>\n<li><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; &nbsp; &nbsp; <span style=\"color: #008000\">&#125;<\/span><\/div><\/li>\n<li><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; <span style=\"color: #008000\">&#125;<\/span><\/div><\/li>\n<li><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp;<\/div><\/li>\n<li><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; <span style=\"color: #6666cc;font-weight: bold\">void<\/span> helper_PoleReadyForBatchProcessing<span style=\"color: #008000\">&#040;<\/span>PPLPole pPole<span style=\"color: #008000\">&#041;<\/span><\/div><\/li>\n<li><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; <span style=\"color: #008000\">&#123;<\/span><\/div><\/li>\n<li><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; &nbsp; &nbsp; MessageBox<span style=\"color: #008000\">.<\/span><span style=\"color: #0000FF\">Show<\/span><span style=\"color: #008000\">&#040;<\/span>pPole<span style=\"color: #008000\">.<\/span><span style=\"color: #0000FF\">DisplayedName<\/span><span style=\"color: #008000\">&#040;<\/span>PPLElement<span style=\"color: #008000\">.<\/span><span style=\"color: #0000FF\">DISPLAY_NAME_MODE<\/span><span style=\"color: #008000\">.<\/span><span style=\"color: #0000FF\">INVENTORY<\/span><span style=\"color: #008000\">&#041;<\/span><span style=\"color: #008000\">&#041;<\/span><span style=\"color: #008000\">;<\/span><\/div><\/li>\n<li><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; <span style=\"color: #008000\">&#125;<\/span><\/div><\/li>\n<li><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #008000\">&#125;<\/span><\/div><\/li>\n<\/ol>\t<\/div>\n\n<\/div>\n\n<p>The important point to notice is that there are two basic steps.<\/p>\n<ol>\n<li>Instantiate a BatchPoleHelper and show it<\/li>\n<li>Catch the PoleReadyForBatchProcessing event<\/li>\n<\/ol>\n<p>The PoleReadyForBatchProcessing event will be fired every time that a pole has been loaded, the correct LoadCase has been selected, and that the pole load calculation process has been successfully completed.<\/p>\n<a class=\"synved-social-button synved-social-button-share synved-social-size-48 synved-social-resolution-single synved-social-provider-facebook nolightbox\" data-provider=\"facebook\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Facebook\" href=\"https:\/\/www.facebook.com\/sharer.php?u=http%3A%2F%2Fo-calcpro.com%2Fwiki%2Fwp-json%2Fwp%2Fv2%2Fposts%2F5&#038;t=Batch%20Pole%20Operations%20in%20Scripts%20and%20Plugins&#038;s=100&#038;p&#091;url&#093;=http%3A%2F%2Fo-calcpro.com%2Fwiki%2Fwp-json%2Fwp%2Fv2%2Fposts%2F5&#038;p&#091;images&#093;&#091;0&#093;=&#038;p&#091;title&#093;=Batch%20Pole%20Operations%20in%20Scripts%20and%20Plugins\" style=\"font-size: 0px;width:48px;height:48px;margin:0;margin-bottom:5px;margin-right:5px\"><img decoding=\"async\" alt=\"Facebook\" title=\"Share on Facebook\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"48\" height=\"48\" style=\"display: inline;width:48px;height:48px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"http:\/\/o-calcpro.com\/wiki\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/96x96\/facebook.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-48 synved-social-resolution-single synved-social-provider-twitter nolightbox\" data-provider=\"twitter\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Twitter\" href=\"https:\/\/twitter.com\/intent\/tweet?url=http%3A%2F%2Fo-calcpro.com%2Fwiki%2Fwp-json%2Fwp%2Fv2%2Fposts%2F5&#038;text=O-Calc%20Pro%20Information\" style=\"font-size: 0px;width:48px;height:48px;margin:0;margin-bottom:5px;margin-right:5px\"><img decoding=\"async\" alt=\"twitter\" title=\"Share on Twitter\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"48\" height=\"48\" style=\"display: inline;width:48px;height:48px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"http:\/\/o-calcpro.com\/wiki\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/96x96\/twitter.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-48 synved-social-resolution-single synved-social-provider-linkedin nolightbox\" data-provider=\"linkedin\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Linkedin\" href=\"https:\/\/www.linkedin.com\/shareArticle?mini=true&#038;url=http%3A%2F%2Fo-calcpro.com%2Fwiki%2Fwp-json%2Fwp%2Fv2%2Fposts%2F5&#038;title=Batch%20Pole%20Operations%20in%20Scripts%20and%20Plugins\" style=\"font-size: 0px;width:48px;height:48px;margin:0;margin-bottom:5px;margin-right:5px\"><img decoding=\"async\" alt=\"linkedin\" title=\"Share on Linkedin\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"48\" height=\"48\" style=\"display: inline;width:48px;height:48px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"http:\/\/o-calcpro.com\/wiki\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/96x96\/linkedin.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-48 synved-social-resolution-single synved-social-provider-mail nolightbox\" data-provider=\"mail\" rel=\"nofollow\" title=\"Share by email\" href=\"mailto:?subject=Batch%20Pole%20Operations%20in%20Scripts%20and%20Plugins&#038;body=O-Calc%20Pro%20Information:%20http%3A%2F%2Fo-calcpro.com%2Fwiki%2Fwp-json%2Fwp%2Fv2%2Fposts%2F5\" style=\"font-size: 0px;width:48px;height:48px;margin:0;margin-bottom:5px\"><img decoding=\"async\" alt=\"mail\" title=\"Share by email\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"48\" height=\"48\" style=\"display: inline;width:48px;height:48px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"http:\/\/o-calcpro.com\/wiki\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/96x96\/mail.png\" \/><\/a>","protected":false},"excerpt":{"rendered":"<p>When creating O-Calc scripts and plugins it is often the case that the developer \/ user would like to be able to perform operations on a large number of poles in a batch operation, perhaps as an un-attended operation. The O-Calc scripting and plugins API provides a convenient way to allow this to be done ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"http:\/\/o-calcpro.com\/wiki\/2015\/11\/03\/batch-pole-operations-in-scripts-and-plugins\/\" title=\"read more...\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,3],"tags":[],"class_list":["post-5","post","type-post","status-publish","format-standard","hentry","category-plugin-development","category-scripting"],"_links":{"self":[{"href":"http:\/\/o-calcpro.com\/wiki\/wp-json\/wp\/v2\/posts\/5","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/o-calcpro.com\/wiki\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/o-calcpro.com\/wiki\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/o-calcpro.com\/wiki\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/o-calcpro.com\/wiki\/wp-json\/wp\/v2\/comments?post=5"}],"version-history":[{"count":5,"href":"http:\/\/o-calcpro.com\/wiki\/wp-json\/wp\/v2\/posts\/5\/revisions"}],"predecessor-version":[{"id":46,"href":"http:\/\/o-calcpro.com\/wiki\/wp-json\/wp\/v2\/posts\/5\/revisions\/46"}],"wp:attachment":[{"href":"http:\/\/o-calcpro.com\/wiki\/wp-json\/wp\/v2\/media?parent=5"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/o-calcpro.com\/wiki\/wp-json\/wp\/v2\/categories?post=5"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/o-calcpro.com\/wiki\/wp-json\/wp\/v2\/tags?post=5"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}