Welcome to Telelogic Product Support
  Home Downloads Knowledgebase Case Tracking Licensing Help Telelogic Passport
Telelogic DOORS (steve huntington)
Decrease font size
Increase font size
Topic Title: Unique Numbering for specific objects
Topic Summary: Need help w/script
Created On: 10-Apr-2007 19:21
Status: Post and Reply
Linear : Threading : Single : Branch
1 2 Next Last unread
Search Topic Search Topic
Topic Tools Topic Tools
Quick Reply Quick Reply
Subscribe to this topic Subscribe to this topic
E-mail this topic to someone. E-mail this topic
Bookmark this topic Bookmark this topic
View similar topics View similar topics
View topic in raw text format. Print this topic.
Answer This question was answered by Deliah Terry, on Wednesday, April 18, 2007 6:39 PM

Answer:
I suppose I'll have to get with my team and take another look at this. I appreciate everyone's input and help.
 10-Apr-2007 19:21
User is offline View Users Profile Print this message


Deliah Terry

Posts: 10
Joined: 13-Sep-2006

I'm new to DOORS, but have experience with C/C++. I need to create a script that will assign a unique identifier to ONLY objects with a specific word in the text. Any suggestions?? Thank you!
Report this to a Moderator Report this to a Moderator
 10-Apr-2007 20:14
User is offline View Users Profile Print this message


David Pechacek

Posts: 674
Joined: 5-Dec-2006

1) Create attribute to store unique identifier in.
2) scan module objects searching for word.
3) set created attribute to unique value you've created with an integer at the end.
4) increment integer.

Alternatively you could write a DXL column that does this and but instead of setting an attribute contains a word(or words) to signify what having your desired word in the object text means (like its a requirement for example).

P.S. - Does anyone know why line breaks aren't being captured in posts? It just puts the whole post on the same line and is quite annoying.

-------------------------
David Pechacek
AAI Services Textron
dpechacek@sc-aaicorp.com
David.Pechacek@gmail.com

Edited: 11-Apr-2007 at 14:07 by David Pechacek
Report this to a Moderator Report this to a Moderator
 10-Apr-2007 23:31
User is offline View Users Profile Print this message


Deliah Terry

Posts: 10
Joined: 13-Sep-2006

Thank you so much for such a quick reply! This is exactly what I'm trying to do. I tried what you've suggested but it's not quite working. I'm going to keep working with it and greatly appreciate the help getting started.
Report this to a Moderator Report this to a Moderator
 11-Apr-2007 03:45
User is offline View Users Profile Print this message


Louie Landale

Posts: 2070
Joined: 12-Sep-2002

I didn't read David's reply but believe that approach is different than this one:

Lets say you want the identifier to read "MyWord_nnn" where nnn is the next integer.

Create the attribute 'MyWord' to house the ID, make sure attribute is defined for objects and the module. Write a script that does the following: Reads the module level value of the attribute, strip off the prefix "MyWord_" and converts the rest to an integer; if its null presume zero. Read each object in the module, skipping deleted objects. If the object doesn't contain TheWord but has a MyWord value, then delete the value (and see below). If it has TheWord and MyWord then its OK. If it has TheWord but no MyWord, then increment the last known count, assigne the prefix and that value to the object, perhaps MyWord_23. At the end of the script set the Module level value to the last known value, in this case MyWord_23.

Now you've got a problem with objects that contain TheWord and are given a MyWord value, perhaps MyWord_23. Next time of TheWord has been removed it will remove MyWord, but if you reinstert TheWord that object will get a new MyWord, which is probably what you do NOT want. If so, instead of erasing MyWord when the object no longer contains TheWord, I'd be tempted to "XX" the value out, to perhaps "xxMyWord_23"; which can then be reinstated if TheWord is reinsterted into that object.

Another issue is that you MAY want to insist that MyWord be sortable chronologically, in which case you'd have to insiste that "nnn" have enough digits to cover the life of MyWord. If you figure more than a 1000 objects will get values then 'nnn' would need to be 4 digits, and the first one would be "MyWord_0001" and the second "MyWord_0002" etc. Guessing the digits can be tricky, in which case go with 5. You can use functions to convert integers to strings with certain number of digits (suffix padded with zeros), but you can also cheat by simply setting the module value originally to some big number like "MyWord_10000".

- Louie
Report this to a Moderator Report this to a Moderator
 11-Apr-2007 16:46
User is offline View Users Profile Print this message


Deliah Terry

Posts: 10
Joined: 13-Sep-2006

I did try David's approach and I did get the assigned numbers, but on the wrong levels. Pretty much, what I need to do is find each object that contains "shall" and assign it a unique identifier that is different than the Object ID. I want to have my actual requirements numbered sequentially. The script I have now is assigning numbers to the headings.
Report this to a Moderator Report this to a Moderator
 11-Apr-2007 17:17
User is offline View Users Profile Print this message


David Pechacek

Posts: 674
Joined: 5-Dec-2006

