Hi experts,
In PW, I checked out a DGN file (called "Ref"), and then used my MVBA to attach this file to another file in PW (called "Master") successfully. But this reference info can not be recognized by PW unless I used PWE's scan references. So what I need to do is add this reference info into Master's reference info, in other words, I need to do "Scan references" by code...
I searched this forum, got sevearl threads, like
Adding reference information via aaApi_CreateReferenceInformation2;
Attach a reference file programmetrickly (pardon my language :-)) using Object GUID or similar
So I used
aaApi_CreateReferenceInformation2 (1, &MasterGuid, 0, &RefGuid, 0, 177, 0, 2);
added a record successfully into dms_refinfo table, but PW still can't recognize this ref. It seems the first argument is not correct, so my question is what does the first argument refElemId mean? How can I get this value? Did I miss any other steps to scan references?
Thanks a lot in advance.
Firstly, let's analyze parameters of aaApi_CreateReferenceInformation2():
refElemId: reference file's id in master file(every reference will produce a element id in master file), it can get by mdl api mdlModelRef_getAttachmentID("DgnModelRefP"), there is similar interface in Automation(same lib with VBA) to get this, refElemId will be recorded to Table dms_refinfo's first field, through which mcm.ma(open dgn through pw will load this automatically)can synchronize reference's path name between pw and microstation.
pMasterGuid: a pw infomation, Master file's Guid. masterModelId: a Ms infomation, Master file's model id, often 0 to default model.pReferenceGuid: a pw infomation, Reference file's Guid.referenceModelId: a Ms infomation, Reference file's model id, often 0 to default model.referenceType: reference operation's type, e.g. AADMS_FTYPE_DGNV8 refers to v8i.nestDepth: nesting depth if reference file reference another file... flags: always AAREFINFO_PROP_FLAGS_DISPLAY_RASTER.
refElemId can't set to a positive number freely Otherwise ref info will miss.
I think this is the reason of your issue.
Another probable reason may be referenceType if you used v7 or other format file.
I tried many times: call aaApi_CreateLSet() then aaApi_CreateReferenceInformation2(), reference work perfectly just as scan tool's effect!
Answer Verified By: Wence
Thank you very much Lijun.
Actually I did exactly what you mentioned here, and I already knew refElemId can't be any arbitrary positive number, it must be the Element ID from the attachement, and I've writen the ref info successfully into the Master (see my post above). My problem is when I checked out this master, and checked it back in, the ref info is gone. And this issue is kind of random, sometime everything is fine, sometimes the ref info is missing. So I suspect I must have missed some other steps...
From your reply now I know I didn't miss any steps, so I focus on my code.
Before in my wrapper function, refElemId is passed by value as long
LONG WINAPI PWWriteRefInfo ( LONG MastPROJECT_ID, /* i Master Project ID*/ LONG MastDOCUMENT_ID, /* i Master Document ID */ LONG RefPROJECT_ID, /* i Ref Project ID*/ LONG RefDOCUMENT_ID, /* i Ref Document ID */ LONG RefEleId /* i RefElementId*/ ) { //..... status = aaApi_CreateReferenceInformation2 (UINT64(RefEleId), &MastDocGuid, 0, &RefDocGuid, 0, AADMS_FTYPE_DGNV8, 0, AAREFINFO_PROP_FLAGS_DISPLAY_RASTER ); return (status == TRUE ? SUCCESS : -1); }
and In VBA,
RefEleId = DLongToLong(oReference.ElementID) status = PWWriteRefInfo(m_lMasterProjId, m_lMasterDocId, m_lRefProjId, m_lRefDocId, RefEleId)
Now I pass the RefEleId ByRef
LONG WINAPI PWWriteRefInfo ( LONG MastPROJECT_ID, /* i Master Project ID*/ LONG MastDOCUMENT_ID, /* i Master Document ID */ LONG RefPROJECT_ID, /* i Ref Project ID*/ LONG RefDOCUMENT_ID, /* i Ref Document ID */ UINT64 * RefEleId ) { .... status = aaApi_CreateReferenceInformation2 (*(RefEleId), &MastDocGuid, 0, &RefDocGuid, 0, AADMS_FTYPE_DGNV8, 0, AAREFINFO_PROP_FLAGS_DISPLAY_RASTER ); return (status == TRUE ? SUCCESS : -1); }
and in VBA
RefEleId = oReference.ElementID status = PWWriteRefInfo(m_lMasterProjId, m_lMasterDocId, m_lRefProjId, m_lRefDocId, RefEleId)
so now everything seems fine, no random error.
Thanks again Lijun.