cdelker/schemdraw

How do I add anchors to elements?

bear-fighter opened this issue · 1 comments

I'd like to add an additional anchor point on flow.Box. Do you have a code example that might show how to do that?

I'd like to place one anchor between the NW and the N anchors so I can connect a line to it.

The easiest way to add custom anchor points is probably to subclass the element and define the new anchors in the __init__:

class MyBoxWithAnchors(flow.Box):
    def __init__(self, w: float = 3, h: float = 2, **kwargs):
        super().__init__(w, h, **kwargs)
        self.anchors['myanchor'] = (w/8, h/2)

Then use the Element and anchor as usual:

with schemdraw.Drawing() as d:
    d += (b:=MyBoxWithAnchors())
    d += elm.Dot().at(b.myanchor)

But before you do that, note that flow.Box already has a NNW anchor that may be what you're looking for.