Teamcenter 获取首选项代码记录

Teamcenter 获取首选项代码示例:

/**
	 * 获取首选项
	 */
	public static Map<String, String> getPreferencesDatas(TCSession session, String mPreferenceName) {
		Map<String, String> xmlItemMap = new HashMap<String, String>();
		String[] xmlItemAttrs = getPreferenceValuesByStrNames(mPreferenceName, session);
		if (xmlItemAttrs != null && xmlItemAttrs.length > 0) {
			for (int i = 0; i < xmlItemAttrs.length; i++) {
				String xmlItemStr = xmlItemAttrs[i];
				if (!"".equals(xmlItemStr) && xmlItemStr != null) {
					String[] xmlAtts = xmlItemStr.split(":");
					if (xmlAtts.length == 2) {
						xmlItemMap.put(xmlAtts[0], xmlAtts[1]);
					}
				}
			}
		}
		return xmlItemMap;
	}
	public static String[] getPreferenceValuesByStrNames(String mPreferenceName, TCSession session) {
		return session.getPreferenceService().getStringArray(TCPreferenceService.TC_preference_site, mPreferenceName);
	}

例如:创建test首选项

	public String test() {
		Map<String, String> itemAttributeMap = Tc.getPreferencesDatas(session,"test"); 
		if (itemAttributeMap == null || itemAttributeMap.size() == 0) {
			Tc.msgBox("请检查首选项test的配置情况");
		}
		String ip = itemAttributeMap.get("ip");
		return ip;
	}

你可能感兴趣的:(tc,Teamcenter,二次开发)