Cancel
Showing results for 
Search instead for 
Did you mean: 

ITK : Copy named reference from Dataset

Creator
Creator

Hello,

 

I want copy a named reference in a new Dataset in ITK but every time I have an error.

 

This is how I proceed :

retcode = AE_create_dataset_with_id(dataset_type_tag, object_name_str, description, 0, 0, &new_dataset_tag);

 

retcode = AOM_save(new_dataset_tag);

 

retcode = AE_find_dataset_named_ref2(dataset_tag, dataset_instance, &reference_name, &reference_type, &reference_tag);

 

retcode = AE_add_dataset_named_ref2(new_dataset_tag, reference_name, AE_PART_OF, reference_tag);

--> This function always return "Unable to add reference to dataset %1$s of type %2$s, refName %3$s".

 

Do you have an idea?

 

Thank you.

 

 

4 REPLIES 4

Re: ITK : Copy named reference from Dataset

Valued Contributor
Valued Contributor
Try to copy the file by IMF_copy_file first, then attach it to the new dataset.

Re: ITK : Copy named reference from Dataset

Creator
Creator

Thank you very much for your answer.


Now,  I have this error when I do:

retcode = IMF_copy_file(reference_tag, "test", &new_file_tag, &file_descriptor);

 

--> The preference "%1$s" cannot be found.."

Re: ITK : Copy named reference from Dataset

Valued Contributor
Valued Contributor

The following example works for me:

static void do_it(void)
{
    int n = 0, j = 0, err = 0;
	tag_t ir_tag = NULLTAG, relation_type_tag = NULLTAG, 
		ds = NULLTAG, *secondaries, dsTypeTag = NULLTAG, nRef = NULLTAG, 
		tool_tag = NULLTAG, relation_tag = NULLTAG, curDsTypeTag = NULLTAG;
	AE_reference_type_t refType;

	ITEM_find_rev("TEST1234", "-", &ir_tag);
	GRM_find_relation_type("IMAN_specification", &relation_type_tag);
	AE_find_datasettype2("Text", &dsTypeTag);
	GRM_list_secondary_objects_only(ir_tag, relation_type_tag, &n, &secondaries);
	for(j = 0; j < n; j++)
    {
		 AE_ask_dataset_datasettype(secondaries[j], &curDsTypeTag);
		 if (curDsTypeTag == dsTypeTag) {
			 AE_ask_dataset_named_ref2(secondaries[j], "Text", &refType, &nRef);
			 break;
		 }
	}
	ITKCALLR(AE_create_dataset_with_id(dsTypeTag, "NEW_DATASET", "NEW_DATASET", 0, 0, &ds));
	ITKCALLR(AE_ask_datasettype_def_tool(dsTypeTag, &tool_tag));
	ITKCALLR(AE_set_dataset_format2(ds, "TEXT_REF"));
	ITKCALLR(AE_set_dataset_tool(ds, tool_tag));
	ITKCALLR(AOM_save(ds));
	ITKCALLR(AOM_unlock(ds));
	// attach the new dataset to item rev
	AOM_refresh(ir_tag, TRUE);
	ITKCALLR(GRM_create_relation(ir_tag, ds, relation_type_tag, NULLTAG, &relation_tag));
	err = ITKCALLR(AOM_save(relation_tag));
	if (err == ITK_ok)
		ITKCALLR(AOM_unlock(relation_tag));
	AOM_unlock(ir_tag);

	// add named reference to the new dataset
	err = ITKCALLR(AOM_refresh(ds, TRUE));
	if (err == ITK_ok)
		ITKCALLR(AE_add_dataset_named_ref(ds, "Text", AE_PART_OF, nRef));
	if (err == ITK_ok)
		err = ITKCALLR(AOM_save(ds));

	if (n > 0) MEM_free(secondaries);
}

Re: ITK : Copy named reference from Dataset

Siemens Genius Siemens Genius
Siemens Genius

Your code is principaly correct. Add a named reference taken from one dataset to a other dataset one is the fast way which creates only meta data (database) without really copy the file.

 

Possible problem:

dataset_type_tag is not the type of dataset_tag

the created dataset is not full defined - tool, format

the dataset might be locked, experiment with position od save/unlock

 

Take a look in the syslog, there shall be the full message text and check the %2$s and %3$s. Or extend your code by evaluating the EMH_ask_errors instead of just EMH_ask_error_text (example)