2022年2月14日 星期一

如何將平面轉變成曲面

使用PyAEDT模組,適合簡單平面。

# -*- coding: utf-8 -*-
"""
Created on Mon Feb 14 23:36:29 2022

@author: mlin
"""
from math import sqrt
from collections import defaultdict
from scipy import interpolate
from pyaedt import Hfss

hfss = Hfss(specified_version='2021.2')

x = hfss.modeler.object_list
path = x[1]
polygon = x[0]

ds = 0
s_map = {}
for edge in path.edges:
v1, v2 = edge.vertices
x1, y1, z1 = v1.position
x2, y2, z2 = v2.position
if len(s_map) == 0:
s_map[ds] = [(0, 0)]
ds += sqrt((x2 - x1) ** 2 + (z2 - z1) ** 2)
s_map[ds] = (x2, z2)

result = defaultdict(list)

for edge in polygon.edges:
v1, v2 = edge.vertices
x1, y1, z1 = v1.position
x2, y2, z2 = v2.position
x = [x1, x2]
y = [y1, y2]
f = interpolate.interp1d(x, y)
if x2 > x1:
new_s = [i for i in s_map.keys() if x2 >= i >= x1]
else:
new_s = [i for i in reversed(s_map.keys()) if x2 <= i <= x1]

print(new_s)
new_y = f(new_s)
for s, y3 in zip(new_s, new_y):
x3, z3 = s_map[s]
result[s].append((x3, y3, z3))

keys = [k for k in result]
pieces = []
for m, n in zip(keys[0:-1], keys[1:]):
v1, v2 = result[m][0:2]
v4, v3 = result[n][0:2]
p = hfss.modeler.primitives.create_polyline([v1, v2, v3, v4], cover_surface=True, close_surface=True)
pieces.append(p)

sheet = hfss.modeler.unite(pieces)
hfss.modeler.purge_history([pieces[0].name])



2022年2月8日 星期二

如何輸出任一AEDT專案3D模型不同視角圖片檔

範例碼如下(當中export3DModel在0.4.26版輸出.obj仍有問題,需手動修改):

import os
from pyaedt import Hfss
from pyaedt.generic.plot import ModelPlotter

hfss = Hfss('d:/demo/RADHAZ_MIL-STD-461C_ICNIRP.aedt', 'HERP', non_graphical=True)

data = {}
for i in hfss.modeler.object_list:
key = (i.color, i.transparency)
if key in data:
data[key].append(i)
else:
data[key] = [i]

cad = {}
for key, objs in data.items():
filename = objs[0].name
hfss.export3DModel(filename, hfss.temp_directory, '.obj', object_list=[i.name for i in objs])
cad[key] = os.path.join(hfss.temp_directory, filename + '.obj')

hfss.close_desktop()

model = ModelPlotter()
model.bounding_box = False
model.show_legend = False
model.show_grid = True
model.show_axes = False
model.off_screen = True
model.background_color = (240,240,240)
model.zoom = 1

for (color, transparency), cad_path in cad.items():
model.add_object(cad_path, cad_color=color, opacity=1-transparency)

for angle in range(0, 360, 30):
model.set_orientation('yz', 0, angle, 30)
model.plot('d:/demo2/view_{}.png'.format(angle))



EDB建立PinGroup

為U2A5建立GND PinGroup,儲存之後匯入EDB from pyaedt import Edb edb = Edb(edbpath= r"D:\demo\Galileo_G87173_20454.aedb" , edbversion= '20...