How can I get the coordinates of a given port name...
# magic
u
How can I get the coordinates of a given port name in the currently selected subcell?
t
Indirectly. Say the port name is "A". Then:
Copy code
goto A
box
If you want to pass back the coordinates to do something with in another command, then
Copy code
set rect [box values]
This will give you the coordinates of the box shape to which the label is attached. If you want a point, then you will have to compute the center or use the lower left corner. Values will be in internal coordinates; you can convert from internal units to microns using
magic::i2u <value>
.
u
Thanks Tim! It doesn't seem to work for a label inside a subcell.
What I'm basically trying to do is: I have two subcells, and I want to connect their
clk
port together by drawing a metal2 wire via a script
so that's why I need to get the coordniates of the
clk
ports that are inside the subcells
t
goto instance_0/clk
, then, where
instance_0
is the instance name, and do the same thing, then
goto instance_1/clk
, repeat.
🤩 1
u
Awesome! I see that there's also a
corner
command that helps me do L shapes when routing. Are there any other commands that are similarly useful when I lay down wires through a scripts?
This is what the code currently looks like:
Copy code
proc port_coords {name} {
  goto $name
  set coords [box values]
  return [list [magic::i2u [lindex $coords 0]] [magic::i2u [lindex $coords 1]] [magic::i2u [lindex $coords 2]] [magic::i2u [lindex $coords 3]]]
}

# Route clk net
goto x2/clk
box grow left 1u
paint metal1
goto x3/clk
box grow left 1u
paint metal1
set start_point [port_coords x2/clk]
set end_point [port_coords x3/clk]
box [lindex $start_point 0]u [lindex $start_point 3]u [lindex $end_point 2]u [lindex $end_point 1]u
box move left 1u
paint metal1
Any suggestions for improvements?
this is what the resulting wire looks like:
image.png
so the code works, but there might be an easier way I'm missing
t
wire segment <layer> <width> <x1> <y1> <x2> <y2> [-noendcap]
The interactive wiring in magic is just a loop around a set of command options for the command
wire
, so it can be scripted as well as done interactively, although I have not tried that approach before.
✅ 1
There is also the command
polygon <layer> <x1> <y1> <x2> <y2> ...
(I just tried using the interactive commands and the problem is that they behave according to the pointer position, and I think this is an issue with
logcommands
meaning that I am missing command options to make the interactive wiring able to be logged, which would require the ability to express the statement with a cursor position, like
wire horizonal at 500 0
. But that doesn't exist and won't until I code it up.)