diff options
author | saurabhb17 | 2020-02-26 16:00:53 +0530 |
---|---|---|
committer | GitHub | 2020-02-26 16:00:53 +0530 |
commit | 886d9cb772e81d2e5262284bc3082664f084337f (patch) | |
tree | 6acee185a4dc19113fcbf0f9a3d6941085dedaf7 /eeschema/plugins/python_scripts/round_value_robin.py | |
parent | 0db48f6533517ecebfd9f0693f89deca28408b76 (diff) | |
parent | aa35045840b78d3f48212db45da59a2e5c69b223 (diff) | |
download | KiCad-eSim-886d9cb772e81d2e5262284bc3082664f084337f.tar.gz KiCad-eSim-886d9cb772e81d2e5262284bc3082664f084337f.tar.bz2 KiCad-eSim-886d9cb772e81d2e5262284bc3082664f084337f.zip |
Merge pull request #1 from saurabhb17/develop
Added main functions
Diffstat (limited to 'eeschema/plugins/python_scripts/round_value_robin.py')
-rw-r--r-- | eeschema/plugins/python_scripts/round_value_robin.py | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/eeschema/plugins/python_scripts/round_value_robin.py b/eeschema/plugins/python_scripts/round_value_robin.py new file mode 100644 index 0000000..e1bf3ff --- /dev/null +++ b/eeschema/plugins/python_scripts/round_value_robin.py @@ -0,0 +1,74 @@ +# +# Example python script to generate an equivalent XML document from XML input +# +# Example: Round value robin, XML to XML conversion with partial value monging +# + +from __future__ import print_function + +# Import the KiCad python helper module and the csv formatter +import kicad_netlist_reader +import sys + +def checkvalue(self): + """Check values, and replace with preferred/consistent values""" + ref = self.getRef() + r = ref.split("R") + c = ref.split("C") + v = self.getValue() + + # Common to all values - convert decimation if necessary + dec = v.split(",") + if (len(dec) == 2): + newval = dec[0] + "." + dec[1] + self.setValue(newval) + v = self.getValue() + + if len(r) == 2 and r[1].isdigit(): + # This is a resistor - make values consistent + # If the value is a pure value, add R to the end of the value + if v.isdigit(): + i = int(v) + if (i > 1000000): + i = i / 1000000 + v = str(i) + "M" + if (i > 1000): + i = i / 1000 + v = str(i) + "K" + else: + v = str(i) + "R" + + self.setValue(v) + else: + # Get the multiplier character + multiplier = v[len(v) - 1] + v = v.strip(multiplier) + v = v.split(".") + if (len(v) == 2): + newval = v[0] + multiplier + v[1] + self.setValue(newval) + v = self.getValue() + + + +# Give components a new method for checking the values (this could easily be a +# Company Part Number generator method instead) +kicad_netlist_reader.comp.checkvalue = checkvalue + +# Generate an instance of a generic netlist, and load the netlist tree from +# the command line option. If the file doesn't exist, execution will stop +net = kicad_netlist_reader.netlist(sys.argv[1]) + +# Open a file to write to, if the file cannot be opened output to stdout +# instead +try: + f = open(sys.argv[2], 'w') +except IOError: + e = "Can't open output file for writing: " + sys.argv[2] + print(__file__, ":", e, file=sys.stderr) + f = sys.stdout + +for c in net.components: + c.checkvalue() + +print(net.formatXML(), file=f) |