on 07-07-2015 10:48 AM
I have been merrily programmatically creating links from requirements to entities, however now I'm struggling to find the magic LDM Entity collection to create a link from entityA in model A (LDM) to EntityB in model B (LDM). I will also need to do the same for the attributes - but I'm sure the if the entity to entity mapping is done then attribute would be basically the same.
For requirements I've used:
Set newLink = requirement.TraceabilityLinks.createNew()
newLink.LinkedObject = destEntity
For the LDM entity level it appears the collection "TraceabilityLinks" isnt available as it only applies to Requirements, so I've tried the similar approach and hoped "ChildTraceabilityLinks" would do the same (but suspect this is more for folders than entities):
Set newLink = srcEntity.ChildTraceabilityLinks.createNew()
newLink.LinkedObject = destEntity
However it doesn't appear that this is working.
Does anyone have a working example/snippet of how to achieve this?
Many thanks,
Gareth
You almost there.
Assume your source LDM is called Source.ldm and it has entity srcEntity.
Your target LDM is called Target.ldm and it has entity targetEntity
set Source=openModel("D:\temp\Source.ldm")
set Target=openModel("D:\temp\Target.ldm")
''''' find srcEntity''''
for each e in Source.Entities
if e.name ="srcEntity" then
set srcEntity=e
end if
next
''''' find targetEntity''''
for each e1 in Target.Entities
if e1.name ="targetEntity" then
set targetEntity=e1
end if
next
''''' this is the code on how to create traceability link in entity''''''
Set newLink = Source.ChildTraceabilityLinks
set tracelink = newLink.createNew()
set tracelink.SourceObject = srcEntity
set tracelink.LinkedObject =targetEntity
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Perfect - many thanks,
I see the reason why you have to point it back, its interesting as I had assumed it behaved like the requirements - but in reality "createNew()" appears to be only a factory to create the link rather than a linking system (minor difference - but that is what tripped me up!)
So my mistake was that I was using createNew() from the entity itself and was unconsciously thinking it would point back to itself. Obviously not 🙂
Super helpful script above - many thanks,
Gareth
User | Count |
---|---|
84 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.