Retrieve all Outlinks in Doors DXL - ibm-doors

I used dxl code to retrieve all outlinks and it works ok .
But it seems it retrieve just some links and neglect others , and i don't know why !
here is code snippet
Object o
string label
Module m = read(planSpecReportPath_inDoors)
Link outLink
for o in m do
{
for outLink in o -> "*" do
{
parentModName = target(outLink)
iTarget= targetAbsNo(outLink)
can any one tell me what is general solution to get all outlinks ? and what is i am missing ?
thanks

first of all, for clarity's sake I though I should mention that your comment says your script gets all outlinks to current modules, but the script you posted will only retrieve outlinks from the module at path planSpecReportPath_inDoors. You can change the script to work for the current module by modifying your code to the following:
Module m = current Module
Secondly, if I understand your question and comment correctly, you want to cycle through each outlink in a module, including the outlinks from previous baselines right? this can be done with a fairly simple script:
Module baselineM = null
Module m = read(planSpecReportPath_inDoors)
Object o = null
Link outLink = null
Baseline b = null
for b in all m do
{
// Load the current baseline and display it
baselineM = load(m, b, true)
for o in entire(m) do
{
for outLink in o -> "*" do
{
parentModName = target(outLink)
iTarget= targetAbsNo(outLink)
// Whatever else you want to do with each link
}
}
}
Basically, you would need to cycle through each baseline individually, then cycle through all of the objects in that baseline, then cycle through each link. I hope that answers your question!

Related

How to Create a view that shows all existing attributes DOORS in all formal modules under a single project?

I have a project under which there are 50+ formal modules in IBM DOORS,
I want to create a single view for all modules ( As default view )
This view should display all the attributes that are available for that particular module when I open it.
And the number of attributes in some modules vary.
If anyone in stack-overflow knows a way on this, It would be really helpful!
Before anything, you should probably be aware that there is a maximum number of attributes that can be loaded into a view. You can check out this thread for more information regarding max columns:
https://www.ibm.com/developerworks/community/forums/html/topic?id=1861480b-7aa0-43b2-bf77-be677f5f778e
Now as for how to do this. If you're looking for an automated solution using DXL here's some sample code that you can modify for your purposes. The current code will add object-level attributes that aren't system attributes to the current view of the module you run this code from.
AttrDef ad
Module m = current Module
string sAttrName
int count = 0
Column col
for col in m do {count++}
for ad in m do
{
if ((ad.object) && (!ad.system))
{
sAttrName = ad.name
col = insert (column count)
attribute(col, sAttrName)
width(col, 200)
count++
}
}
Note: This code will only generate a view with all attributes in the module it is run from, it will not loop through all modules in a project or save the view.
To loop through a project and get all modules you'll need to create a recursive function using for itemRef in folder do {...}. Something like the following:
Folder f = current Folder
void recurseFolder(Folder f)
{
Item iRef
for iRef in f do
{
if (type(iRef) == "Formal")
(call your create views function here with parameter iRef)
else if (type(iRef) == "Folder" || type(iRef) == "Project")
recurseFolder(folder(iRef))
}
}
recurseFolder(f)
And then if you need additional code to save the view, you'll have to add appropriate code for that too using save(View v). You can look up additional information pertaining to setting view preferences and saving them in the DXL Reference Manual.

RATIONAL DOORS DXL, transfering a versioned link from a formal module to an other

So, I'm trying to make a formal module merging tool right now, and everything is working so far, except link copy. Here's how we copy
We empty already baselined reception formal module
We copy object with correct hierarchy
Then we should copy links
(Yes, it's more of a destroy and rebuild tool, than merging, but still, end result is the same)
The problem is, for incoming links, I'm told the source object of the link is inaccessible, even though the formal module is loaded, and I can access and do whatever I want with it. Here's the code to copy Incoming Links
for o in entire PRBaseline do
{
//Once current PBS has been emptied, start recovering objects from baseline
print "Inside Object : " o."IE PUID" "\n" ""
//Once current PBS is emptied & reconstructed to this PBS baseline, do links.
Link incomingLink
Link outLink
Object sourceObject
Object targetObject
for incomingLink in all(o <- "*") do //Iterate on all incoming baselined links, and load source module
{
ModName_ srcModRef = source(incomingLink)
Module temp = edit(fullName(srcModRef),true)
sourceObject = source(incomingLink)
Object oPRCurr
print name srcModRef
print sourceObject."IE PUID" ""
for oPRCurr in modOldPR do
{
print "Currently on Object : " oPRCurr."IE PUID" " and object : " o."IE PUID" "\n" ""
if (oPRCurr."IE PUID" "" == o."IE PUID" "")
{
createLinkset(fullName(srcModRef), fullName(modOldPR), "Test")
print sourceObject."IE PUID" "\n" ""
sourceObject -> "/Test_Access/Test" -> oPRCurr
print "Creating link between source object : " sourceObject."IE PUID" " & target object : " oPRCurr."IE PUID" " from" name srcModRef "\n" ""
}
}
}
}
As for outgoing links I'm not even able to recover the target object of the link, even though I've loaded in edit mode the targeted module
// Continuation of preceding code block
for outLink in all(o -> "*") do
{
ModName_ srcModRef = target(outLink)
print name srcModRef " est la cible \n" ""
Module temp = read(fullName(srcModRef),true)
targetObject = target(outLink)
Object oPRCurr
print name srcModRef
for oPRCurr in modOldPR do
{
print "Currently on Object : " oPRCurr."IE PUID" " and object : " o."IE PUID" "\n" ""
if (oPRCurr."IE PUID" "" == o."IE PUID" "")
{
createLinkset(fullName(srcModRef), fullName(modOldPR), "Test")
oPRCurr -> "/Test_Access/Test" -> targetObject
print "Creating link between target object : " " " " & source object : " oPRCurr."IE PUID" " from" name srcModRef "\n" ""
}
}
}
I'm sorry if I'm already asking a question that's been asked before, but I can't figure out why it doesn't want to work, and I've tried a lot of solutions already.
So, I actually found the answer after a whole lot more of digging. I'll post it below to help people that need to do this.
So, first of all, regarding incoming links the problem to not having access to the link was actually that I recoverd the baseline object, and not the current version object, like that, I was therefore only able to recover info, not edit the object (As it should be !). Therefore the solutionn should be then to actually open the CURRENT module, and find the object via a comparaison key (I hope you have a way to find the object back). Afterwards, I just proceed as before, with the only difference being that I have the current object, and not it's baselined counterpart.
For outgoing links, the matter was a little trickier, I was able to recover my target module name BUT I couldn't load objects from it for the life of me. The problem was, that you have to actually open the baselined module, to recover the baselined object, to recreate the link. To do so, I loaded it like this (know, that I'm iterating on Baseline Sets in this code, that's what the bs variable is)
Module temp = load(test,baseline(major bs, minor bs, suffix bs), true)
and proceeded as before. Now the scripts works perfectly well, so if you need precisions on the way I do this, feel free to ask below, I'll answer to the best of my capacity.

delete all incoming links to specified module with dxl

Something went wrong I got no error but links are not deleted.
Link l
Object o
for o in document current Module do
{
for l in all ((o) <- ("/GMH/test4")) do
{
void delete(Link l)
}
}
I think here is the solution it works on my code. It is deleting links from a module to another one!
void deleteLinksFromSSS(string moduleName)
{
for tgtObject in document current Module do
{
Object o = tgtObject
Object t
Link l
for l in o -> "*" do
{
t = target(l)
t <- o
delete l
}
flushDeletions
}
}
Despite how it may appear, links are actually stored in the 'outgoing' object side.
In the code you've provided, you are scanning for each incoming link, then deleting the link- but that doesn't actually do anything, because the link 'lives' on the other side of the transaction. You need to grab the link information, then go to the object where the link originates and delete from there.
Part of this will be making sure the module that contains that object is open in edit mode. There are examples of this code in the reference guide.

Print the target of an outlink

According to the DOORS Reference Manual, this code will print the source module identification of an inlink:
Object o = current
string srcModName
for srcModName in o<-"*" do print srcModName "\n"
This does work, however what I'm trying to do is print the target module identification of an outlink. I thought simply switching o<- to o-> would do the trick, but it doesn't. Does anyone know why, and how to fix this?
Not sure why that doesn't work but this does:
Object o = current
string tgtMod
Link l
for l in o -> "*" do
{
tgtMod = target(l)
print tgtMod "\n"
}
It doesn't work simply because there is no loop construct with that signature. All you have to work with is what's listed in the DXL Reference Manual.
EDIT: I forgot to mention though that Steve's answer is the way to do it if you just want the name of the target module.

Using tables in other files

Edit I got this working, I'm not sure if this is the right way to do it, but this is what works right now
I just started learning Lua, and I'm trying to figure out how to pass tables between files so that I can have a more organized codespace. I have read through the book Programming in Lua, and for some reason, I can't figure out what i'm doing wrong.
The problem i'm getting is this error:
lua: Test2.lua:3: attempt to call method 'New' (a nil value)
From this code:
--Test.lua----------------
module("Test", package.seeall)
vector = require "./Hump/vector"
Bot = {}
Bot.position = vector.new(0,0)
function Bot:New(object)
object = object or {}
setmetatable(object, self)
self.__index = self
return object
end
--Test2.lua------------------
require "Test"
Bot1 = Test.Bot:New()
print(Bot1.position)
As far as I understand it, this error means that it cannot find the method new, it is effectively undefined. I thought that require imports the file in the path?
Bot is an empty table.
local B = {} -- initialize local B with new table
Bot = B -- Bot now references the same table as B
B = { position = vector.new(0,0) } -- here you create a NEW table, B ~= Bot now
function B:New(object) -- store New function in B table, Bot still empty
So you're returning an empty table.
No need for two variables here at all.
local Bot = {
-- stuff
}
function Bot:New(object)
-- stuff
end
return Bot

Resources