1.什么是中望3D的SDK
类似UGNX的外部模式,中望的SDK可以脱离ZW3D软件在后台运行,不显示界面。但是SDK也有不足,相对接口比较少,有些功能不能实现。
2.如何使用SDK
ZW3D二次开发_SDK_如何使用SDK
3.代码示例
void SDK_遍历装配树(ZwObjHandle* pPartHandle)
{
//获取零件下的组件
int count = 0;
ZwObjHandle* pCompHandles = NULL;
ZF_SDK(ZwDbPartGetChildComps(pPartHandle, false, &pCompHandles, &count));
//遍历组件
for (int i = 0; i < count; i++)
{
//获取组件显示状态
//int visible = 0;
//ZF_SDK(ZwDbCompGetVisible(pCompHandles + i, &visible));
//WriteMessage("组件%s可见", visible ? "不" : "");
//获取组件抑制状态
int suppress = 0;
ZF_SDK(ZwDbCompGetSuppress(pCompHandles + i, &suppress));
WriteMessage("组件%s抑制", suppress ? "" : "未");
//获取组件对应的零件的文件路径和根对象
ZwLongPath filePath = { 0 };
ZwName rootName = { 0 };
//ZF_SDK(ZwDbCompGetInfo(pCompHandles + i, filePath, rootName));
ZF_SDK(ZwDbCompGetInfoLongPath(pCompHandles + i, filePath, rootName));
WriteMessage("filePath:%s", filePath);
WriteMessage("rootName:%s", rootName);
// string filePath;
// if (string(fileName).find_first_of("\\") == string::npos)//当获取到的零件与总装配的目录不一致时,ZwDbCompGetInfoLongPath返回的是文件名,不包含目录
// {
// //项目属性->配置属性->C/C++->语言->C++语言标准:ISO C++17 标准 (/std:c++17)
// //遍历特定目录及其子目录以查找该文件,返回第一个查找到的文件
// for (const auto& entry : std::filesystem::recursive_directory_iterator("C:\\Users\\Administrator\\Desktop\\测试多层组织模型\\"))
// {
// if (entry.path().filename() == fileName)
// {
// filePath = entry.path().string();
// break;
// }
// }
// }
// else
// {
// filePath = fileName;//当获取到的零件位于总装配相同目录下时,ZwDbCompGetInfoLongPath返回的是全路径
// }
// WriteMessage("filePath = %s",filePath.c_str());
//获取组件对应的零件
ZwObjHandle compPartHandle;
ZwDatabase compDB;
ZF_SDK(ZwDbCompGetPart(pCompHandles + i, &compDB, &compPartHandle));
//递归
SDK_遍历装配树(&compPartHandle);
}
ZF_VOID(ZwDbFree((void**)&pCompHandles));
}
void main()
{
const char* filePath = "C:\\Users\\Administrator\\Desktop\\ZW3D装配\\装配体.Z3ASM";
//打开文件
ZwDatabase db = { 0 };
ZF_VOID(ZwDbOpenFile(filePath, Z_MODE_READ, &db));
if (db.pBin == NULL)
{
WriteMessage("打开文件失败:%s", filePath);
return;
}
//获取零件对象
const char* rootName = "装配体";
ZwObjHandle* pPartHandle = ZwDbFindRootObject(&db, rootName);
if (pPartHandle == NULL)
{
WriteMessage("没有找到根对象:%s", rootName);
ZF_VOID(ZwDbCloseFile(&db));
return;
}
SDK_遍历装配树(pPartHandle);
//关闭文件
ZF_VOID(ZwDbCloseFile(&db));
}