我正在编写一个DXL脚本,它通过多个级别跟踪链接。我注意到,当模块打开时,脚本会正确地遍历这些链接。但是,有大约20个模块要迭代,我不想打开所有这些模块。如何在不必手动打开链接模块的情况下查看这些链接?
以下是我的代码示例:
// Checks to see if the object exists or not. If not returns a null.
// This will be eventually adapted to make sure the object is from a
// specific set of modules, but for now we're just checking for ability
// to retrieve
Object getObject(Link obj_link) {
ModuleVersion other_ver = null
ModName_ other_mod = null
Object other_obj
other_ver = sourceVersion obj_link
other_mod = module(other_ver)
if (null other_mod || isDeleted other_mod) return null
other_obj = source obj_link
if (null other_obj) load(other_ver, true)
other_obj = source obj_link
if (isDeleted other_obj) return null
return other_obj
}
// Displays the object from a specific link module if it's found
void showOut(Object o) {
Link l_obj_link
string s = null
Item linkModItem = itemFromID(MODULE_ID)
string linkModName = fullName(linkModItem)
for l_obj_link in all(o <- linkModName) do {
Object test_obj
display("Test")
test_obj = getObject(l_obj_link)
if (null test_obj){
display("Null Object Found")
} else {
s = probeRichAttr_(test_obj, "Object Identifier", false)
displayRich(s)
}
}
}
// Call showOut for the object
showOut(obj)
再次,使用它作为布局DXL脚本,当且仅当链接模块被打开时,我才能看到对象ID。
答案 0 :(得分:1)
首先,我建议您使用Analysis -> Wizard
,并确保选择All Modules
而非All Open Modules
的选项来代替生成所有代码,然后修改该代码如果它没有完全满足您的需要,则显示您想要的内容。
但是,如果您只想更新现有代码,则需要更改getObject
函数以包括静默打开每个模块(以获取模块必须打开的信息,但不需要可见)。
Object getObject(Link obj_link) {
ModuleVersion other_ver = null
ModName_ other_mod = null
Object other_obj
other_ver = sourceVersion obj_link
other_mod = module(other_ver)
Module m = read(fullName(other_ver), false) // false, tells it to open silently.
if (null other_mod || isDeleted other_mod) return null
other_obj = source obj_link
if (null other_obj) load(other_ver, true)
other_obj = source obj_link
if (isDeleted other_obj) return null
return other_obj
}
这应该也可以,但我仍然建议从分析向导开始,因为它会更清洁。
答案 1 :(得分:0)
您需要使用链接引用(load
)LinkRef
模块。这是一个简单的函数,可以加载特定LinkModule和Object的所有模块:
// Loads all incoming linked modules for the given link module and Object. To load from
// ALL link modules use the linkModName = "*"
void LoadSourceModules(string linkModName, Object o) {
ModName_ otherMod = null
LinkRef lr
// For each incoming link check to see if the moduel exists, isn't deleted and loaded
// if not loaded `(null data(sourceVersion lr))` then load the module.
for lr in all(o<-linkModName) do {
otherMod = module(sourceVersion lr)
if (!null otherMod) {
if ((!isDeleted otherMod) && (null data(sourceVersion lr))) {
load((sourceVersion lr), false)
}
}
}
}