{"id":1061,"date":"2015-05-31T19:21:17","date_gmt":"2015-06-01T00:21:17","guid":{"rendered":"https:\/\/danvanfleet.com\/?p=1061"},"modified":"2015-06-01T16:17:33","modified_gmt":"2015-06-01T21:17:33","slug":"a-look-at-iron-python-in-select","status":"publish","type":"post","link":"https:\/\/danvanfleet.com\/index.php\/a-look-at-iron-python-in-select\/","title":{"rendered":"A look at Iron Python in Select"},"content":{"rendered":"<p><a href=\"https:\/\/i0.wp.com\/danvanfleet.com\/wp-content\/uploads\/2015\/05\/image9.png\"><img data-recalc-dims=\"1\" decoding=\"async\" style=\"background-image: none; float: left; padding-top: 0px; padding-left: 0px; margin: 0px 10px 0px 0px; display: inline; padding-right: 0px; border-width: 0px;\" title=\"image\" src=\"https:\/\/i0.wp.com\/danvanfleet.com\/wp-content\/uploads\/2015\/05\/image_thumb9.png?resize=103%2C113\" alt=\"image\" width=\"103\" height=\"113\" align=\"left\" border=\"0\" \/><\/a>I&#8217;ve been playing around a little bit with Iron Python in SoftPro Select. Setting fields, doing validation, learning some boundaries and how it fits in. It was time for a real life example so I chose the EscrowBriefLegal field. That seemed complex but simple.<\/p>\n<p><!--more--><\/p>\n<p><a href=\"https:\/\/i0.wp.com\/danvanfleet.com\/wp-content\/uploads\/2015\/05\/clip_image0011.png\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" style=\"background-image: none; float: left; padding-top: 0px; padding-left: 0px; margin: 0px 10px 0px 0px; display: inline; padding-right: 0px; border-width: 0px;\" title=\"clip_image001\" src=\"https:\/\/i0.wp.com\/danvanfleet.com\/wp-content\/uploads\/2015\/05\/clip_image001_thumb1.png?resize=395%2C280\" alt=\"clip_image001\" width=\"395\" height=\"280\" align=\"left\" border=\"0\" \/><\/a><\/p>\n<p>A custom rule starts by defining the function with the Context (<strong>Property<\/strong>) as it&#8217;s seen in the Field Code browser at the bottom<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/danvanfleet.com\/wp-content\/uploads\/2015\/05\/clip_image0021.png\"><img data-recalc-dims=\"1\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border-width: 0px;\" title=\"clip_image002\" src=\"https:\/\/i0.wp.com\/danvanfleet.com\/wp-content\/uploads\/2015\/05\/clip_image002_thumb1.png?resize=179%2C57\" alt=\"clip_image002\" width=\"179\" height=\"57\" border=\"0\" \/><\/a><\/p>\n<p>Followed by the Field Name (<strong>EscrowBriefLegal<\/strong>) which is displayed in bold, and the rule aspect being attached to.\u00a0 (<strong>Value<\/strong>)<\/p>\n<p>Line 9 sets up a couple of variables to use later.<\/p>\n<p>On line 13, we are looping up <strong>args.Context.Lots<\/strong>, which says, hey IronPython that Context you started at, (Property in this case)\u00a0 give me the .Lots object of it please. In IronPython indents keep us in our loop, the loop ends when the next line is on the same indent of the start of the loop.<\/p>\n<p>Order.Properties(0).Lots has a member Number, which can be seen in the field code browser, if there is text in Number then we care about it, otherwise loop.\u00a0 That keeps the output updated when users delete a cell in a row without deleting the row.\u00a0 In line 15, I did my if statement a bit backward, if count is zero we save the number in the else statement. Then the counter is incremented and we loop. If there are more lots they are preceded by a comma space and the count incremented.. Finally if we counted more than one number precede the numbers with the appropriate tag. Set the count to zero for the next usage.<\/p>\n<p>The code does the same thing with Units and Parcels and TaxMaps, saving each to a string variable<\/p>\n<p>Next we just grab some individual fields starting with Block<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/danvanfleet.com\/wp-content\/uploads\/2015\/05\/clip_image0031.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" style=\"background-image: none; float: left; padding-top: 0px; padding-left: 0px; margin: 0px 10px 0px 0px; display: inline; padding-right: 0px; border-width: 0px;\" title=\"clip_image003\" src=\"https:\/\/i0.wp.com\/danvanfleet.com\/wp-content\/uploads\/2015\/05\/clip_image003_thumb1.png?resize=360%2C111\" alt=\"clip_image003\" width=\"360\" height=\"111\" align=\"left\" border=\"0\" \/><\/a><\/p>\n<p>Our Context is Property so we define and set the variable pblock to whatever is there. If it&#8217;s something it is formatted, if it&#8217;s nothing, it is set to String.Empty() to keep the final line happy.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/danvanfleet.com\/wp-content\/uploads\/2015\/05\/clip_image0041.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" style=\"background-image: none; float: left; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;\" title=\"clip_image004\" src=\"https:\/\/i0.wp.com\/danvanfleet.com\/wp-content\/uploads\/2015\/05\/clip_image004_thumb1.png?resize=364%2C91\" alt=\"clip_image004\" width=\"364\" height=\"91\" align=\"left\" border=\"0\" \/><\/a><\/p>\n<p>The Subdivision should start on a new line done with &#8220;\\r\\n&#8221; in IronPython.<\/p>\n<p>&nbsp;<\/p>\n<p>At the end the order is set as it&#8217;s being assigned to the value<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/danvanfleet.com\/wp-content\/uploads\/2015\/05\/clip_image0051.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;\" title=\"clip_image005\" src=\"https:\/\/i0.wp.com\/danvanfleet.com\/wp-content\/uploads\/2015\/05\/clip_image005_thumb1.png?resize=761%2C29\" alt=\"clip_image005\" width=\"761\" height=\"29\" border=\"0\" \/><\/a><\/p>\n<p>and it renders on every property every time.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/danvanfleet.com\/wp-content\/uploads\/2015\/05\/image4.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;\" title=\"image\" src=\"https:\/\/i0.wp.com\/danvanfleet.com\/wp-content\/uploads\/2015\/05\/image_thumb4.png?resize=612%2C128\" alt=\"image\" width=\"612\" height=\"128\" border=\"0\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>That all has been refactored in this module<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nfrom System import *\r\nfrom SoftPro.ClientModel import *\r\nfrom SoftPro.OrderTracking.Client import *\r\nfrom SoftPro.OrderTracking.Client.Orders import *\r\nfrom System.Text import StringBuilder\r\n\u00a0 \r\n#\r\n# Escrow Brief Legal creation by Dan Van Fleet &#x64;&#x61;&#x6e;&#x40;&#x76;&#x66;&#x69;&#x6e;&#x66;&#x6f;&#x2e;&#x63;&#x6f;&#x6d; 05\/31\/2015\r\n\u00a0\r\ndef AddObjectNumber(sb, object, single, multiple, afterLabel, betweenMultiples):\r\n#object = multiple object with a .Number child\r\n#single = label for single item return (Lot)\r\n#multiple = label for multiple item return (Lots)\r\n#afterLabel = string to appear after the label and before the Identifier\r\n#betweenMultiples = string to appear between multiples normally ', '\r\n\u00a0\u00a0\u00a0 count = 0\r\n\u00a0\u00a0\u00a0 curPos = sb.Length\r\n\u00a0\u00a0\u00a0 for u in object:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if u.Number &gt; '':\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if count &gt; 0:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 sb.Append(betweenMultiples)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 sb.Append(u.Number)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 else:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 sb.Append(u.Number)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 count += 1\r\n\u00a0\u00a0\u00a0 InsertLabel(sb, curPos, count,single,multiple, afterLabel)\r\n\u00a0 \r\ndef AddObjectIdentification(sb, object, single, multiple, afterLabel, betweenMultiples):\r\n#object = multiple object with a .Identification child\r\n#single = label for single item return (Lot)\r\n#multiple = label for multiple item return (Lots)\r\n#afterLabel = string to appear after the label and before the Identifier\r\n#betweenMultiples = string to appear between multiples normally ', '\r\n\u00a0\u00a0\u00a0 count = 0\r\n\u00a0\u00a0\u00a0 curPos = sb.Length\r\n\u00a0\u00a0\u00a0 for u in object:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if u.Identification &gt; '':\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if count &gt; 0:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 sb.Append(betweenMultiples)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 sb.Append(u.Identification)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 else:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 sb.Append(u.Identification)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 count += 1\r\n\u00a0\u00a0\u00a0 InsertLabel(sb, curPos, count,single,multiple, afterLabel)\r\n\u00a0\u00a0\u00a0 \u00a0\r\ndef InsertLabel(sb, curPos, count, single, multiple, spaceAfter):\r\n#Inserts single or multiple text label at curPos \r\n\u00a0\u00a0\u00a0 if count &gt; 1:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 sb.Insert(curPos, multiple)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 sb.Append(spaceAfter)\r\n\u00a0\u00a0\u00a0 elif count == 1:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 sb.Insert(curPos, single)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 sb.Append(spaceAfter)\r\n\u00a0 \r\ndef AddSingleField(sb, field, pre, post):\r\n\u00a0\u00a0\u00a0 #adds field with preamble and post text, or skips if no field data\r\n\u00a0\u00a0\u00a0 if field &gt; '':\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 sb.Append(pre).Append(field).Append(post)\r\n\u00a0\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0\u00a0 \u00a0\r\ndef Property_EscrowBriefLegal_Value(args):\r\n\u00a0\u00a0\u00a0 sb = StringBuilder()\r\n\u00a0\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0\u00a0 AddObjectNumber(sb, args.Context.Lots, 'Lot ', 'Lots ', ' ' , ', ')\r\n\u00a0\u00a0\u00a0 AddObjectNumber(sb, args.Context.Units, 'Unit ', 'Units ', ' ' , ', ')\r\n\u00a0 \r\n\u00a0\u00a0\u00a0 AddSingleField(sb, args.Context.Block, 'Block ', ' ' )\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0\u00a0 AddSingleField(sb, args.Context.Building, 'Building '\u00a0 , ' ' )\r\n\u00a0\u00a0\u00a0 #demo start Subdivision on a new Line if it exists, \r\n\u00a0\u00a0\u00a0 # start Condo on one if Subdivision doesn't exist\r\n\u00a0\u00a0\u00a0 preSubdivision = sb.Length\u00a0 #Save length\r\n\u00a0\u00a0\u00a0 AddSingleField(sb, args.Context.Subdivision, '\\r\\n', ' ')\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0\u00a0 if preSubdivision == sb.Length: \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 #Length didn't grow so put Condo on separate line\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 AddSingleField(sb, args.Context.Condo, '\\r\\n', ' ')\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0\u00a0 else:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 AddSingleField(sb, args.Context.Condo, '', ' ')\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0\u00a0 AddSingleField(sb, args.Context.Section, '\\r\\nSection ', ' ')\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0\u00a0 AddSingleField(sb, args.Context.Phase, 'Phase ' , ' ' )\r\n\u00a0\u00a0\u00a0 AddObjectIdentification(sb, args.Context.Parcels, '\\r\\nParcel ID ','\\r\\nParcel IDs ', ' ' , ', ')\r\n\u00a0\u00a0\u00a0 AddObjectIdentification(sb, args.Context.TaxMaps, '\\r\\nTax\/Map ID ','\\r\\nTax\/Map IDs ', ' ' , ', ')\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0\u00a0 args.Value = sb.ToString()\r\n <\/pre>\n<p>A little about the refactored code:<\/p>\n<p>6\/1\/15 A new update has been made using StringBuilder to end the immutable string issue on performance.<\/p>\n<p>New function refactored, InsertLabel to handle the single or plural<\/p>\n<p>The function AddObjectNumber() is used to pull the Lot.Number and Unit Number.\u00a0 AddObjectIdentification() is used for Parcels and TaxMaps.\u00a0 The function AddSingleField() is used to format non multiple Order.Properties().Objects.<\/p>\n<p>AddOrderNumber accepts 3 parameters, the multiple being processed, the single unit label and the multiple unit label, either of which can be string.Empty().\u00a0 AddOrderIdentification works the same way, but is used for objects that contain an .Identification field.<\/p>\n<p>AddSingleField accepts a non multiple field which gets combined with the pre and post text.<\/p>\n<p>Add field by field name for example to add Order.Property(current).MapReference use<\/p>\n<p>AddSingleField(sb, args.Context.MapReference, \u2018Map Ref \u2018, \u2018\\r\\n\\r\\n\u2019)<\/p>\n<p>where ever in the order MapReference is to appear.\u00a0 With that coding it will be preceded by \u201cMap Ref\u201d and followed by an double line feed.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been playing around a little bit with Iron Python in SoftPro Select. Setting fields, doing validation, learning some boundaries and how it fits in. It was time for a real life example so I chose the EscrowBriefLegal field. That seemed complex but simple.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[23],"tags":[39],"class_list":["post-1061","post","type-post","status-publish","format-standard","hentry","category-softpro-2","tag-select","entry"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4wyVb-h7","jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/danvanfleet.com\/index.php\/wp-json\/wp\/v2\/posts\/1061","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/danvanfleet.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/danvanfleet.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/danvanfleet.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/danvanfleet.com\/index.php\/wp-json\/wp\/v2\/comments?post=1061"}],"version-history":[{"count":35,"href":"https:\/\/danvanfleet.com\/index.php\/wp-json\/wp\/v2\/posts\/1061\/revisions"}],"predecessor-version":[{"id":1099,"href":"https:\/\/danvanfleet.com\/index.php\/wp-json\/wp\/v2\/posts\/1061\/revisions\/1099"}],"wp:attachment":[{"href":"https:\/\/danvanfleet.com\/index.php\/wp-json\/wp\/v2\/media?parent=1061"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/danvanfleet.com\/index.php\/wp-json\/wp\/v2\/categories?post=1061"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/danvanfleet.com\/index.php\/wp-json\/wp\/v2\/tags?post=1061"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}