{"id":671,"date":"2020-09-28T14:34:16","date_gmt":"2020-09-28T21:34:16","guid":{"rendered":"http:\/\/gantovnik.com\/bio-tips\/?p=671"},"modified":"2020-09-28T14:34:16","modified_gmt":"2020-09-28T21:34:16","slug":"114-python-script-for-remove-offsets-from-cbar-elements","status":"publish","type":"post","link":"https:\/\/gantovnik.com\/bio-tips\/2020\/09\/114-python-script-for-remove-offsets-from-cbar-elements\/","title":{"rendered":"#114: Python script for remove offsets from CBAR elements"},"content":{"rendered":"<p>#114: Python script for remove offsets from CBAR elements<\/p>\n<p>SOL 106 does not allow offsets in CBAR elements.<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nprint &quot;-------------------------------------&quot;\r\nprint &quot;remove_cbush_offsets_v1.0&quot;\r\nprint &quot;Vladimir Gantovnik&quot;\r\nprint &quot;March 15 2016&quot;\r\nprint &quot;-------------------------------------&quot;\r\n\r\n#input file\r\ninName='test.bdf'\r\ninFile=open(inName)\r\n\r\n#output file\r\noutName='stripped.bdf'\r\noutFile=open(outName,'w')\r\n\r\nimport string\r\n\r\nwhile 1 :\r\n    line=inFile.readline()\r\n    if not line :\r\n        break\r\n    if line&#x5B;0:4] == 'CBAR' :\r\n       outFile.write(line)\r\n       line=inFile.readline()\r\n       if not line :\r\n           break\r\n       if line&#x5B;0:1] == '+' :\r\n          pinflags=line&#x5B;0:24].lstrip()\r\n          outFile.write(pinflags)\r\n          outFile.write('\\n')\r\n       elif line&#x5B;0:1] == '*' :\r\n          outFile.write(line)\r\n          line=inFile.readline()\r\n          if not line :\r\n              break\r\n          if line&#x5B;0:1] == '*' :\r\n             pinflags=line&#x5B;0:40].lstrip()\r\n             outFile.write(pinflags)\r\n             outFile.write('\\n')\r\n             line=inFile.readline()\r\n             if not line :\r\n               break\r\n             if line&#x5B;0:1] == '*' :\r\n                 x=1\r\n             else :\r\n                outFile.write(line)\r\n          else :\r\n             outFile.write(line)\r\n       else :\r\n          outFile.write(line)\r\n             \r\n    else :\r\n       outFile.write(line)\r\n\r\n\r\noutFile.close()\r\nprint &quot;Finished&quot;\r\nprint &quot;-------------------------------------&quot;\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>#114: Python script for remove offsets from CBAR elements SOL 106 does not allow offsets in CBAR elements. print &quot;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&quot; print &quot;remove_cbush_offsets_v1.0&quot; print &quot;Vladimir Gantovnik&quot; print &quot;March 15 2016&quot; print &quot;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&quot; #input file inName=&#8217;test.bdf&#8217; inFile=open(inName) #output file outName=&#8217;stripped.bdf&#8217; outFile=open(outName,&#8217;w&#8217;) import string while 1 : line=inFile.readline() if not line : break if line&#x5B;0:4] == &#8216;CBAR&#8217; : [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","_lmt_disableupdate":"yes","_lmt_disable":"","jetpack_post_was_ever_published":false,"_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":""},"categories":[22,2],"tags":[],"class_list":["post-671","post","type-post","status-publish","format-standard","hentry","category-nastran","category-python"],"modified_by":"gantovnik","jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8bH0k-aP","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":9440,"url":"https:\/\/gantovnik.com\/bio-tips\/2025\/04\/459-python-script-to-group-consecutive-numbers-into-ranges-like-in-msc-patran\/","url_meta":{"origin":671,"position":0},"title":"#459 Python Script to Group Consecutive Numbers into Ranges Like in MSC Patran","author":"gantovnik","date":"2025-04-20","format":false,"excerpt":"This Python script reads a text file containing a list of numbers (such as node or element IDs), sorts them, removes duplicates, and groups consecutive numbers into compact ranges - just like MSC Patran's range format. It's a handy tool for preprocessing or organizing large ID lists efficiently. def read_numbers(filename):\u2026","rel":"","context":"In &quot;patran&quot;","block_context":{"text":"patran","link":"https:\/\/gantovnik.com\/bio-tips\/category\/patran\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1929,"url":"https:\/\/gantovnik.com\/bio-tips\/2023\/08\/379-joint-and-marginal-histograms-using-seaborn-library\/","url_meta":{"origin":671,"position":1},"title":"#379 Joint and marginal histograms using seaborn library","author":"gantovnik","date":"2023-08-10","format":false,"excerpt":"[code language=\"python\"] #Joint and marginal histograms using seaborn library import matplotlib.pyplot as plt #conda install -c anaconda seaborn import seaborn as sns sns.set_theme(style=\"ticks\") def main(): # Load the planets dataset and initialize the figure planets = sns.load_dataset(\"planets\") g = sns.JointGrid(data=planets, x=\"year\", y=\"distance\", marginal_ticks=True) # Set a log scaling on the\u2026","rel":"","context":"In &quot;plot&quot;","block_context":{"text":"plot","link":"https:\/\/gantovnik.com\/bio-tips\/category\/plot\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex379.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex379.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex379.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":413,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/03\/perl-script-to-write-line-containing-specific-word-and-next-second-and-third-lines\/","url_meta":{"origin":671,"position":2},"title":"#62 Perl script to write line containing specific word and next second and third lines","author":"gantovnik","date":"2019-03-10","format":false,"excerpt":"[code language=\"python\"] #!usr\/bin\/perl my $newfile = 'cleaned.csv'; open(my $newfh, '>', $newfile) or die \"Can't read file '$newfile' [$!]\\n\"; my $file = 'original.csv'; my @data; open(my $fh, '<', $file) or die \"Can't read file '$file' [$!]\\n\"; while (my $line = <$fh>) { chomp $line; my @fields = split(\/,\/, $line); if ($fields[4]\u2026","rel":"","context":"In &quot;perl&quot;","block_context":{"text":"perl","link":"https:\/\/gantovnik.com\/bio-tips\/category\/perl\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1718,"url":"https:\/\/gantovnik.com\/bio-tips\/2022\/12\/204-mandelbrot-fractal-using-python-2-2-2-2-2-2\/","url_meta":{"origin":671,"position":3},"title":"#325 Finding the intersection points between two functions using python","author":"gantovnik","date":"2022-12-13","format":false,"excerpt":"[code language=\"python\"] from scipy.optimize import fsolve import numpy as np import matplotlib.pyplot as plt # Defining function to simplify intersection solution def findIntersection(func1, func2, x0): return fsolve(lambda x : func1(x) - func2(x), x0) # Defining functions that will intersect funky = lambda x : np.cos(x \/ 5) * np.sin(x \/\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/12\/ex325.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/12\/ex325.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/12\/ex325.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":2219,"url":"https:\/\/gantovnik.com\/bio-tips\/2024\/06\/431-hypermesh-python-script-to-create-nodes-using-coordinates-from-csv-file\/","url_meta":{"origin":671,"position":4},"title":"#431 HyperMesh python script to create nodes using coordinates from csv file","author":"gantovnik","date":"2024-06-24","format":false,"excerpt":"Finally, I read how to write a script for HyperMesh in python. In this example, the script reads the coordinates of points from a cvs file. [code language=\"python\"] import os import hm import hm.entities as e from hwx import gui import csv model=hm.Model() os.chdir(r\"D:\\projects\\wordpress\\ex431\") with open('ex431_coordinates.csv', mode ='r') as file:\u2026","rel":"","context":"In &quot;HyperMesh&quot;","block_context":{"text":"HyperMesh","link":"https:\/\/gantovnik.com\/bio-tips\/category\/hypermesh\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/06\/ex431.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":432,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/07\/windows-batch-script-to-print-nth-lines-after-line-containing-matched-string\/","url_meta":{"origin":671,"position":5},"title":"#63 Batch script to print n-th lines after line containing matched string","author":"gantovnik","date":"2019-07-26","format":false,"excerpt":"[code language=\"python\"] @echo off setlocal enableDelayedExpansion set \"word=VON MISES\" set \"keep=3\" set \"file=model.f06\" find \" X \" model.f06 > extract_weight.txt del extract_stress.txt set n=%keep% for \/f \"usebackq delims=\" %%A in (\"%file%\") do ( set \"ln=%%A\" if \"!ln:%word%=!\" neq \"!ln!\" ( echo( set n=0 ) if !n! lss !keep! ( echo\u2026","rel":"","context":"In &quot;batch&quot;","block_context":{"text":"batch","link":"https:\/\/gantovnik.com\/bio-tips\/category\/batch\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/671","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/comments?post=671"}],"version-history":[{"count":0,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/671\/revisions"}],"wp:attachment":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/media?parent=671"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/categories?post=671"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/tags?post=671"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}