That should assign the number to each object where the object text contains shall. Headings should not have any object text. And when you're assigning the unique identifier to the object, the object being referenced should still be the object where the object text contained "shall". So I don't see how my code could be assigning the unique identifier to a heading object above the object containing the requirement.

Copy and paste in a reply your code so I can see it. You aren't putting this code in a layout dxl column or an dxl attribute are you?

Edit: I did have a break in there that shouldn't be there but that wouldn't have caused the unique identifier to be put in a different object than where the "shall" was found.

-------------------------
David Pechacek
AAI Services Textron
dpechacek@sc-aaicorp.com
David.Pechacek@gmail.com

Edited: 11-Apr-2007 at 17:28 by David Pechacek
Report this to a Moderator Report this to a Moderator
 11-Apr-2007 17:55
User is offline View Users Profile Print this message


Deliah Terry

Posts: 10
Joined: 13-Sep-2006

Here's what I ran yesterday. I tried modifying it and rerunning and now I'm getting an incorrect regular expression error.
Report this to a Moderator Report this to a Moderator
 11-Apr-2007 19:45
User is offline View Users Profile Print this message


David Pechacek

Posts: 674
Joined: 5-Dec-2006

Try changing your if statement to:

if(!null(stringOf(objText)) && matches(stringOf(objText), findWord)) {

This should let it skip your headers (where object text should be blank) and anywhere else object text is blank. I also got an error where it was assigning a unique ID to objects where the object text was blank. Odd. Is that what you were referring to? That it was assigning IDs to requirements but also headers or just the header instead of the requirement?

Where are you getting the regular expression error?

-------------------------
David Pechacek
AAI Services Textron
dpechacek@sc-aaicorp.com
David.Pechacek@gmail.com

Edited: 11-Apr-2007 at 19:49 by David Pechacek
Report this to a Moderator Report this to a Moderator
 11-Apr-2007 19:49
User is offline View Users Profile Print this message


Deliah Terry

Posts: 10
Joined: 13-Sep-2006

It's giving me that on line 9. Not sure why...
Report this to a Moderator Report this to a Moderator
 11-Apr-2007 21:27
User is offline View Users Profile Print this message


David Pechacek

Posts: 674
Joined: 5-Dec-2006

Is that the if statement or the assignment line underneath. You have a leading blank line so I'm not sure if you mean line 9 starting from the first line of code or line 9 starting from that blank line?

I copied and pasted the code you posted and it doesn't give any errors but puts the IDs in every column (and I have no object text. I change the if statement to mine and no errors and it doesn't put IDs in any column (as it should).

-------------------------
David Pechacek
AAI Services Textron
dpechacek@sc-aaicorp.com
David.Pechacek@gmail.com

Edited: 11-Apr-2007 at 21:31 by David Pechacek
Report this to a Moderator Report this to a Moderator
 12-Apr-2007 16:58
User is offline View Users Profile Print this message


Deliah Terry

Posts: 10
Joined: 13-Sep-2006

Did you use the null or matches function?
Report this to a Moderator Report this to a Moderator
 12-Apr-2007 17:01
User is offline View Users Profile Print this message


David Pechacek

Posts: 674
Joined: 5-Dec-2006

I used both. This was my if statement to get it to work properly.

if(!null(stringOf(objText)) && matches(stringOf(objText), findWord)) {

-------------------------
David Pechacek
AAI Services Textron
dpechacek@sc-aaicorp.com
David.Pechacek@gmail.com
Report this to a Moderator Report this to a Moderator
 12-Apr-2007 23:46
User is offline View Users Profile Print this message


Louie Landale

Posts: 2070
Joined: 12-Sep-2002

It seems odd to me that you can tolerate this new unique ID being changed for an object day-to-day. If the "shall be green" requirement has ID "BSDREQ_29" last week it seems very odd that you can handle it having ID "BSDREQ_30" this week, just because you added a requirement above it.

Also, you are not saving any space by staging the Object Text in a buffer, if you use stringOf(buf) later on. If you use stringOf(buf) twice (as in your later posting) then you are wasting string-table space. Just use string Text = o."Object Text" and use Text directly.

Very trivial comment: Also, you are wasting some time creating and deleting the buffer inside the loop. That doesn't matter for this loop, but in general there is considerable time spent creating and deleting buffers. I'd but the create buffer before the for loop and the delete after it.

- Louie
Report this to a Moderator Report this to a Moderator
 13-Apr-2007 14:45
User is offline View Users Profile Print this message


David Pechacek

Posts: 674
Joined: 5-Dec-2006

Yes I know. If you look at the original code I wrote at the top, I used tempStringOf. It was later changed to stringOf by Terry. For almost all of my own scripts, I use tempStringOf. I just left it the way Deliah posted it after it was changed.

As far as creating and deleting buffers, I know maybe you don't need to do it that way, but it doesn't appear to have any performance impact either way even when dealing with large numbers of objects. As you say, a trivial matter and one of preference. And one of being paranoid that the buffer will retain some information from a previous iteration.

-------------------------
David Pechacek
AAI Services Textron
dpechacek@sc-aaicorp.com
David.Pechacek@gmail.com
Report this to a Moderator Report this to a Moderator
 13-Apr-2007 19:00
User is offline View Users Profile Print this message


Louie Landale

Posts: 2070
Joined: 12-Sep-2002

You know, I never really thought if using 'tempStringOf' when the value is used in a boolean comparison operation. Yes, that sounds like it might work out very well...

Did some tests a few years ago and concluded Buffer create and deletes took quite a long while. I thus modified most of my library that uses Buffers, to move the local buffer and declare it 'globally' and create it there, leaving the function to simply erase it before using it. Did some tests just now in v8.1 and it looks like the create-delete doesn't take much time at all; specifically a million creates and deletes took around 2 seconds. Maybe I need to rethink that...

Attached is the test. Takes 22-24 seconds each run in v8.1, 13-15 seconds each for v7.1.

- Louie
Report this to a Moderator Report this to a Moderator
 16-Apr-2007 20:45
User is offline View Users Profile Print this message


Deliah Terry

Posts: 10
Joined: 13-Sep-2006

FYI - I've tried this again with the code below and I still get the following error: -R-E- DXL: incorrect regular expression (Badly placed parenthesis) -I- DXL: execution halted
Report this to a Moderator Report this to a Moderator
 16-Apr-2007 20:58
User is offline View Users Profile Print this message


ron lewis

Posts: 650
Joined: 20-Sep-2004

I suspect, the error is occuring because of your using Object Text in a matches expression.

Apparently you object text has some characters that the matches function interprets as regular expressions.

If this is the case the easiest solution is to eliminate the matches expression.

To do this --- create a filter for object that contains the shalls then run you number script.
Report this to a Moderator Report this to a Moderator
 17-Apr-2007 15:26
User is offline View Users Profile Print this message


Chris Annal

Posts: 36
Joined: 14-Dec-2005

I agree with Ron's comment. I usually create unique numbers for my shalls by using the following, from the DOORS DXL help files:

Filters on objects that include the string text in a specific attribute attributeName. If caseSensitive is set to true, the filter takes character case into account when searching. If caseSensitive is false, the filter ignores case. If caseSensitive is omitted, the filter accepts regular expressions.

Example

Module m = current 
Filter f = contains(attribute "Object Text", "shall", false) 
set f 
filtering on 




Once the module is filtered, you could run a script that counts the displayed
objects and uses a counter to increment a separate attribute. (This example assumes
you've created a module attribute named "Last_Used_Number" (set to zero) and also
have an attribute (Object level) named "Unique_Identifier":







//populate the attribute of the filtered objects
void setNumber ()
{
 //declare variables
 int iLastNum
 int iNewNum
 
 //get last used identifier
 iLastNum = mCurrentMod."Last_Used_Number"
 
 //for every object in the filtered list
 for oCurrentObject in mCurrentMod do
 {
  //increment the integer
  iLastNum ++
  
  //set the Unique_Identifier attribute for the current object to the integer
  oCurrentObject."Unique_Identifier" = iLastNum
 
 }//end for oCurrentObject in mCurrentMod
 
 mCurrentMod."Last_Used_Number" = iLastNum
}
setNumber





If you want to have an attribute that combines a prefix with this "Unique_Identifier",
you could create an attribute named "ReqNum", then use the following script to combine the
module prefix (You can edit this to be anything you want) and the existing value in the
"Unique_Identifier" attribute to populate "ReqNum". Something like this:




//initialize variables
Object oCurrObject
Module oCurrModule = current
string sModPrefix = oCurrModule."Prefix"
int iCurrObjNum = null
//loop through every object in the module
for oCurrObject in oCurrModule do
{
//get the Unique Identifier of the object
iCurrObjNum = oCurrObject."Unique_Identifier"
//create a new attribute out of the module prefix and the above number
//cast the integer to a string...
oCurrObject."ReqNum" = sModPrefix iCurrObjNum ""
}
Report this to a Moderator Report this to a Moderator
 17-Apr-2007 15:31
User is offline View Users Profile Print this message


Chris Annal

Posts: 36
Joined: 14-Dec-2005

One typo I noticed in my script example"
mCurrentMod."Last_Used_Number" should simply be
m."Last_Used_Number" - since I already declare "m" to be the current module in my
first example.

Chris "Mavis Beacon Teaches Typing" Annal
Report this to a Moderator Report this to a Moderator
 17-Apr-2007 17:00
User is offline View Users Profile Print this message


Deliah Terry

Posts: 10
Joined: 13-Sep-2006

I really appreciate everyone's comments and suggestions. This is turning out to be much more complicated that I though it would be!
Report this to a Moderator Report this to a Moderator
Telelogic DOORS » DXL Exchange » Unique Numbering for specific objects

1 2 Next Last unread
Topic Tools Topic Tools
Statistics
20925 users are registered to the Telelogic DOORS forum.
There are currently 2 users logged in.
The most users ever online was 15 on 15-Jan-2009 at 16:36.
There are currently 0 guests browsing this forum, which makes a total of 2 users using this forum.
You have posted 0 messages to this forum. 0 overall.

FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.