Topic
10 replies Latest Post - ‏2014-02-27T14:03:16Z by GregM_dxler
KBSri
KBSri
104 Posts
ACCEPTED ANSWER

Pinned topic I need to obtain the linked object ID's of the object via DXL Scripting

‏2014-02-25T11:50:47Z |

Hello,

I need to obtain the Object IDs of the linked objects in the module.

For e.g.: If a module contains object ID as - SYS_403, It has two links which in turn points to other Object Id's - SR-9.

I have obtain those object IDs in a separate column as SYS_SR_9.

Please help.

  • Mathias Mamsch
    Mathias Mamsch
    1911 Posts
    ACCEPTED ANSWER

    Re: I need to obtain the linked object ID's of the object via DXL Scripting

    ‏2014-02-25T13:02:34Z  in response to KBSri

    If you use the search on the forum you will find a lot of examples for that. Search for something like "iterate links" or "get link target". Please use the search before posting. Regards, Mathias

  • GregM_dxler
    GregM_dxler
    160 Posts
    ACCEPTED ANSWER

    Re: I need to obtain the linked object ID's of the object via DXL Scripting

    ‏2014-02-25T15:35:01Z  in response to KBSri

    I agree with Mathias.  Seems like this forum is starting to become a dxl script request site instead of a place to learn about dxl.

    Instead of a dxl script for this, it seems like DOORS already provides what you want.  Use the Analysis Wizard or the Link Analysis tool.  You can set the depth in the Link Analysis tool to recursively go from link to link.  This is also a good way to get a framework of what you want to do in dxl and then edit it to your liking.

    Maybe I'm just getting crabby from the long winter.

    Greg

    • KBSri
      KBSri
      104 Posts
      ACCEPTED ANSWER

      Re: I need to obtain the linked object ID's of the object via DXL Scripting

      ‏2014-02-26T04:05:10Z  in response to GregM_dxler

      It s not script request!!!! We guys are new to scripting...We are in assumption that we will get an idea over here!!

      Thanks for your replies.

      • KBSri
        KBSri
        104 Posts
        ACCEPTED ANSWER

        Re: I need to obtain the linked object ID's of the object via DXL Scripting

        ‏2014-02-26T10:28:28Z  in response to KBSri

        Hello All,

        I am not requesting for a script. I got stuck up here. Please help if u wish.

        I need to obtains the Object IDs of all the incoming links of the objects.

        But I am able to obtain only one objects ID, but if there are many object IDs for the object it is not able to obtain.

        Please help.

        bIngoingLinkObjIDs = false        
                      

        string derivedObjIDsSource = ""
        string derivedObjIDsTarget = ""
        string derivedObjIDsSourceTarget = ""
                    
        for l in obj <- "*" do

        {
                            bIngoingLinkObjIDs = true
                            Object ObjnameSource = source(l)
                            Object ObjnameTarget = target(l)
                        
                            derivedObjIDsSource = identifier(ObjnameSource)
                            derivedObjIDsTarget = identifier(ObjnameTarget)
                            
                            print "\nDerived Object IDs:" derivedObjIDsSource "_" derivedObjIDsTarget "\n"
                            derivedObjIDsSourceTarget = derivedObjIDsSource "_" derivedObjIDsTarget
        }

        • adevicq
          adevicq
          154 Posts
          ACCEPTED ANSWER

          Re: I need to obtain the linked object ID's of the object via DXL Scripting

          ‏2014-02-26T10:45:28Z  in response to KBSri

          Hi,

          If you loop through links and try to get the source object you will get a "null" value if the corresponding module is not loaded.

          I suggest you to use a "LinkRef" instead of a "Link":

          LinkRef l
          ModName_ mnSrc
          int nAbs
          Module mSrc 
          Object oSrc
          
          for l in o<-"your link module" do {
              nAbs = sourceAbsNo(l)           // Gets the source object absolute number
              mnSrc = source(l)               // Gets the source module name
              mSrc = load(moduleVersion(mnSrc), false) // Loads the source module
              oSrc = object(nAbs, mSrc)       // Reads the source object
          }
          

          Play with these perms and you will probably find a solution...

          In addition, if you need to store more than one value, you should use a Skip list. check the DXL help. It is well documented.

          Regards,

          Alain

          • KBSri
            KBSri
            104 Posts
            ACCEPTED ANSWER

            Re: I need to obtain the linked object ID's of the object via DXL Scripting

            ‏2014-02-26T11:17:38Z  in response to adevicq

            Thanks a ton. I need this kind of help to improve myself. Yes your idea of replacing the links with linkRef can be done.

            I need to get the Target Object IDs of the source Object.

            For e.g: Source Object ID has SYS_49 and it has two ingoing links such as SR_23 and XR_76.I need to get both of them stored in an string as SYS_49_SR_29; SYS_49_XR_76 respectively.

            Updated on 2014-02-26T11:43:46Z at 2014-02-26T11:43:46Z by KBSri
            • GregM_dxler
              GregM_dxler
              160 Posts
              ACCEPTED ANSWER

              Re: I need to obtain the linked object ID's of the object via DXL Scripting

              ‏2014-02-26T14:01:59Z  in response to KBSri

              KBSri,

              The above example from adevicq is good to get link information.  A couple of things to note though.

              If you want to get all incoming links, then use "*" for the "your link module".  Otherwise it will only loop through incoming links through "your link module".  Many times what happens is people will make links without linksets made up and DOORS will put the link information in a DOORS links link module.  Same thing is true with looping through outgoing links, using "*" for the "your link module" will go through all links, not just the ones in the link module.

              For incoming links, you need to have at least read access to the module the link is sourced from.  If you don't have read access, then it will skip the links.  This has bit me as well.  The easiest way to tell if there is an incoming link that you don't see, is to try and delete the object.  DOORS will tell you it can't be deleted because there is an incoming link.

              I still don't understand why you don't use the link tools in DOORS to help you.  Run the link wizard to have it populate a column with the object IDs of the source of the incoming links.  Then you can right click on the column heading, select properties and then look at the dxl code it writes.  You can copy and paste this into your editor to use as a starting point.  Maybe it is because of the previous issues I've mentioned as to why you can not do this?

              Hope this helps,

              Greg

        • GregM_dxler
          GregM_dxler
          160 Posts
          ACCEPTED ANSWER

          Re: I need to obtain the linked object ID's of the object via DXL Scripting

          ‏2014-02-26T14:07:42Z  in response to KBSri

          One more thing on your posted code.

          The loop is going through incoming links.  source(l) works to find the source of the incoming link, but target(l) is used to find the object where the outgoing link goes to.  The target of the incoming link is the object it is working on.  That is, it would be identifier(obj).

          If you want to loop through outgoing links, then you would use identifier(obj) for the "source" of the link and then target(l) to find the object to where the link goes.

          Hope this helps,

          Greg

          • KBSri
            KBSri
            104 Posts
            ACCEPTED ANSWER

            Re: I need to obtain the linked object ID's of the object via DXL Scripting

            ‏2014-02-27T10:03:06Z  in response to GregM_dxler

            Greg thanks a lot for your invaluable suggestions for newbie.But what I require is for incoming links only.

            Now I am able to fetch only one of the ObjectID corresponding to the Source module Object ID,but what I am not able to do is store all the IDs in the same string.

            More over I have used the link tools in DOORS but what I need is in DXL Scripting.

            Thanks a ton in advance.Please suggest.

            • GregM_dxler
              GregM_dxler
              160 Posts
              ACCEPTED ANSWER

              Re: I need to obtain the linked object ID's of the object via DXL Scripting

              ‏2014-02-27T14:03:16Z  in response to KBSri

              It sounds like the problem is not in getting the links but to save the link information together.  What your code is doing is overwritting what is currently there.  The simpliest way is when you save the link information for one link you just add it to the string.  So instead of your command

              derivedObjIDsSourceTarget = derivedObjIDsSource "_" derivedObjIDsTarget
               You use

              derivedObjIDsSourceTarget = derivedObjIDsSourceTarget ", " derivedObjIDsSource "_" derivedObjIDsTarget

              A better and more efficient way to handle it is to use a buffer instead of a string variable.  To do this, the declaration would be

              Buffer derivedObjIDsSourceTarget = create

              Then when you want to add stuff to it, you use the command

              derivedObjIDsSourceTarget += ", " derivedObjIDsSource "_" derivedObjIDsTarget

              And then for cleanup you would use the following command at the end of your program.

              delete derivedObjIDsSourceTarget

              Hope this helps,

              Greg
               

              Updated on 2014-02-27T14:04:38Z at 2014-02-27T14:04:38Z by GregM_dxler