How to add Reference Info to Master file?

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.

Parents
  • I tried. If fact , using any positive number can make aaApi_CreateReferenceInformation2 () work, i.e. write a record in dms_refInfo table. However if this number is not the reference' Unique ID, this record doesn't make sense. If you use Scan Reference tool to scan refs, this number will be overwritten by the the reference Unique ID, so the PW still can't recognize the reference.

    As I said above, my current problem is not about this argument, I can get it through MDL. My problem is even though I used the valid reference's unique ID, and PW recognizes the ref, but when I check out the master, and check it back in. The ref info is gone, so I must have missed some steps...
  • 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!

       
    This is a test

    Answer Verified By: Wence 

Reply
  • 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!

       
    This is a test

    Answer Verified By: Wence 

Children
  • 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.

  • Memory storage is different between UINT64 and LONG, the root cause of your random problem. Cheers.

    Your VBA can access both dgn files and pw data,so cool!

       
    This is a test