ZW3D二次开发_SDK_操作装配

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));
}
4.图文无关

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值