Generate negative Gerber file for drawings

Hi,
is there a way to obtain a negative gerber file from i.e. a positive drawing in an internal user layer?

I’ve found this interesting script here:

Unfortunately it seems it is not possible to invert directly a gerber file…

It seems to me it is necessary to create a filled area covering all pcb area and then subtract to this the file to be inverted.
I would like to know if this feature could be obtained internally in kicad or externally without manual extra work.

Gerber does have support for negative features, for example with:
%TF.FilePolarity,Negative*%

(Source: Gerber X2 standard from Ucamco, page 131)

This is commonly used for the soldermask, in which all the D-codes usually are subtracted from the cencil. Best I know, it also has support for negative features in restricted areas, but I never looked for the syntax.

But what is the goal you want to achieve? There may be better methods to get there. Gerber is normally regarded as an “end” format that you send to the fab. if you want to put some kind of logo on your PCB, then it’s probably to process it in a graphical drawing program before you import it in KiCad.

Everything can be written to the fab, but giving them the correct data is the best.

The code you pointed out seems to be an internal comment or at least is what is added at the beginning of the mask files (I’m not in front of a pc ATM to check the internal syntax).

I’ve not tried this but could you not plot the “gerbers” as dxf or one of the other options? Then negate the colors in another program.

Again:

Gerber output for the user layers is a bit ??? And then invert it too?

confused0024

Yes, a user layer as an intermediate layer to elaborate the result… Obviously
in the final packaging of the gerbers it will be renamed as silkscreen or an other production layer.
Just to be more clear, a tool that creates some artwork with the layers is svg2shenzen.

This is more complicated than create a full filled area and subtract it with the python utils, directly with the gerber format.

Which is also my point. If you want to import some graphical things, then inverting the graphics before you import them into KiCad is almost certainly a better option. KiCad is not very strong in graphic manipulation and there are far better editors for such things. KiCad focuses on PCB layout, not fanciness.

I explained a similar path, not exactly my path.
Still I’m asking if someone has a solution for inverting a gerber file.
Please reply if you have a way to invert it.

Have you came across this?:

“Most major design tools produce Positive and Negative gerbers based on the Layer Type for each copper plane. If the Layer Type is set to “Signal”, then the design tool will produce Positive gerbers, which are suitable for our production. If the Layer Type is set to Power, then it will produce Negative gerbers, which will not work with our process without correction.”
https://docs.oshpark.com/troubleshooting/inverted-gerbers/

This tool will also help inverting the polarization of the gerber files:

hope this helps

I don’t understand why you are so obtuse. Having a boarder look at a problem often leads to better solutions and avoids the XY problem

But if you want a direct answer, it’s simple: There is no such option in KiCad.

'Cause of your obtusion :rofl:

1 Like

Thanks, I will have a look at that.

%IPNEG*%

From:

A 23 year old document?

I already mentioned the X2 standard from Ucamco. (Apparently that was not good enough, or I’m being to obtuse) X3 version has also been released a few years ago but I don’t know how widespread their use is. A more direct link:

Even more direct, and despite the link name, the document says: “Revision 2024-05”. X2 and X3 have apparently been combined in a single document now:

@maui My old brain is slow thinking… Is this what you’re trying to accomplish?

In the image sequence: I didn’t bother loading Drill Holes…
1 = PCB
2 = GerbViewer
3 = print of GerbViewer
4 = Inverted Print of GerbViewer

ADDED#1: Perhaps just spinning my wheels (to borrow an old expression) but, this is a Simple approach… I’ll leave here with a Video (if you’re looking at Coding something as a Stand-Alone, Plugin or addition to Workbench… may give you Python idea’s…

ADDED#2: I dug into my old Download directory, pulled out a Gerber-Viewer, updated it.
Loaded a Gerber, set background to Grey( could choose any color including Black) and toggled the Positive/Negative feature… Last screenshot.

ADDED#3: The last one, I promise! I manually edited the Gerber File and changed ‘Positive’ to ‘Negative’ then opened it in the above mentioned Gerber viewer and Bingo, the Inverse’d Color worked. Thus, Editing that ‘word’ alone is sufficient to make it happen in a Modern (meaning, not old) Gerber Viewer. I also opened them in Kicad’s GerberViewer and it worked, very last image below.

Screen Shot 2024-07-31 at 14.59.39

Set the Background to Greenish for observing color difference

yeah, working directly with the Gerber format!

I’m pinging @bobc to see if he can update his scripts to add the option to simply invert a gerber file…

Not knowing what you want, aside from stated above, this may help you… It changes Positive to Negative and verifies it by manually opening the file Before and After the change

You can Copy&Paste the Code, as shown in Video or, If you want it in a Plugin, that’s 3 minutes of work… let me know…

Bubba_SandR_ThisFile.py (363 Bytes)

thanks, but unfortunately this simple command attribute inside the gerber doesn’t seem to work/be used with the gerber viewer and factories…

The only way I have found atm is the one I stated in the first post… using the script to subtract from a fullfil area the desired gerber to be inverted.