VSTA API Event ProjectObjectChanged
Thomas J
✭
in RobotStudio
I have been expereiencing the following problem with ProjectObjectChanged event:
1: ProjectObjectChanged event is fired for everything in the station.
if you declare the following
MyPart.ProjectObjectChanged += new ProjectObjectChangedEventHandler(MyPart_ProjectObjectChanged);
MyPart.ProjectObjectChanged += new ProjectObjectChangedEventHandler(MyPart_ProjectObjectChanged);
But the event behavior is for every GraphicComponent in teh station, including soem things that are not even named...
Should'nt the behavior of the event only fire for the part (or graphiccomponent) that is was subscribed to , like MyPart only, instead of all of the gc's present in the station?
So I try the VistaBridge, result is the same behavior:
VSTABridge vb = new VSTABridge();
vb.ProjectObjectChanged += new ProjectObjectChangedEventHandler vb_ProjectObjectChanged);
2: Unload/Load or Reload the addin, then the following error occurs:
RobotStudio .NET exception: Unknown Error: ProjectObjectChanged [a kaBillion of them]
============================================
Base exception: AppDomainUnloadedException
The target application domain has been unloaded.
============================================
Base exception: AppDomainUnloadedException
The target application domain has been unloaded.
Server stack trace:
at System.Threading.Thread.InternalCrossContextCallback(Context ctx, IntPtr ctxID, Int32 appDomainID, InternalCrossContextDelegate ftnToCall, Object[] args)
at System.Runtime.Remoting.Channels.CrossAppDomainSink.DoTransitionDispatch(Byte[] reqStmBuff, SmuggledMethodCallMessage smuggledMcm, SmuggledMethodReturnMessage& smuggledMrm)
at System.Runtime.Remoting.Channels.CrossAppDomainSink.SyncProcessMessage(IMessage reqMsg)
at System.Threading.Thread.InternalCrossContextCallback(Context ctx, IntPtr ctxID, Int32 appDomainID, InternalCrossContextDelegate ftnToCall, Object[] args)
at System.Runtime.Remoting.Channels.CrossAppDomainSink.DoTransitionDispatch(Byte[] reqStmBuff, SmuggledMethodCallMessage smuggledMcm, SmuggledMethodReturnMessage& smuggledMrm)
at System.Runtime.Remoting.Channels.CrossAppDomainSink.SyncProcessMessage(IMessage reqMsg)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at System.AddIn.Contract.Automation.IRemoteDelegateContract.InvokeDelegate(IRemoteArgumentArrayContract args)
at Microsoft.VisualStudio.Tools.Applications.ExceptionFilterHelper.DynamicInvoke(IExceptionManagerContract mgr, IExceptionNotificationObjectContract exceptionNotificationObjectContract, IRemoteDelegateContract delegateContract, IRemoteArgumentArrayContract remoteArgs)
at Microsoft.VisualStudio.Tools.Applications.DelegateProxy.InvokeDelegate_VV_Return[R,A0,A1](A0 a0, A1 a1)
at Microsoft.VisualStudio.Tools.Applications.DelegateProxy.InvokeDelegate_VV_NoReturn[A0,A1](A0 a0, A1 a1)
at ABB.Robotics.RobotStudio.Stations.VSTABridge.raise_ProjectObjectChanged(Object value0, ProjectObjectChangedEventArgs value1)
at ABB.Robotics.RobotStudio.Stations.VSTABridge.ProjectObject_ProjectObjectChanged(Object sender, ProjectObjectChangedEventArgs e)
at ABB.Robotics.RobotStudio.ProjectObjectChangedEventHandler.Invoke(Object sender, ProjectObjectChangedEventArgs e)
at ABB.Robotics.RobotStudio.ProjectObject.raise_ProjectObjectChanged(Object value0, ProjectObjectChangedEventArgs value1)
at ABB.Robotics.RobotStudio.ProjectObject.SendPendingChangeEvents()
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at System.AddIn.Contract.Automation.IRemoteDelegateContract.InvokeDelegate(IRemoteArgumentArrayContract args)
at Microsoft.VisualStudio.Tools.Applications.ExceptionFilterHelper.DynamicInvoke(IExceptionManagerContract mgr, IExceptionNotificationObjectContract exceptionNotificationObjectContract, IRemoteDelegateContract delegateContract, IRemoteArgumentArrayContract remoteArgs)
at Microsoft.VisualStudio.Tools.Applications.DelegateProxy.InvokeDelegate_VV_Return[R,A0,A1](A0 a0, A1 a1)
at Microsoft.VisualStudio.Tools.Applications.DelegateProxy.InvokeDelegate_VV_NoReturn[A0,A1](A0 a0, A1 a1)
at ABB.Robotics.RobotStudio.Stations.VSTABridge.raise_ProjectObjectChanged(Object value0, ProjectObjectChangedEventArgs value1)
at ABB.Robotics.RobotStudio.Stations.VSTABridge.ProjectObject_ProjectObjectChanged(Object sender, ProjectObjectChangedEventArgs e)
at ABB.Robotics.RobotStudio.ProjectObjectChangedEventHandler.Invoke(Object sender, ProjectObjectChangedEventArgs e)
at ABB.Robotics.RobotStudio.ProjectObject.raise_ProjectObjectChanged(Object value0, ProjectObjectChangedEventArgs value1)
at ABB.Robotics.RobotStudio.ProjectObject.SendPendingChangeEvents()
You have to completely shutdown RS, and re-open - you can only have then the one load attempt - if you eedit the code, it gets reloaded with the new buiild, and the event no longer works... to test your change, shutdown RS5 then restart - this gets real time consuming and irritating!
I unsubscribe the event in the AddInShutdown procedure.
How do you/What is the fix for the problem?
Thomas H. Johnston
PACs Application Engineer
PACs Application Engineer
0
Comments
-
Hi Thomas,
ProjectObjectChanged is a static event, so the behavior is by design.
In Visual Studio your first code wouldn't even compile, but VSTA isn't good at understanding static members - hence the confusion (and the need for VSTABridge).
Your second problem I can't reproduce. Make sure to use the same VSTABridge object when you unsubscribe, e.g.
[code] VSTABridge vb;
// This method is called when the addin is loaded into RobotStudio.
public void AddInStartup()
{
// TODO: Add startup code here. Create toolbars, etc.
vb = new VSTABridge();
vb.ProjectObjectChanged += new ProjectObjectChangedEventHandler(vb_ProjectObjectChanged);
}
// This method is called when the addin is unloaded from RobotStudio.
public void AddInShutdown()
{
// TODO: Add cleanup code here. Remove toolbars, etc.
vb.ProjectObjectChanged -= new ProjectObjectChangedEventHandler(vb_ProjectObjectChanged);
vb = null;
}
void vb_ProjectObjectChanged(object sender, ProjectObjectChangedEventArgs e)
{
Logger.AddMessage(new LogMessage("ProjectObjectChanged: " + e.ChangedObject.ToString()));
}
[/code]
regards,
Johannes
Johannes Weiman
Software Engineer
ABB Robotics0 -
Thanks Johannes, your code example solved my problem.
I negelected to null globally defiend variables in the shutdown - all is fixewd now!
Thomas H. Johnston
PACs Application Engineer0 -
Hi Thomas,just a small addition to Johannes helpful post:If you are debugging your Macro and stop execution (by pressing the Debug/Stop Debugging button), the AddInShutdown() method will not be called.In that scenario you will have the same problem, that RobotStudio tries to call an event handler in an unloaded AppDomain.If you do this often you can create a Macro that calls your AddInShutdown() method, which you can invoke manually, before stopping.0
-
Excelent Tip!Thomas H. Johnston
PACs Application Engineer0
This discussion has been closed.
Categories
- All Categories
- 5.5K RobotStudio
- 396 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 249 ScreenMaker
- 2.7K Robot Controller
- 310 IRC5
- 59 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 786 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 5 Job listings