How can I set value for the property ?
Printed From: MetaCase
Category:
Forum Name: MetaEdit+
Forum Description: All topics relating to MetaEdit+ or DSM
URL: https://www.metacase.com/forums/forum_posts.asp?TID=702
Printed Date: 27.Mar.2026 at 02:17 Software Version: Web Wiz Forums 12.05 - http://www.webwizforums.com
Topic: How can I set value for the property ?
Posted By: Jiarui
Subject: How can I set value for the property ?
Date Posted: 20.May.2013 at 06:14
|
Hello, I have studied MetaEdit+ for months, and I like it very much! I want to know that can I set value for the property of the object or role in the generator? If can, how? Thank you very much!
|
Replies:
Posted By: stevek
Date Posted: 20.May.2013 at 11:43
|
Hi Jiarui,
Glad you like MetaEdit+! The generators are intended for read-only access to the models, so there aren't commands to set properties, add objects to a graph, etc. Instead you can use the http://www.metacase.com/support/50/manuals/mwb/Mw-8.html" rel="nofollow - API , which gives you full create, read, update and delete access to models and their representations. You can either have your API program running all the time with its own UI, from which you run the operations on MetaEdit+, or then invoke your API program with " http://www.metacase.com/support/50/manuals/mwb/Mw-5_7_7.html#Heading1582" rel="nofollow - external...execute " from a MetaEdit+ generator.
Since it sounds like you want to set a property value based on information already available elsewhere in the model, there may also be an alternative strategy. Since that property doesn't add any information that can't already be calculated from elsewhere, you may not need it: remember http://en.wikipedia.org/wiki/Dont_repeat_yourself" rel="nofollow - DRY . If it's something you want to be visible in the diagrams, then rather than storing a calculated value, you can simply calculate the value as needed when displaying. You can do this in a text element in a symbol, setting its source to a generator. Top-most on the generator stack is the object, and below that is the graph, so you can access not only the properties of this object, but also navigate in the graph - and with "do graphs", also to any other graph.
|
Posted By: sinnom
Date Posted: 24.May.2013 at 15:51
Hello, I have a similar issue where I want to use an id generator to derive the id of a graph which is used as a property in an object from the name of this object and the graph containg the element. However, employing the "do graphs" command fails with "*Error* Generator took too long..." even in the simplest use cases ("do graphs { type ' ' }"). Are there restrictions concerning these kinds of loops in id generators?
|
Posted By: stevek
Date Posted: 24.May.2013 at 17:01
Hi sinnom,
You've unknowingly made an infinite recursion: your graph is trying to find its name, which is calling its id generator, which is executing "do graphs", which tries to sort the graphs by type then name, which asks the name of your graph...
You could change the sorting of do graphs to something explicit that doesn't ask its id, e.g. "do graphs orderby type". You might also want to avoid searching unnecessary graphs by restricting on type, "do graphs where type='MyGraphType' orderby type". [Edit: these don't help in 5.0, since "graphs" is already sorted, and only then are its results passed to "do...where...orderby"]
However, I think you ought to consider giving the graph a name. Think of it like a function: your top-level object is a call to a function, and the definition of the function is the graph. I'd say that the definition is primary. If the top-level objects should always have a subgraph, you can make their id generator show the name of that graph. If not, you can use property sharing to make the name of the subgraph be the same as the name of the top-level object. Or you can let the top-level object have an independent name: e.g. you could have a graph "Alarm", which is the subgraph of two top-level objects "Alarm1" and "Alarm2".
|
Posted By: cwb38
Date Posted: 29.May.2013 at 16:08
Hi stevek,
your suggestion using the custom sorting on types for the "do graphs" loop does not seem to work: The same error message is displayed after a brief period of time - even when the type is limited via "where type = 'X'".
Incidentally, how would one create a shared property in MetaEdit+?
|
Posted By: stevek
Date Posted: 29.May.2013 at 23:38
|
Perhaps you have something inside the loop body that's causing the infinite recursion, e.g. id? If the loop body is completely empty, do you still get the timeout message?
To create a shared property, open the pop-up menu in its field in the property dialog and choose Share Property. It will offer you a list of all instances of that property type, showing how many times each is already reused. For more detail you can go to http://www.metacase.com/support/50/manuals/" rel="nofollow - www.metacase.com/support/50/manuals/ and search for Share Property - the first two hits should tell you everything you need to know.
|
Posted By: epc
Date Posted: 31.May.2013 at 13:08
Thank you for your support!
Unfortunately even a basic generator code like "do graphs where type='Composition' orderby type { 'executing generator' }" causes an infinite loop. Furthermore, I am unable to find the "Share Property" option in MetaEdit+ - does "Open a property dialog for an object" refer to opening an object in the object tool and accessing its properties list?
A problem concerning this forum: It seems like that after doing one post, the second time the error message "You do not have permission to reply to posts in this forum" pops up, so I am the third member of our team that has to create an account to reply to your answers.
|
Posted By: stevek
Date Posted: 31.May.2013 at 13:12
Correction: adding "where" or "orderby" to "do graphs" in a graph type's identifier generator won't help avoid infinite recursion, since "graphs" is already sorted by id, and only then are its results passed to "do...where...orderby" for possible further filtering and sorting. You should also note that in the event of two elements comparing the same on all orderby clauses, the default MetaEdit+ sorting (type, id, oid) will be used as a tiebreaker, to guarantee consistent ordering in generator output.
We'll see if we can work some magic in a future version so that "graphs" notices it's being called by a "do...orderby", and avoids doing its own default sorting. But in any case, using "do graphs" in an identifier generator is never going to be best practice - MERL may be fast, but nothing can save you from an algorithmic complexity of O((n^2)*(log n)). An identifier should be based on something the object itself knows, not having to ask every other graph in the system.
|
Posted By: stevek
Date Posted: 31.May.2013 at 13:33
epc wrote:
Furthermore, I am unable to find the "Share Property" option in MetaEdit+ - does "Open a property dialog for an object" refer to opening an object in the object tool and accessing its properties list? |
No, the property dialog is for instances. Please see my post above and its link to the manual for more detail.
epc wrote:
A problem concerning this forum: It seems like that after doing one post, the second time the error message "You do not have permission to reply to posts in this forum" pops up, so I am the third member of our team that has to create an account to reply to your answers. | Sorry, that was human error by our moderators. I've corrected it, emailed those affected, and reminded our moderators of the correct process.
|
Posted By: Jiarui
Date Posted: 05.Jun.2013 at 05:18
Thank you very much for your answer. I have a question about the generator: the idea of the generator is to navigate and extract information from models, and I want to know that when navigating, wo often use foreach.() coupled with ~From~To etc, I want to navigate according to a rule, foe example, Depth-first traverse, so I need to have a flag which can control if the element is visited, if visited, the flag is true, else is false, now I cannot set vaule to the flag in the generator, and I want to know is there any other way todo so ? Yhank you very much!
|
Posted By: janne
Date Posted: 05.Jun.2013 at 08:37
How about the following: collect all the visited elements to one variable (reported_elements) and test before reporting has this element been reported earlier. Similar structure can be found from Metrics generator (Generator editor | Ghange Graph Type... | Graph)
First call '_translators' subreport (wildsp translator needed later in comparison) and initialize a variable ($reported_elements) having all the visited elements:
subreport '_translators' run $reported_elements = ' '
Then inside the foreach loop, check has the current object oid been reported earlier, if not --> go ahead and add the current oid first to the variable and a space. Wildcard comparison (=~) searches space-separated values from the $reported_elements.
if not $reported_elements =~ oid%wildsp then variable 'reported_elements' append oid ' ' close /* Here comes the part for elements which have not been reported earlier */ endif
|
|