2025-05-08 09-05-06 llm畫線
頁面布置
?
?
?
?expand有自己的格式
刪了就會按照子元素格式?
?
不加px無效
沒有指定尺寸設置100%無效
怎么把線條導出dxf
@command({name: "file.export",display: "command.export",icon: "icon-export",
})
export class Export extends CancelableCommand {@Property.define("file.format")public get formats() {return this.getPrivateValue("formats", this.initCombobox());}public set formats(value: Combobox<string>) {this.setProperty("formats", value);}private initCombobox() {const box = new Combobox<string>();box.items.push(...this.application.dataExchange.exportFormats());return box;}protected async executeAsync() {const nodes = await this.selectNodesAsync();if (!nodes || nodes.length === 0) {PubSub.default.pub("showToast", "toast.select.noSelected");return;}PubSub.default.pub("showPermanent",async () => {const format = this.formats.selectedItem;if (format === undefined) return;const data = await this.application.dataExchange.export(format, nodes);if (!data) return;PubSub.default.pub("showToast", "toast.downloading");download(data, `${nodes[0].name}${format}`);},"toast.excuting{0}",I18n.translate("command.export"),);}
?
?
? 問題 3:缺少?TABLES
?段定義圖層等信息
如果你沒有定義圖層(Layer),某些軟件可能會忽略你的圖形。
? 推薦解決方案:補充 HEADER 和 TABLES 段落
下面是一個 完整且經過驗證可以在 FreeCAD 中正常打開的 DXF 示例,基于你提供的線條數據:
?
dxf模板? ? ? ? ? ? 不能用
0
SECTION
2
HEADER
9
$ACADVER
1
AC1027
9
$INSUNITS
70
4
0
ENDSEC0
SECTION
2
TABLES
0
TABLE
2
LAYER
701
0
LAYER
2
0
700
627
6
CONTINUOUS
0
ENDTAB
0
TABLE
2
LTYPE
701
0
LTYPE
2
CONTINUOUS
700
3
Solid line
7265
730
40
0.0
0
ENDTAB
0
ENDSEC0
SECTION
2
BLOCKS
0
BLOCK
8
0
2
*MODEL_SPACE
700
10
0.0
20
0.0
30
0.0
100
AcDbBlockBegin
3
*MODEL_SPACE
10
ENDBLK
100
AcDbBlockEnd
0
ENDSEC0
SECTION
2
ENTITIES
{{entities}}
0
ENDSEC0
SECTION
2
OBJECTS
0
DICTIONARY
5
F000
330
0
100
AcDbDictionary
3
ACAD_GROUP
350
F001
0
DICTIONARY
5
F001
330
F000
100
AcDbDictionary
0
ENDSEC0
EOF
讓ai打工?
放棄了,用三方庫
cnpm install three-dxf
// three-dxf.d.ts
declare module 'three-dxf' {class Point3D {x: number;y: number;z: number;constructor(x: number, y: number, z?: number);}class Drawing {header: {setVersion(version: string): void;setUnit(unit: string): void;};addLayer(name: string, options?: any): void;addLine(start: Point3D, end: Point3D): void;toString(): string;}export { Drawing, Point3D };
}
?
freecad打不開別的打開了
cnpm install @tarikjabiri/dxf
@tarikjabiri/dxf CDN by jsDelivr - A CDN for npm and GitHub
private async handleDxfExport(nodes: VisualNode[]): Promise<string[]> {// 創建一個新的 DXF 文檔const d = new DxfDocument();for (const node of nodes) {if (node instanceof LineNode) {const start = node.start;const end = node.end;// 創建線段并設置起點和終點const line = new Line({ x: start.x, y: start.y, z: Math.abs(start.z) < 1e-9 ? 0 : start.z },{ x: end.x, y: end.y, z: Math.abs(end.z) < 1e-9 ? 0 : end.z });// 添加到文檔的實體集合中d.entities.modelSpace.addEntity(line);}}const fullDxfContent= d.stringify(); // 轉換為字符串// 返回分割成行的數組,每行后加上換行符return fullDxfContent.split('\n').map(line => line + '\n');}
?
2年前的了,用python寫吧
python直接寫本地freecad可以打得開發回網頁就打不開
import ezdxf
import tempfile
import osdef draw_lines_and_get_dxf(lines):"""根據給定的線段列表繪制直線,并返回 DXF 文檔的字符串格式。:param lines: 線段列表,每個線段由起點和終點組成,格式為 [{"start": {"x": x1, "y": y1, "z": z1}, "end": {"x": x2, "y": y2, "z": z2}}, ...]:return: DXF 文檔的字符串表示"""# 創建一個新的 DXF 文檔doc = ezdxf.new('R2010')msp = doc.modelspace()# 遍歷每條線段并繪制直線for line in lines:print(line)start = (line["start"]["x"], line["start"]["y"], line["start"]["z"])end = (line["end"]["x"], line["end"]["y"], line["end"]["z"])msp.add_line(start, end)# 保存到臨時文件with tempfile.NamedTemporaryFile(suffix=".dxf", delete=False) as temp_file:doc.saveas(temp_file.name)temp_file_path = temp_file.name# 創建保存目錄save_dir = './run/dxf'os.makedirs(save_dir, exist_ok=True)# 另存為指定路徑save_path = os.path.join(save_dir, 'output.dxf')doc.saveas(save_path)# 讀取文件內容with open(temp_file_path, "r") as file:dxf_content = file.read()# 刪除臨時文件os.remove(temp_file_path)return dxf_content
打不開的:
打得開的
浪費了一下午發現是freecad打不開中文命名的文檔
不是卡中文可能@tarikjabiri/dxf包就能用了
2025-05-08 16-59-41 linenode導出dxf