ezdxfを使用して、既存の.dxfファイルのモデルスペースにエンティティを追加しようとしています。挿入されたエンティティの場所は、私が期待する場所から完全に外れています。
円の場合、e.dxf.insertを使用してエンティティの位置座標を取得し、この点を円の中心として使用しました。私は次のコードを使用しました:
import ezdxf
dwg = ezdxf.readfile("drainage.dxf")
msp = dwg.modelspace()
dwg.layers.new(name='MyCircles', dxfattribs={'color': 7})
def encircle_entity(e):
if e.dxftype()=='INSERT':
circleCenter = e.dxf.insert
msp.add_circle(circleCenter, 10, dxfattribs={'layer': 'MyCircles'})
print("Circle entity added")
washBasins = msp.query('*[layer=="WASH BASINS"]')
for e in washBasins:
encircle_entity(e)
dwg.saveas('encircle.dxf')
drainage.dxf(入力)およびencircle.dxf(出力)ファイルへのリンク:https://drive.google.com/open?id = 1aIhZiuEdClt0warjPPcKiz4XJ7A7QWf_
これにより円が作成されますが、位置が正しくありません。
dxfファイルの原点とezdxfが使用する原点はどこにありますか?すべてのエンティティ、特にINSERT、LINES、CIRCLESの正しい位置を取得するにはどうすればよいですか?ezdxfを使用して、既存のdxfファイルの目的の位置にエンティティを配置するにはどうすればよいですか?座標に関して、線のe.dxf.startポイントとe.dxf.endポイントはどこにありますか?
ここの座標に何かが欠けていると思います。座標がどのように機能するかを説明してください。
@LeeMacソリューションのPythonバージョンですが、OCSを無視します。
import ezdxf
from ezdxf.math import Vector
DXFFILE = 'drainage.dxf'
OUTFILE = 'encircle.dxf'
dwg = ezdxf.readfile(DXFFILE)
msp = dwg.modelspace()
dwg.layers.new(name='MyCircles', dxfattribs={'color': 4})
def get_first_circle_center(block_layout):
block = block_layout.block
base_point = Vector(block.dxf.base_point)
circles = block_layout.query('CIRCLE')
if len(circles):
circle = circles[0] # take first circle
center = Vector(circle.dxf.center)
return center - base_point
else:
return Vector(0, 0, 0)
# block definition to examine
block_layout = dwg.blocks.get('WB')
offset = get_first_circle_center(block_layout)
for e in msp.query('INSERT[name=="WB"]'):
scale = e.get_dxf_attrib('xscale', 1) # assume uniform scaling
_offset = offset.rotate_deg(e.get_dxf_attrib('rotation', 0)) * scale
location = e.dxf.insert + _offset
msp.add_circle(center=location, radius=1, dxfattribs={'layer': 'MyCircles'})
dwg.saveas(OUTFILE)
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加