User Tools

Site Tools


inventree

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
inventree [2024/05/04 09:55] utedassinventree [2024/05/04 22:10] (current) utedass
Line 9: Line 9:
 Generate resistors Generate resistors
 <code> <code>
-{"name":"","template_type":"PART","template":{"version":"1.2.3","input":{"firstDecade":"-2","tolerance":"5","decimalPlacesInBaseValues":"2","unitLetter":"Q"},"templates":[],"output":{"parent_name_match":"true","dimensions":["1.33, 1.40, 1.47","*NUMERIC","0603"],"count":["","3",""],"generate":{"name":"RES SMD {{global.descriptionValueStr}} OHM {{inp.tolerance}}% {{global.power}}{{dim.3}}","parameters":[{"template":"1","value":"{{global.titleValueStr}}"}]},"global_context":"{# Prepare lookup tables #}\n{% set prefixes = {-4: 'p', -3: 'n', -2: 'u', -1: 'm', 0: inp.unitLetter, 1: 'k', 2: 'M', 3: 'G', 4: 'T'} %}\n\n{# Prepare arguments and dimensions #}\n{% set baseValue = dim.1|float %}\n{% set decade =  (dim.2|int-1)+(inp.firstDecade|int) %}\n\n{# Calculate which prefix we are having #}\n{% set prefixIndex = decade//3 %}\n{% set prefix = prefixes[prefixIndex] %}\n\n{# Calculate values for different text formattings and round them to avoid float artifacts #}\n{% set actualValue = (baseValue * 10 ** decade)|round(inp.decimalPlacesInBaseValues|int -decade) %}\n{% set prefixedValue = (baseValue * 10 ** (decade % 3))|round(inp.decimalPlacesInBaseValues|int) %}\n\n{# Format a string for the value in my personal prefered format #}\n{% set titleValueStr = prefixedValue|string|replace('.',prefix)|trim('0') %}\n\n{# Format a string for the value in DigiKeys description format#}\n{# The adding of the @ sign is just an ugly way of inventing trim trailing characters.. #}\n{% if decade < 3 %}\n{% set descriptionValueStr = ('@'+actualValue|string)|trim('0')|trim('.')|trim('@') %}\n{% else %}\n{% set descriptionValueStr = ('@'+prefixedValue|string)|trim('0')|trim('.')|trim('@') + prefix %}\n{% endif %}\n\n{% set power = 0.1 %}"}}}+{"name":"","template_type":"PART","template":{"version":"1.2.3","input":{"firstDecade":"-3","tolerance":"1","decimalPlacesInBaseValues":"2","unitLetter":"R"},"templates":[],"output":{"parent_name_match":"true","dimensions":["1.0, 1.2, 1.5, 1.8, 2.2, 2.7, 3.3, 3.9, 4.7, 5.6, 6.8, 8.2","*NUMERIC","01005,0201,0402,0603,0805,1206,1210,2010,2512"],"count":["","11",""],"generate":{"name":"RES SMD {{global.descriptionValueStr}} OHM {{inp.tolerance}}% {{global.powerDescription}} {{global.footprintCode}}","parameters":[{"template":"1","value":"{{global.titleValueStr}}"},{"template":"7","value":"{{inp.tolerance}}"},{"template":"8","value":"-{{inp.tolerance}}"},{"template":"23","value":"{{global.power}}"},{"template":"27","value":"Thick Film"},{"template":"24","value":"100"},{"template":"25","value":"-100"},{"template":"3","value":"155"},{"template":"4","value":"-55"},{"template":"6","value":"{{global.footprintName}}"},{"template":"26","value":"{{global.footprintCode}}"}]},"global_context":"{# Prepare lookup tables #}\n{% set prefixes = {-4: 'p', -3: 'n', -2: 'u', -1: 'm', 0: inp.unitLetter, 1: 'k', 2: 'M', 3: 'G', 4: 'T'} %}\n{% set footprintNames = {'01005': '01005 (0402 Metric)','0201': '0201 (0603 Metric)','0402': '0402 (1010 Metric)','0603': '0603 (1608 Metric)','0805': '0805 (2012 Metric)','1206': '1206 (3216 Metric)','1210': '1210 (3225 Metric)','2010': '2010 (5025 Metric)','2512': '2512 (6332 Metric)'} %}\n{% set footprintPower = {'01005': '30m','0201': '50m','0402': '62.5m','0603': '100m','0805': '125m','1206': '250m','1210': '500m','2010': '750m','2512': '1'} %}\n{% set footprintDescriptionPower = {'01005': '1/32W','0201': '1/20W','0402': '1/16W','0603': '1/10W','0805': '1/8W','1206': '1/4W','1210': '1/2W','2010': '3/4W','2512': '1W'} %}\n\n{# Prepare arguments and dimensions #}\n{% set baseValue = dim.1|float %}\n{% set decade =  (dim.2|int-1)+(inp.firstDecade|int) %}\n{% set footprintCode = dim.3|string %}\n{% set footprintName = footprintNames[footprintCode] %}\n\n{# Calculate which prefix we are having #}\n{% set prefixIndex = decade//3 %}\n{% set prefix = prefixes[prefixIndex] %}\n\n{# Calculate values for different text formattings and round them to avoid float artifacts #}\n{% set actualValue = (baseValue * 10 ** decade)|round(inp.decimalPlacesInBaseValues|int -decade) %}\n{% set prefixedValue = (baseValue * 10 ** (decade % 3))|round(inp.decimalPlacesInBaseValues|int) %}\n\n{# Format a string for the value in my personal prefered format #}\n{% set titleValueStr = prefixedValue|string|replace('.',prefix)|trim('0') %}\n\n{# Format a string for the value in DigiKeys description format #}\n{# The adding of the @ sign is just an ugly way of inventing trim trailing characters.. #}\n{% if decade >=  0 and decade < 3 %}\n{% set descriptionValueStr = ('@'+prefixedValue|string)|trim('0')|trim('.')|trim('@') %}\n{% else %}\n{% set descriptionValueStr = ('@'+prefixedValue|string)|trim('0')|trim('.')|trim('@') + prefix %}\n{% endif %}\n\n{% set power = footprintPower[footprintCode] %}\n{% set powerDescription = footprintDescriptionPower[footprintCode] %}"}}}
 </code> </code>
  
inventree.1714816515.txt.gz · Last modified: 2024/05/04 09:55 by utedass

Except where otherwise noted, content on this wiki is licensed under the following license: CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki