Topic
  • 3 replies
  • Latest Post - ‏2013-11-04T15:47:12Z by llandale
bandchef
bandchef
21 Posts

Pinned topic How to get a module reference from a link?

‏2013-10-31T12:00:48Z |

Hi!
 

I must get a module reference from a link. My code is:

gmod_CurrentModule2 = module(lnk_InnerOutLink1)

for gobj_CurrentObject2 in gmod_CurrentModule2 do

{

print targetAbsNo(lnk_InnerOutLink1)

}

 

The first line should give me the reference from the link to the module in that way, that the for Loop can operate in the common way but, if I start the code, the for-loop reads not all objects from the module.

 

Where is the mistkae?

Updated on 2013-10-31T12:01:52Z at 2013-10-31T12:01:52Z by bandchef
  • etleg
    etleg
    12 Posts

    Re: How to get a module reference from a link?

    ‏2013-10-31T13:57:04Z  

    Hi

    i am not sure about your question, but I think you are looking for something like this or you can use it create what you need.

    Module m = current

    ModName_ modRef

    Object o

    Link l

    for o in entire m do {

              for l in all o->"*" do {           // maybe in-links?? then o<-"*"

                        modRef = target(l)

                        print fullName modRef

              }

    }

    German

  • bandchef
    bandchef
    21 Posts

    Re: How to get a module reference from a link?

    ‏2013-11-04T14:24:49Z  
    • etleg
    • ‏2013-10-31T13:57:04Z

    Hi

    i am not sure about your question, but I think you are looking for something like this or you can use it create what you need.

    Module m = current

    ModName_ modRef

    Object o

    Link l

    for o in entire m do {

              for l in all o->"*" do {           // maybe in-links?? then o<-"*"

                        modRef = target(l)

                        print fullName modRef

              }

    }

    German

    Thank you for your answer. I have attached a .dxl-File with the whole code which I have programmed on my own. There are a module "Output", "LH" and "SCS.

    The first for-loop iterates all objects in module "Output". The first inner for-loop iterates over all links of the current object. The next important statement: gmod_CurrentObject2 = module(lnk_InnerOutLink1) should write the module-reference to which the current link Points to.

    I don't know, but I think this is the first mistake. The module() statement don't work in this way I assume module() should work.

    The module gmod_CurrentModule2 should be the module which the current link points to.

    The second inner for-loop iterates all objects of the current module now. The current module now is "LH".

    The third inner for-loop iterates all links of the current object.

     

    If the last link from the third inner for-loop is iterated, the first for-loop will take the next object of module Output

     

     

    Do you understand the system behind my script? In each for-loop I will read attributes of the particular current object and write information in specific attributes of the output module.

    Attachments

  • llandale
    llandale
    2972 Posts

    Re: How to get a module reference from a link?

    ‏2013-11-04T15:47:12Z  
    • bandchef
    • ‏2013-11-04T14:24:49Z

    Thank you for your answer. I have attached a .dxl-File with the whole code which I have programmed on my own. There are a module "Output", "LH" and "SCS.

    The first for-loop iterates all objects in module "Output". The first inner for-loop iterates over all links of the current object. The next important statement: gmod_CurrentObject2 = module(lnk_InnerOutLink1) should write the module-reference to which the current link Points to.

    I don't know, but I think this is the first mistake. The module() statement don't work in this way I assume module() should work.

    The module gmod_CurrentModule2 should be the module which the current link points to.

    The second inner for-loop iterates all objects of the current module now. The current module now is "LH".

    The third inner for-loop iterates all links of the current object.

     

    If the last link from the third inner for-loop is iterated, the first for-loop will take the next object of module Output

     

     

    Do you understand the system behind my script? In each for-loop I will read attributes of the particular current object and write information in specific attributes of the output module.

    module(Link) returns a handle of the Link Module.  You want the target module.  A "Link" is composed of a Source Object (in a formal module), a Target Object (in a formal module), and a Link Set (in a Link Module).

    For OUTLINKS (this object is the source) you can always get the "Link" handle.  But the target module may not yet be open, so you get a reference to it and open it.  Then you can see the target Object.   There are a couple ways to do that, here is one; add checks for "null" along the way.

    • for lnk in o ->"*" do
    • {  ModName_ mnTarget(target(lnk))
    •    Module mTarget = read(fullName(mnOther, false, true))
    •    Object oTarget = target(lnk)
    •    ...
    • }

    I have to say looping through the target module's Objects does not seem reasonable.  If you are trying to get a Handle on objects that are 2 links away, then get a Handle on the 1st target object, then loop through that target's outlinks.

    For INLINKS (this object is the target), you must first get a reference to the Source module, open it, then loop through the links.  So you have an extra loop.  That looks like this:

    • LinkRef lr
    • for lr in o <- "*" do
    • {  read(fullName(lr), false, true)
    • }
    • for lnk in o<"*" do
    • {  oSource = source(lnk)
    •     ...
    • }

    It gets stickier if you allow "versioned" links; where a link here can go to a baselined module.

    If you know exactly which link module, then replace "*" with the name.  However, general scripts don't know the name of the current Project, and for other reasons I use generic relative names for my link modules.  For example, any link in any link module named "Test Links" are for testing links.  My code, then, looks like this:

    • for lnk in o ->"*" do
    • {  mLM = module(lnk)
    •    if (name(mLM) != "Test Links")      then continue   // don't care about this link
    •    ...
    • }

    You can add attributes to your Link Modules and then these become accessible to the links themselves.  perhaps add attribute "Verified by" to the link module, and when folks "verify" a link (whatever that means), they can change the link attr value to their name.  Your DXL can then:

    • Name = lnk."Verfied By"
    • if (null Name) then link not yet verified

    All this code requieres checking for null values before continuing.  Otherwise your DXL will abort often.  Also, if your code plows through links in many modules, these other modules are opened and never close.  You need either to keep track of which ones you opened, or routinely close all opened modules.  Yuuuuuck.

    On other news...

    [1] Since "setLinkFeature()" is a function, you need a "void" in front of it:

    • void setLinkFeature()

    [2] If you break at object 28 I'm guessing you want to update the display:

    • current = gobj_CurrentObject1
    • refresh(gmod_CurentModule1)

    [3] if you are modifying an obj-attr value, you need to make sure your module is open edit:

    • if (!isEdit(gmod_CurrentModule1)) then Ooops.

    -Louie

    This is a pet-peave of mine, but using the word "Current" in your variable names may lead to confusion, since "Current" has a connotation not present in your script.  Now your gmod_CurrentModule1 is appropriate since it is indeed the "current" module, but none of the other Object/Module referrences are actually "current".

    Updated on 2013-11-04T15:48:27Z at 2013-11-04T15:48:27Z by llandale