如何將文字實體寫入 dxf 檔案?
我找到了一個可以將 SketchUp 繪圖匯出為 dxf 檔案的腳本,但不幸的是它忽略了圖層和文字。我修復了它,以便它輸出正確的圖層,但我不知道如何讓它輸出文字。
我已經做到了當遇到實體集合中的文字實體時會彈出一條訊息,但我不確定如何讓它正確地將其寫入檔案。
答案1
def dfx_output_text
model = Sketchup.active_model
entities = model.entities
if (entities.length > 0)
$dxf_file = File.new( "test.dxf" , "w" )
i = 0
while i < (entities.count)
if(entities[i].typename == "Text")
dxf_ouput_text(entities[i])
end
i+=1
end
end
end
def dxf_ouput_text(text)
points = text.point
$dxf_file.puts( " 0\nTEXT\n1\n192\n330\n1F\n100\nAcDbEntity\n8\n"+text.layer.name+"\n")
$dxf_file.puts("100\nAcDbText\n")
if(points == nil)
$dxf_file.puts("10\n0.0\n")#x
$dxf_file.puts("20\n0.0\n")#y
$dxf_file.puts("30\n0.0\n")#z
else
$dxf_file.puts("10\n"+points.x.to_f.to_s+"\n")#x
$dxf_file.puts("20\n"+points.y.to_f.to_s+"\n")#y
$dxf_file.puts("30\n"+points.z.to_f.to_s+"\n")#z
end
$dxf_file.puts("39\n"+text.line_weight.to_s+"\n")#thickness
$dxf_file.puts("40\n"+(1).to_s+"\n")#text height
$dxf_file.puts("1\n"+text.text+"\n")#text
end