Skip to content

Commit

Permalink
Add project files.
Browse files Browse the repository at this point in the history
  • Loading branch information
JETomi committed Sep 15, 2023
1 parent 2d84408 commit 2941a67
Show file tree
Hide file tree
Showing 9 changed files with 525 additions and 0 deletions.
107 changes: 107 additions & 0 deletions Class1.cs
@@ -0,0 +1,107 @@
using ABB.Robotics.Controllers;
using ABB.Robotics.Controllers.RapidDomain;
using ABB.Robotics.Math;
using ABB.Robotics.RobotStudio;
using ABB.Robotics.RobotStudio.Controllers;
using ABB.Robotics.RobotStudio.Environment;
using ABB.Robotics.RobotStudio.Stations;
using System;
using System.Collections.Generic;
using System.Text;

namespace TwRobotstudioSyncTarget
{
public class Class1
{
// This is the entry point which will be called when the Add-in is loaded
public static void AddinMain()
{
// Add context menu button to target datatype
CommandBarContextPopup ctxPopup = UIEnvironment.GetContextMenu(typeof(RsTarget));
CommandBarControlCollection cbcc = ctxPopup.Controls;
// Create button object
CommandBarButton BtnSyncTarget = new CommandBarButton("TwRobotstudioSyncTarget.SyncTarget", "Sync without path");
BtnSyncTarget.DefaultEnabled = true;
BtnSyncTarget.Image = Properties.Resources.icon_16;
BtnSyncTarget.LargeImage = Properties.Resources.icon_32;
BtnSyncTarget.ExecuteCommand += BtnSyncTarget_ExecuteCommand;
//Add button to top.
cbcc.Insert(0,BtnSyncTarget);
//
}

private static void BtnSyncTarget_ExecuteCommand(object sender, ExecuteCommandEventArgs e)
{
// Get selected objects
ProjectSelection Selected = Selection.SelectedObjects;
//
foreach (var item in Selected)
{
//Check if selected object is a target
if (item is RsTarget target)
{
//Set target to synchronized
target.RobTarget.Synchronize = true;
//Module to store robtarget in. Default should automaticly be from settings in robotstudio.
if (target.RobTarget.ModuleName == "")
{
target.RobTarget.ModuleName = "Tw_TargetSync";
}
//Decleare storage type as constant
target.RobTarget.StorageType = RapidStorageType.Constant;
//Sync target to rapid.
SynchronizeToRapid(target.RobTarget, target.Parent as RsTask);
}
}
Logger.AddMessage("TwRobotstudioSyncTarget: Sync complete");
}

// Copied from documentation, adjusted for Target instead of Path.
// https://developercenter.robotstudio.com/api/robotstudio/articles/How-To/Rapid/SynchronizeToRapid.html
private static bool SynchronizeToRapid(RsRobTarget path, RsTask task)
{
bool result = false;
Project.UndoContext.BeginUndoStep("SynchronizeToRapid");
try
{
path.Synchronize = true;
//Get reference to instance of RsIrc5Controller
RsIrc5Controller rsIrc5Controller = (RsIrc5Controller)task.Parent;
//Get virtual controller instance from RsIrc5Controller instance
ABB.Robotics.Controllers.Controller controller =
new ABB.Robotics.Controllers.Controller(new Guid(rsIrc5Controller.SystemId.ToString()));

//Request for Mastership from controller
//If granted then call SyncPathProcedure instance method of RsTask
using (ABB.Robotics.Controllers.Mastership m =
ABB.Robotics.Controllers.Mastership.Request(controller.Rapid))
{
try
{
List<SyncLogMessage> messages = new List<SyncLogMessage>();
task.SyncData(path.ModuleName + "/" + path.Name,
SyncDirection.ToController,
messages);

}
catch (Exception ex)
{
Logger.AddMessage(new LogMessage(ex.Message.ToString()));
result = false;
}
}
}
catch (Exception ex)
{
Logger.AddMessage(new LogMessage(ex.Message.ToString()));
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
}
finally
{
Project.UndoContext.EndUndoStep();
}

return result;
}
}
}
36 changes: 36 additions & 0 deletions Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("TwRobotstudioSyncTarget")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TwRobotstudioSyncTarget")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("2b9b044e-e9aa-41e1-a2ea-0c7506c90da6")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
83 changes: 83 additions & 0 deletions Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

127 changes: 127 additions & 0 deletions Properties/Resources.resx
@@ -0,0 +1,127 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="icon_16" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon_16.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icon_32" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon_32.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>
Binary file added Resources/icon_16.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/icon_32.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2941a67

Please sign in to comment.