cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

API: GetObjectFromID doesn't work with _HexaIdAbs within HOPEX V1R2 ?

Occasional Contributor

API: GetObjectFromID doesn't work with _HexaIdAbs within HOPEX V1R2 ?

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?

Tags (4)
3 Replies
MEGA

Re: API: GetObjectFromID doesn't work with _HexaIdAbs within HOPEX V1R2 ?

Hello JPots

 

To test the existance of an object with API script, it is recommended to used the function Exists

See KB 00003703

Jerome
Occasional Contributor

Re: API: GetObjectFromID doesn't work with _HexaIdAbs within HOPEX V1R2 ?

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

 

  • We have added an contextual menu (metacommand) on the metaclass Diagram.
    metacommand.png
  • when this metacommand is run, it calls a VB.net application and 1 of the commandlinearguments we use to call the VB.net application is the value of the '_HexaIdAbs' of the concerned diagram
    macro_01.PNG

    The function GetObjectFromId works on a the object aSysExtRef (type is a Sytem External Reference)

  • Within the VB.net application we call several macro where we use the value of '_HexaIdAbs' to find the diagram and to select objects that are connected to that diagram using the function GetObjectFromID.

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).

error.png

 

kind regards,

 

Jeroen.

Highlighted
Occasional Contributor

Re: API: GetObjectFromID doesn't work with _HexaIdAbs within HOPEX V1R2 ?

***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.