API 參考
Facade 操作
匯入 Mattmy\DwgConverter\Facades\Dwg 即可呼叫這些方法。
Dwg::thumbnail(UploadedFile|string|DwgBinary $source): ThumbnailExtraction
Dwg::toDxf(UploadedFile|string|DwgBinary $source): DxfConversion
Dwg::toJson(UploadedFile|string|DwgBinary $source): JsonConversion
Dwg::toImage(UploadedFile|string|DwgBinary $source): ImageConversion
Dwg::layers(UploadedFile|string|DwgBinary $source): LayerReading
Dwg::entities(UploadedFile|string|DwgBinary $source): EntityReading
Dwg::version(UploadedFile|string|DwgBinary $source): DwgFileVersion
Dwg::info(UploadedFile|string|DwgBinary $source): InfoReadingversion() 立即讀取檔頭。其他方法只綁定來源並回傳新的操作物件,綁定時沒有 I/O。 請參考輸入與輸出。
圖面資訊
InfoReading::read(): DwgInfoDwgFileVersion 提供 code: string 和 format: ?string。DwgInfo 包含 version、 drawingUnits、summary 和 timestamps。請參考讀取圖面資訊。
ThumbnailExtraction
extract(): DwgOutput擷取內嵌 BMP、PNG 或 WMF 預覽。請參考擷取縮圖。
DxfConversion
toVersion(DxfVersion $version): self
convert(): DwgOutputtoVersion() 回傳已指定目標版本的新操作;convert() 建立 ASCII DXF。請參考 轉換為 DXF。
DxfVersion 可選值:R12、R14、R2000、R2004、R2007、R2010、R2013、R2018。
JsonConversion
convert(): DwgOutput建立 LibreDWG 結構 JSON,沒有目標版本或格式選項。請參考輸出結構 JSON。
ImageConversion
format(ImageFormat $format): self
usingDxfVersion(DxfVersion $version): self
atResolution(ImageResolution $resolution): self
convert(): DwgOutput每個選項都回傳新操作並保留其他選擇。請參考建立圖片預覽。
ImageFormat:PNG、JPEG、WEBP。ImageResolution:HIGH、MEDIUM、LOW。
LayerReading
onlyOn(): self
read(): Collection<int, DwgLayer>onlyOn() 回傳新操作,選取未關閉且未凍結的圖層,其中可以包含鎖定的圖層。 DwgLayer 提供唯讀欄位:name: string、isFrozen: bool、isOff: bool、isLocked: bool。 篩選方式與狀態說明見圖層資料查詢。
圖元查詢
使用方式見圖元資料查詢。
// EntityReading
onlyLayers(string|DwgLayer|array|Collection $layers, string|DwgLayer ...$additionalLayers): self
read(): DwgEntityQueryResultonlyLayers() 接受圖層名稱、DwgLayer,或由這兩種值組成的清單或 Laravel 集合。 陣列須為從索引 0 開始的平面清單。集合可使用任意鍵。無效項目會拋出 InvalidArgumentException。 圖層物件只以名稱比對,之後修改傳入的集合不會影響選取條件。
篩選方法
complete(): DwgEntityCollection
incomplete(): DwgEntityCollection
withColorMode(DwgColorMode $mode): DwgEntityCollection
ofType(DwgEntityType|string $type): DwgEntityCollection
onLayer(string $name): DwgEntityCollection
withOwnerKind(DwgOwnerKind $kind): DwgEntityCollection
referencingBlock(string $name): DwgEntityCollection
withIssue(DwgEntityIssueReason $reason): DwgEntityCollection這些方法可從查詢結果或圖元集合呼叫,也可串接使用。上方列的是查詢結果的方法簽章。 DwgEntityCollection 的同名方法回傳 static,並保留索引、順序與圖元物件。
選項型別皆位於 Mattmy\DwgConverter:
ofType():可用DwgEntityType::LINE等 enum,或直接傳入'LINE'等原始類型字串。withOwnerKind():DwgOwnerKind::MODEL_SPACE、PAPER_SPACE、BLOCK_DEFINITION、UNKNOWN。withColorMode():DwgColorMode::ACI、TRUE_COLOR、BY_LAYER、BY_BLOCK、UNKNOWN。withIssue():傳入DwgEntityIssueReason,例如DwgEntityIssueReason::TARGET_NOT_FOUND。
查詢結果
DwgEntityQueryResult 提供 entities、drawingUnits 與 diagnostics。 各筆圖元的 issues 描述單筆解析問題;diagnostics 描述整次查詢的資訊,有內容不一定表示失敗。 常用欄位的取值方式與問題判讀,請參考看懂查詢結果。
DwgBinary
DwgBinary::from(string $contents): DwgBinary
$binary->contents(): string包裝原始位元組內容,避免直接傳入字串時被當成本機路徑。
DwgOutput
extension(): string
mimeType(): string
output(): string
storeAs(string $path, ?string $name = null, ?string $disk = null): stringextension() 與 mimeType() 可以重複讀取。每個 DwgOutput 只能從 storeAs() 和 output() 選一個呼叫一次。 若呼叫失敗,請重新執行原本的操作以取得新的結果。複製、序列化或反序列化 DwgOutput 都會拋出 LogicException。
儲存路徑與檔名規則請見一次性輸出。
例外
LibreDwgUnavailable、InvalidDwg、DwgOperationFailed 都提供:
reason(): string
context(): array請參考錯誤與疑難排解。
版本之間的變更請參考 Changelog。