Access to ${REFERENCE} and ${VALUE}

Hello,

I want to duplicate the references and values of components in pcbnew to layers User.1 and User.2.

To do this, I added footprints properties ${REFERENCE} and ${VALUES} that copy respectively the reference and value fields of the footprint.

In the properties popup , those fields are described as “text items”. I didn’t find a way to access and manipulate those fields in the python console. did I miss something in the API ?

Thanks

c.

I believe that qu1ck gave an answer to this a week ago.

Yeah, in addition to that post:
footprint has Drawings() list of all graphical items including custom text objects. But footprint’s built in reference and value text items are accessed directly with Reference() and Value(). If you want copy of those on another layer then easiest way is to access them, create a copy with constructor or Clone() method, change layer and then add to footprint using it’s Add() method.

thanks for your answers but maybe i did not explain correctly my problem :i dont want to copy Reference and Value values to another layer. i want to use the defined system variables defined in k6 that will keep my copy synchronous with the reference and value updated by schematic.

I have something like the attached image and want to access and work on the fields ${REFERENCE} and ${VALUE}

maybe it’s just not possible.

anyway, thanks to those who answered :slight_smile:

board = pcbnew.GetBoard()
fps = board.GetFirstFootprint()
fptext = pcbnew.FP_TEXT(fps)
fptext.SetText("${VALUE}")
fps.Add(fptext)
fptext.SetLayer(pcbnew.F_SilkS)
pcbnew.Refresh()

(I’m not sure which steps are really necessary, I just tried quickly.)

The result is a new text item in the silkscreen (large text centered on the footprint):

image

It is possible. What have you tried?
eelik above showed a working example of creating one. To access one use footprint’s GraphicalItems().

thanks!

now i can access those objects.
Next step is to modify or create items if they do not exist and set them as i want but it should not be a poblem.

the following script lists them footprint by footprint if it can help someone.

import pcbnew
board=pcbnew.GetBoard()
footprints=board.GetFootprints()
for fp in footprints:
	print(fp.GetReference(), "--",fp.IsFlipped()) 
	for gi in fp.GraphicalItems():
		if gi.GetClass()=="MTEXT":
			print("text: ", gi.GetText(), " - layer: ", gi.GetLayerName())
			print("thickness: ", gi.GetTextThickness(), " - Width:  ", gi.GetTextWidth(), " - Height: ",gi.GetTextHeight())	
			print("visible: ",gi.IsVisible())		
	print("---")
1 Like

Use markdown to format blocks of code, otherwise whitespace is lost and what you posted is not a valid python program.

In your case triple backticks surrounding the code will do.

1 Like

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