‎08-07-2015 01:59 PM
We've written several macros in our MEGA 2009 environment. Now that we are looking forward to migrate towards HOPEX a lot of those macros don't work anymore. We use the function GetObjectFromID in combination with the _HexaIdAbs.
The result of the query aObject = myRoot.GetObjectFromID(IdObject) is empty, but the value of idObject is a valid _HexaIdAbs of a diagram.
Should I adapt all of my macros so I use the 'Absolute Identifier' instead of the '_HexaIdAbs' or is there a way around?
‎09-07-2015 02:56 PM
***UPDATE*** ***UPDATE*** ***UPDATE***
The problem seems not to be with the function GetObjectFromIDn but with the MegaObjectType Diagram when the macro is called from within the VB.NET project:
For testing purposes I've written a simple macro that makes collections of 2 types of MegaObjectTypes, macros and diagrams:
myRoot = GetRoot
oObjects = myRoot.Getcollection("Macro")
msgbox oObjects.Count & " Macros"
oObjects = myRoot.Getcollection("Diagram")
msgbox oObjects.Count & " diagrams"
When I launch the macro from within MEGA I get the correct result for macros (6474) AND diagrams (.
When I call the macro from VB.NET I get the correct result for macros (6474), but I get no diagrams.
If go further and try to count other object, I try queries (2 times succesfull), next I try Database (only lucky within MEGA, and not via VB.NET)
It seems that the currentenvironment is not properly loaded when I perform my GetRoot in the called macro. All objects that are shared in different repositories (query, macro, ...) can be selected, all objects that belong to the currentrepository can not be selected...
I'm calling my macro from VB.NET using the following code (written by an external consultant of MEGA who helped us with our migration from MEGA 6.1 towards MEGA 2009)
oMacro = MyRoot.GetSelection("Select [Macro] where [_hexaidabs] =" + DQ + sIdMacro + DQ) If oMacro.Count = 1 Then aMacro = oMacro(1) pMacro = MyRoot.CurrentEnvironment.GetMacro(aMacro.GetProp("name")) end if oResult = pMacro.GetType().InvokeMember(sMacroFunction, BindingFlags.InvokeMethod, defaultBinder, pMacro, Nothing)
Where sMacroFunction is the function within the macro that serves as starting point.
‎08-07-2015 02:45 PM
Jérome,
this is not an answer to my question. I know the object exists !
But I now have to specify that this problem, until now, only occurred when I wanted to select a Diagram using GetObjectFromID, other MegaObjects can be selected
In MEGA 2009 the diagram was found without any problem and I could perform any kind of task on it without any problem, getProp, GetSelection, GetCollection,...
Within HOPEX V1R2 I get an error message when I want to extract a property of the object using GetProp (first attempt of accessing the object). (See image below).
kind regards,
Jeroen.
‎08-07-2015 02:04 PM
Hello JPots
To test the existance of an object with API script, it is recommended to used the function Exists
See KB 00003703