Hi,
//Initialize attribute strings
AttrDef creastr //final string
string aname
string desc
string type
string defval
string inhrtval
string exsfr
string mltval = null
//Construct attribute string
bool done = false
itr = 0
while(!done){
//Name
if(itr == 0){
//Set value
aname = "attribute " "\"" kval "\""
//Increment index
i++
}
//Description
if(itr == 1){
//Set value
desc = kval
//Increment index
i++
}
//Type
if(itr == 2){
//Set value
type = "type " "\"" kval "\""
//Increment index
i++
}
//Default value
if(itr == 3){
//Set value
defval = "(default " "\"" kval "\"" ")"
//Increment index
i++
}
//Inherit value
if(itr == 4){
//Set value
if(kval == "Yes")
inhrtval = "inherit true"
else
inhrtval = "inherit false"
//Increment index
i++
}
//Exists for
if(itr == 5){
//Set value
if(kval == "Module")
exsfr = "module"
else
exsfr = "object"
//Increment index
i++
}
//Enumerated values
if(itr == 6){
//Set flag
eflag++
//Determine value
if(kval == "strtEnum"){
//Set value
mltval = "(default " "\""
//Traverse enumerated values
bool finished = false
while(!finished){
//Do comparison
if(kval == "endEnum"){
//Terminate loop
finished = true
//Increment index
i++
}
else{
//Check value
if(kval != "strtEnum"){
//Check if last enumerated value
if((string get(keyArray,i+1,1)) == "endEnum"){
//Concatenate string
mltval = mltval kval
}
else{
//Concatenate string
mltval = mltval kval "\\n"
}
}
//Increment index
i++
//Extract string
kval = (string get(keyArray,i,1))
}
}
//Append closing string
mltval = mltval "\"" ") multi true"
}
}
//Increment iterator
itr++
//Determine if done
if(itr == 7){
//Terminate loop
done = true
}
else{
//Change string to new attribute
kval = (string get(keyArray,i,1))
}
}
//Create string
if(null mltval)
creastr = exsfr " " type " " defval " " inhrtval " " aname
else
creastr = exsfr " " type " " mltval " " inhrtval " " aname
//Create the attribute
create creastr
meherts - Thu Jun 17 09:28:14 EDT 2010 |
Re: How to dynamically create an attribute definition using strings What exactly are you trying to do with that code? There might be a more elegant way for whatever you are trying to achieve. Regards, Mathias Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS |
Re: How to dynamically create an attribute definition using strings
E-gads. Consider using spaces to indent, instead of tabs.
{ current = mod
noError()
if (DoModule and DoObject)
ad = create(module object //-
type NameType history DoHistory changeBars DoBars //-
date DoDate inherit DoInherit attribute NameAttr
)
elseif (DoModule and !DoObject)
ad = create(module //-
type NameType history DoHistory changeBars DoBars //-
date DoDate inherit DoInherit attribute NameAttr
)
elseif (!DoModule and DoObject)
ad = create(object //-
type NameType history DoHistory changeBars DoBars //-
date DoDate inherit DoInherit attribute NameAttr
)
else{} // must be either DoModule or DoObject or Both.
ErrMess = lastError() // Capture the Create error, if any
|
Re: How to dynamically create an attribute definition using strings Mathias Mamsch - Thu Jun 17 10:01:18 EDT 2010 Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS Here is what my code is trying to acheive: 1)read all attributes from a key module into an array (kval); 2) inspect all modules within DOORS to see if they have these key attributes - if they don't, create them. I've realized that the error with my code is that I'm trying to create an attribute using a string, instead of an attribute definition variable ... there has to be a more elegant way of acheiving what I'm trying to do. |
Re: How to dynamically create an attribute definition using strings One of the corelaries of that is this: its a lot easier to make understandable software work than mis-understandable software. Thus, always right code for the benefit of the reader 6 months from now.
|
Re: How to dynamically create an attribute definition using strings llandale - Thu Jun 17 12:22:08 EDT 2010
E-gads. Consider using spaces to indent, instead of tabs.
{ current = mod
noError()
if (DoModule and DoObject)
ad = create(module object //-
type NameType history DoHistory changeBars DoBars //-
date DoDate inherit DoInherit attribute NameAttr
)
elseif (DoModule and !DoObject)
ad = create(module //-
type NameType history DoHistory changeBars DoBars //-
date DoDate inherit DoInherit attribute NameAttr
)
elseif (!DoModule and DoObject)
ad = create(object //-
type NameType history DoHistory changeBars DoBars //-
date DoDate inherit DoInherit attribute NameAttr
)
else{} // must be either DoModule or DoObject or Both.
ErrMess = lastError() // Capture the Create error, if any
Instead of doing all cases with IF statements you can use the AttrDef__ Type to build your create string. Something like this does the trick:
AttrDef__ a = type sType date DoDates history DoHistory changeBars DoChangeBars attribute attributeName
if(bModule) a = module a else a = object a
if (!null sDefault) a = (default sDefault) a
create a
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: How to dynamically create an attribute definition using strings Mathias Mamsch - Thu Jun 17 12:32:48 EDT 2010
Instead of doing all cases with IF statements you can use the AttrDef__ Type to build your create string. Something like this does the trick:
AttrDef__ a = type sType date DoDates history DoHistory changeBars DoChangeBars attribute attributeName
if(bModule) a = module a else a = object a
if (!null sDefault) a = (default sDefault) a
create a
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
@Louie ... I'm relatively new to DXL, but I understand where you're coming from ... unfortunately, this was my first attempt at coding this up ... refactoring was definitely going to be necessary anyway ... just trying to wrap my head around this language - thank you for your input as well! Best regards to all that helped me, m. |
Re: How to dynamically create an attribute definition using strings meherts - Thu Jun 17 14:33:25 EDT 2010 I tried the setDef function, but the attribute doesn't actually exist within the module ... so how can I give myself permissions to create? |
Re: How to dynamically create an attribute definition using strings meherts - Thu Jun 17 16:14:59 EDT 2010 Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS |
Re: How to dynamically create an attribute definition using strings Mathias Mamsch - Thu Jun 17 18:44:23 EDT 2010 Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
This is going to sound silly, but here is what I was missing ...: //Open module for editing m = edit(fullName(m), true)
|