Draw line segment from python


#1

I’m trying to draw a segment on B.SilkS, but can’t see anything when I execute the code below. What am I doing wrong?

(KiCAD 4.0.6; Windows 7)

            ds=pcbnew.DRAWSEGMENT(self._board)
            self._board.Add(ds)
            #ds.SetShape(pcbnew.S_SEGMENT)
            ds.SetStart(pcbnew.wxPoint(corners[i].x,corners[i].y))
            ds.SetEnd(pcbnew.wxPoint(corners[i+1].x,corners[i+1].y))
            ds.SetLayer(self._LayerNumByName["B.SilkS"])
            ds.SetWidth(int(0.15*pcbnew.IU_PER_MM))

#2

Have you enabled the “B.SilkS” layer to be displayed? Does it use a color that is easily seen on your display?

Dale


#3

Yes. I have other items on that layer that are visible. I continue to test, and sometimes the layer is not added, sometimes the properties aren’t set, and sometimes the python variable itself doesn’t seem to get a value. Very weird. When i’vd repeated the commands in the console, I can verify that the object appears in the GetDrawings() list, and gets the right properties. It simply never appears on the board.


#4

Have you tried it in both Legacy and OpenGL modes?


#5

I hadn’t tried different modes until your message. When I switch modes, the line appears. And then switch back (to OpenGL), it still is there.

So something about switching seems to enable the display of the new DRAWSEGMENT.

I haven’t tried all combinations (staying in legacy or cairo modes, or switching from/to all combinations).

Now at least there’s a successful path to display. There’s still a bug somewhere though…


#6

I’ve also had this issue with the OpenGL display. Updating the board via python doesn’t update the OpenGL display. That includes moving adding objects, moving objects and deleting them. It does update in the legacy display.

If you figure out a way to refresh the OpenGL display, can you post it?


#7

Will do. I have seen objects on which SetHighlight() is executed get updated on OpenGL (Windows) when the mouse enters the pcbnew window.


#8

I’ve filed this as a KiCad bug. It still happens in nightly (as of July 31, 2017).