PDMS 下有个 DARs 模块,它提供了访问模型数据库的 C 接口,可以不用启动 PDMS。DARs 模块需要单独授权。如果你用的是破解的,要注意这点,网上我找到的 11.5 和 11.6 版都是没有破解 DARs 模块,不过优易那里有破解的 DARs,看[1];12.1SP4的有破解 DARs。

DARs 没看到遍历属性的能力,只能对已知属性进行遍历,这就没法让人用这个导出完整的模型了。

以下是遍历 SAMPLE 模型,导出深度三层以内所有节点的 NAME 和 TYPE 属性。

#include <iostream>
#include <fstream>
#include <d3libc.h>
using namespace std;

#define check_error() if (id3err != 0) { return id3err; }

int dump_child(ofstream &fout, int indent)
{
	if (indent == 3)
		return 0;

	string str_indent(indent, '\t');

	int id3err = 0;
	int id3lis = 1;
	d3mnum("MEMBER", &id3lis, &id3err);
	check_error();

	bool isFirst = true;
	while (true)
	{
		PDMS_WORD cd3type;
		d3rtyp(cd3type, &id3err);
		check_error();
		if (strcmp(cd3type, "STLNKW") == 0
			|| strcmp(cd3type, "TPWL") == 0
			|| strcmp(cd3type, "LINKWL") == 0
			|| strcmp(cd3type, "APPLDW") == 0
			|| strcmp(cd3type, "CYMWRL") == 0
			|| strcmp(cd3type, "SYGPWL") == 0
			|| strcmp(cd3type, "ASSOWL") == 0
			|| strcmp(cd3type, "ASDFWL") == 0)
		{

		}
		else
		{
			PDMS_NAME name;
			d3rnam("NAME", name, &id3err);

			check_error();

			fout << str_indent << "NEW " << name << endl
				<< str_indent << "NAME:=  " << name << endl
				<< str_indent << "TYPE:=  " << cd3type << endl;

			id3err = dump_child(fout, indent + 1);
			check_error();
		}

		int cd3pos = 1;
		d3mrel(isFirst ? "FIRST" : "NEXT", "ELEMENT", &id3err);
		if (id3err == 203)
		{
			d3erst();
			d3mown(&id3err);
			check_error();
			return 0;
		}
		check_error();
		isFirst = false;
	}
	return 0;
}

int dump()
{
	int id3err = 0;

	d3umon("FULL");
	d3mmdb("DESI/SAMPLE", " ", &id3err);
	check_error();

	d3mnam("/*", &id3err);
	check_error();

	ofstream fout("tt.attr");

	id3err = dump_child(fout, 0);
	check_error();

	return 0;
}

int main()
{
	int id3err = 0;
	d3init("SAM", "SYSTEM", "XXXXXX", "FULL", " ", &id3err);
	if (id3err == 0)
		id3err = dump();

	d3umon("NONE");

	if (id3err != 0)
	{
		int ld3dis = 0;
		DARS_MESS cd3msg;
		d3emsg(&id3err, &ld3dis, cd3msg);
		printf("%s\n", cd3msg);
	}

	d3fin(&id3err);
	d3fend();
	return id3err;
}

  1. [下载]AVEVA PDMS DARS 动态链接库接口d3lib.dll

发表回复

您的电子邮箱地址不会被公开。