MetaCase Homepage
Forum Home Forum Home > > MetaEdit+
  New Posts New Posts RSS Feed - Using UUID or GUID in the Generator
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Using UUID or GUID in the Generator

 Post Reply Post Reply
Author
Message
Liroth View Drop Down
Member
Member


Joined: 05.Jul.2013
Location: Kiel
Points: 5
Post Options Post Options   Thanks (0) Thanks(0)   Quote Liroth Quote  Post ReplyReply Direct Link To This Post Topic: Using UUID or GUID in the Generator
    Posted: 05.Jul.2013 at 14:16
Hello,

is it possible to generate a UUID or GUID with the MetaEdit generator?
If not cold I use the "external executeBlocking" command to call a function which returns me one?
In the Workbench User's Guide it's not mentioned if the generator gets the output from the external call or not.

Thanks for any help
Liroth
Back to Top
stevek View Drop Down
MetaCase
MetaCase
Avatar

Joined: 11.Mar.2008
Points: 643
Post Options Post Options   Thanks (1) Thanks(1)   Quote stevek Quote  Post ReplyReply Direct Link To This Post Posted: 05.Jul.2013 at 14:48

You can use external...executeBlocking to call a command that sends its results to a text file, and then read that into a variable.

external 'uuid >uuid.txt' externalBlocking
variable 'uuid' write
   filename 'uuid.txt' read
close
 
If the command also writes a line break to the file, you'll need to strip that off (e.g. do $uuid where id {$uuid = id}).
 
If you need multiple UUIDs, I'd suggest you use just one executeBlocking for better performance, outputting multiple UUIDs to the file:
 
external 'uuid -n 100 >uuids.txt' externalBlocking
variable 'uuids' write
   filename 'uuids.txt' read
close
do $uuids where id
{   /* use id in the block to give you the next uuid */
}
 
You could also grab the next UUID into $uuid like this:
 
variable 'uuids' write
   $uuid = ''
   do $uuids
   {  if $uuid then id else $uuid = id endif
   }
close


Edited by stevek - 05.Jul.2013 at 14:50
Back to Top
Liroth View Drop Down
Member
Member


Joined: 05.Jul.2013
Location: Kiel
Points: 5
Post Options Post Options   Thanks (0) Thanks(0)   Quote Liroth Quote  Post ReplyReply Direct Link To This Post Posted: 25.Jul.2013 at 12:44
Hello,

thanks for your help. In order to use the external uuid command I had to install the Windows SDK, now it works fine.

Now I have another question. My model has two Objects: Components and Channels. They might be connected somehow. In the outputfile the connection has to be discribed via these uuids. At first there is a list of all channels with their generated uuids. In a later section the component connections are listed. These connections refere to the channels with the uuid. In order to do that I need some kind of array variable/map to group the channelnames from the model with their coresponding generated uuids to call them later.
Another way would be to add a parameter to the channelobject with the uuid, which the user doesn't see but the generator writes into.
So:
Is it possible to make an array or map in MERL?
or is it possible to write into objectproperties with MERL?
or is there another approach?

If nothing works I could make an external call for that too, but I'd like to keep as much as possible within MetaEdit+.
Back to Top
stevek View Drop Down
MetaCase
MetaCase
Avatar

Joined: 11.Mar.2008
Points: 643
Post Options Post Options   Thanks (0) Thanks(0)   Quote stevek Quote  Post ReplyReply Direct Link To This Post Posted: 25.Jul.2013 at 13:58

Absolutely! MERL has associative variables, so they can be used as a map.

While writing out your Channel list, you grab the uuid and store it in a variable named after the Channel. If you have channels called A and B, the code below will store their UUIDs in $channelUuidA and $channelUuidB.

foreach .Channel
{  _nextUuid() /* sets $uuid, define as in 2nd block above */
   'this.addChannel(' id ');' newline /* or however you write your list */
   variable
      'channelUuid' id /* the name of the variable, cf. key of map */
   write
      $uuid /* the value of the variable, cf. value of map */
   close
}

You can then later grab the UUIDs when you need them in a similar way, with variable...read. E.g. iterating over the Cartesian product of Components and Channels and writing out a connection for each:

foreach .Component
do .Channel
   {  'this.addConnection(' id;1 ', '
      variable 'channelUuid' id read
      ');' newline
   }
}

id;1 is the id of the object one level further out in the loop nesting (or further back on the stack), i.e. the Component here.

You might want to build your variable names based on the oid rather than id, if the channel names aren't sufficiently unique. And of course if you prefer arrays, that's possible too: just build the variable names with numbers instead (there are earlier posts on arrays in generators and using arrays in sub-generators). There is no particular format or syntax to the variable names, and no restriction on what characters can be used when building names like this with variable/local...write/read.

Back to Top
Liroth View Drop Down
Member
Member


Joined: 05.Jul.2013
Location: Kiel
Points: 5
Post Options Post Options   Thanks (0) Thanks(0)   Quote Liroth Quote  Post ReplyReply Direct Link To This Post Posted: 27.Jul.2013 at 15:08
Thank you, this helped a lot!
Back to Top
janne View Drop Down
MetaCase
MetaCase
Avatar

Joined: 25.Mar.2008
Points: 58
Post Options Post Options   Thanks (0) Thanks(0)   Quote janne Quote  Post ReplyReply Direct Link To This Post Posted: 30.Jul.2013 at 11:32
Hi,

Just my "two cents": is the UUID style of unique identifier needed for some certain reason or would the object identifier (inside the same repository) satisfy your needs?

MetaEdit+ can generate the unique and permanent identifier by using the "oid" command in MERL (http://www.metacase.com/support/50/manuals/mwb/Mw-5_5_8.html#Heading1283). With the MERL oid generation you could avoid the "external" calls and generation overall might be faster and generation script(s) simpler to create and debug?
Back to Top
Liroth View Drop Down
Member
Member


Joined: 05.Jul.2013
Location: Kiel
Points: 5
Post Options Post Options   Thanks (0) Thanks(0)   Quote Liroth Quote  Post ReplyReply Direct Link To This Post Posted: 31.Jul.2013 at 14:03
Thanks for the idea!
In my case I need these UUIDs in the outputfile because the next software uses these. I am aware of the oid command und I use it to make variables with the oid in the name and the UUID as value because the objectnames aren't unique.


Edited by Liroth - 31.Jul.2013 at 14:04
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.05
Copyright ©2001-2022 Web Wiz Ltd.

This page was generated in 0.046 seconds.