使用SOLIDWORKS API從CSV文件加載組件的演示變換

此示例演示如何從 CSV 文件加載組件的變換矩陣,并使用 SOLIDWORKS API 將其以演示變換(presentation transform)的方式應(yīng)用到組件中。
下載并打開(kāi)示例 SOLIDWORKS 文件。(https://www.codestack.net/solidworks-api/document/assembly/components/apply-presentation-transform-from-csv/presentation-transform-example.zip)
下載CSV文件并保存到硬盤(pán)。(https://www.codestack.net/solidworks-api/document/assembly/components/apply-presentation-transform-from-csv/transforms.csv)
修改宏常量中 CSV 文件的路徑。
運(yùn)行宏。宏停止執(zhí)行,組件變換了位置,如下所示。

紅色組件在 XYZ 空間中平移,綠色組件繞全局 Y 軸(軸 1)旋轉(zhuǎn) 90 度。
請(qǐng)注意,無(wú)論它們是否在空間中完全定義(通過(guò)配合或固定約束),組件都會(huì)移動(dòng)。而且配合仍然被保存下來(lái)。原因是應(yīng)用了演示變換(presentation transform)而不是永久變換。這允許僅出于視覺(jué)目的移動(dòng)組件,而無(wú)需更改幾何形狀。
使用 F5 或綠色“播放”按鈕繼續(xù)宏,以刪除演示變換。如果需要,請(qǐng)使用 IComponent2::Transform2屬性而不是 IComponent2::PresentationTransform 來(lái)應(yīng)用永久變換(在這種情況下,需要?jiǎng)h除任何不適合此變換的配合)。
IComponent2::Transform2(https://help.solidworks.com/2023/english/api/sldworksapi/SolidWorks.Interop.sldworks~SolidWorks.Interop.sldworks.IComponent2~Transform2.html)
IComponent2::PresentationTransform(https://help.solidworks.com/2023/english/api/sldworksapi/solidworks.interop.sldworks~solidworks.interop.sldworks.icomponent2~presentationtransform.html)
文章翻譯自https://www.codestack.net/
僅供學(xué)習(xí)使用。