I urgently need to write one macro :
The macro should not let user save the model if anything is changed in it (except creating one type of object). This means : the user (e.g "BANKUSER") should create only one object (e.g. SymbolNumb=999999) on EPC model and mustn't change anything else (attributes of objects or model, delete objects, placement of occurences and etc.) If he changes other things the shouldn't be saved.
I am new to macros , can you help me with the task ?
Thanks.
Hi Misha,
for example - I disable model attributes.
So, create macro with event "Model attribute is to be changed by modeling (vetoable)". Use this code:
var m = Context.getSelectedModels(); if (Context.getLoginInfo(m[0]).getUserName() == "BANKUSER"){ Context.setProperty("event.veto", "1") }
Open model attributes and try to change any - are disabled. So try other events, but in event name must be "(vetoable)".
Hi Misha,
I write you example, where I can create only event. You should select macro event "Object occurence created". There isn't vetoable event for creating occurence, so we have to delete occurence.
var oObjOccs = Context.getSelectedObjOccs(); if (Context.getLoginInfo(oObjOccs[0]).getDatabaseName() == "TEST" && Context.getLoginInfo(oObjOccs[0]).getUserName() == "BANKUSER"){ if (oObjOccs[0].getSymbolNum() != Constants.ST_EV){ Designer.deleteOcc(Designer.getModel(oObjOccs[0]), oObjOccs[0]); } }
The only problem in this great solution is that it slows down modeling. Our designers wait for the macro (1 sec.) to run before or after editing each attribute, creating new object , moving objects etc. And all this because of blocking one user :D They are angry :)))
Can you write in more details ? If I create a new filter, with one object, the user will not be able to see whole model.... and wich macro should I use ?
thanks
Hi Mischa,
Didn't see your post until now. It's a common issue that running a macro takes a while and impacts the modelers work. That's why I usually only execute the macro on save (vetoable) or user triggered. One question I have about the limiting a user to model certain objects on the model. Do you mean in this case that the user is not allowed to place the occurrence at all (so also no reuse of existing) or is it not allowed to create new object definitions, but allowed to reuse existing.
In the first situation, working on the same model is no option. I would suggest to have separate models for the different purposes. If you have a derived modeltype you can limit the symbols to be used for the specific models. Using a report you can then generate a view containing the information of both other views (this however results in high school scripting knowledge).
If the second situation is the case, you can run a report checking on the creator of the objects with a signaling function.
Unfortunately I can't give you another option.
Best regards,
Edwin
Thanks for reply !
In my case I have situation, where user should create only one type of Object-Risk Object (create definition or reuse it as occurence) and shouldn't create definitions/occurences , delete , replace, or do anything else with other types of object or connections.
Now I use one macro , that checks username while deleting object. It doesn't slow down designers' working process