V5 Symbol Generator Multi-Unit

Hi All,

I’m trying to use the SymGen, but can’t seem to figure out how to create a symbol that has multiple units. I have modified the example as I wanted an import from CSV function added to it.

The insertion of all the pins I can see in the .lib, but when I open the symbol editor there is no Unit A, B, C, D. Just Unit A which has only the pins that Unit A should have. When I open the show pin table, all the rest of the pins for Units B-D are listed there, but I can’t access them.

I made the symbol to have 4 units and it just copied over pins in Unit A.

*Note I stay on the IRC channel often enough so if that’s easier you can talk to me there.

Symbol Generator Script - Original: https://gitlab.com/kicad/libraries/kicad-library-utils/-/blob/v5/schlib/autogen/demo-KiCadSymbolGenerator.py

Modified Script for my CSV

Select a unit to display with the dropdown combo box. You don’t need to offset pin positions per unit, each unit is a separate entity.

edit; sorry on closer inspection I misread the script. But I think

deMorgan_idx=pinUnit)) should be deMorgan_idx=1))

1 Like

The dropdown is grey and Number of Units is 1 when I open “Library Symbol Properties”

To be noted maybe I’m using this incorrectly too. I am running the script, copying the definiton of the symbol, then pasting it to the .lib in use. I originally thought this would append to the .lib but it seems to wipe it and overwrite. So that’s how I’m approaching using the script and adding to my library.

Edit: For the record bobc, I changed deMorgan_idx = 1.

Grey Dropdown
Pin List

You should be able to use the import feature of kicad to get the symbol into a lib of your choosing instead of relying on a text editor. (in the symbol editor under file import or similar)


Also you should be able to drag and drop at least one image per post here on the forum which would make it easier to read the information you provide. Maybe also schare the source file that you give to symgen.

I didn’t even know there was an importer function. I’ll try that.

I was going to post the CSV originally, but then was a new member and had a limit of 2 links/post.

My CSV

The first column is just for my reference of the true pinout of the PXI Card. I’m not really using KiCAD as intended.

Importer did the same thing as the copy/pasting. Still not reading as a multi-unit symbol.

I think you need to set the number of units after the loop:

current_symbol.num_units = lastUnit

Ah ha!

Thank you I didn’t catch that when I was reading the example. I set current_symbol.num_units = 4 and that worked. The pins for units B-D are all stacked on one location, but at least this is progress!

I suspect that KiCadSymbolGenerator may never have been used for multiple units, so there may be some quirks.

Make sure your unit numbers start at 1 not 0…

At least the v6 Generator is well tested.
I will add Split-Resistor-Networks to ‘R_Network.py’ and see how that works out.

edit: I added an issue for the v6 generator https://gitlab.com/kicad/libraries/kicad-library-utils/-/issues/353

For the record, I haven’t figured out the fix to the multi unit symbol pin-stacking issue. The generator also ‘skips’ a space which I don’t understand either. I have the YPos moving at 254*i, where i is an int from 1 to 50.

For some reason every third pin moves YPos two grid points down instead of one. Unsure why this happens, could be my code.

Need to look into this, but now is not the time sorry.

I made a few changes to your script, and it now generates a symbol how I would expect it to be (which may not be the same as you :slight_smile: :

# File intented to demo some functions available in the Symbol Generator module.
# Another example is the connecor generator

# sys.path.append(os.path.join(sys.path[0],..))
# load KiCadSymbolGenerator path
# add KiCadSymbolGenerator to searchpath using export PYTHONPATH="${PYTHONPATH}<absolute path>/autogen/"
# or use relative module path. Example ..KiCadSymbolGenerator

import csv
from KiCadSymbolGenerator import *

generator = SymbolGenerator('VPC')

current_symbol = generator.addSymbol('PXI-2575', interchangable=Symbol.UnitsInterchangable.NOT_INTERCHANGEABLE)
current_symbol.setReference('U', at={'x':0, 'y':250})
current_symbol.setValue(at={'x':0, 'y':150})

i = 0
lastUnit = 1

with open('PXIe2575.csv', newline='') as csvfile:
    reader = csv.reader(csvfile, delimiter=',', quotechar="|")
    for row in reader:
        pinNum = int(row[1])
        pinName = row[2]
        pinUnit = int(row[3])
        if lastUnit != pinUnit:
            rect = DrawingRectangle(start={'x':-100, 'y':100}, end={'x':250, 'y':-i*100}, unit_idx=lastUnit)
            current_symbol.drawing.append(rect)
            i = 0
            lastUnit = pinUnit
        yPos = -100*i
        i += 1

        current_symbol.drawing.append(DrawingPin(at=Point({'x':-250, 'y':yPos}), number=pinNum,
                                                          orientation=DrawingPin.PinOrientation.RIGHT,
                                                         name=pinName, pin_length=150, unit_idx=pinUnit, deMorgan_idx=1))


rect = DrawingRectangle(start={'x':-100, 'y':100}, end={'x':250, 'y':-i*100}, unit_idx=lastUnit)
current_symbol.drawing.append(rect)

current_symbol.num_units = lastUnit

current_symbol.drawing.translate({'x':-50, 'y':0})

generator.writeFiles()


zilenc.zip (2.6 KB)

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.