bool AlembicCustomAttributesEx::defineCustomAttributes(INode* node, Abc::OCompoundProperty& compoundProp, const AbcA::MetaData& metadata, unsigned int animatedTs)
{
   Modifier* pMod = FindModifier(node, (char*)this->modName.c_str());

   if(!pMod){
      return false;
   }

	ICustAttribContainer* cont = pMod->GetCustAttribContainer();
	if(!cont){
		return false;
	}

	for(int i=0; i<cont->GetNumCustAttribs(); i++)
	{
		CustAttrib* ca = cont->GetCustAttrib(i);
		std::string name = EC_MCHAR_to_UTF8( ca->GetName() );
	
		pblock = ca->GetParamBlockByID(0);
      break;
	}

   if(!pblock){
      return false;
   }


	for(int i=0, nNumParams = pblock->NumParams(); i<nNumParams; i++){

		ParamID id = pblock->IndextoID(i);
		MSTR name = pblock->GetLocalName(id, 0);

      std::stringstream propName;
      propName<<EC_MSTR_to_UTF8(name);

      ParamType2 type = pblock->GetParameterType(id);
      if(type == TYPE_STRING){
         customProps[propName.str()] = new Abc::OStringProperty(compoundProp, propName.str().c_str(), metadata, animatedTs );
      }
      else if(type == TYPE_FLOAT){
         customProps[propName.str()] = new Abc::OFloatProperty(compoundProp, propName.str().c_str(), metadata, animatedTs );
      }
      else if(type == TYPE_INT){
         customProps[propName.str()] = new Abc::OInt32Property(compoundProp, propName.str().c_str(), metadata, animatedTs );
      }
	}
   
   return true;
}
void SaveMetaData(INode* node, AlembicObject* object)
{
  if (object == NULL) {
    return;
  }
  if (object->GetNumSamples() > 0) {
    return;
  }

  Modifier* pMod = FindModifier(node, Class_ID(0xd81fc3e, 0x1e4eacf5));

  bool bReadCustAttribs = false;
  if (!pMod) {
    pMod = FindModifier(node, "Metadata");
    bReadCustAttribs = true;
  }

  if (!pMod) {
    return;
  }

  std::vector<std::string> metaData;

  if (bReadCustAttribs) {
    ICustAttribContainer* cont = pMod->GetCustAttribContainer();
    if (!cont) {
      return;
    }
    for (int i = 0; i < cont->GetNumCustAttribs(); i++) {
      CustAttrib* ca = cont->GetCustAttrib(i);
      std::string name = EC_MCHAR_to_UTF8(ca->GetName());

      IParamBlock2* pblock = ca->GetParamBlockByID(0);
      if (pblock) {
        int nNumParams = pblock->NumParams();
        for (int i = 0; i < nNumParams; i++) {
          ParamID id = pblock->IndextoID(i);
          // MSTR name = pblock->GetLocalName(id, 0);
          MSTR value = pblock->GetStr(id, 0);
          metaData.push_back(EC_MSTR_to_UTF8(value));
        }
      }
    }
  }
  else {
    IParamBlock2* pblock = pMod->GetParamBlockByID(0);
    if (pblock && pblock->NumParams() == 1) {
      ParamID id = pblock->IndextoID(0);
      MSTR name = pblock->GetLocalName(id, 0);
      int nSize = pblock->Count(id);

      for (int i = 0; i < nSize; i++) {
        MSTR value = pblock->GetStr(id, 0, i);
        metaData.push_back(EC_MSTR_to_UTF8(value));
      }
    }
  }

  if (metaData.size() > 0) {
    Abc::OStringArrayProperty metaDataProperty = Abc::OStringArrayProperty(
        object->GetCompound(), ".metadata", object->GetCompound().getMetaData(),
        object->GetCurrentJob()->GetAnimatedTs());
    Abc::StringArraySample metaDataSample(&metaData.front(), metaData.size());
    metaDataProperty.set(metaDataSample);
  }
}