Ejemplo n.º 1
0
        public VirtualStation(string stationFile)
        {
            try
            {
                if (!RobotStudioAPI.Initialized)
                {
                    RobotStudioAPI.Initialize();
                }

                activeProject = Station.Load(stationFile, true);
                tStation      = activeProject as Station;

                rsTask = tStation.ActiveTask;
                robot  = rsTask.Mechanism;
                rsWobj = rsTask.ActiveWorkObject;

                tStation.Irc5Controllers[0].StartAsync(VirtualControllerRestartMode.IStart,
                                                       new List <Mechanism>(1)
                {
                    robot
                });
            }
            catch (Exception e)
            {
            }
        }
Ejemplo n.º 2
0
        static RsRobTarget CreateRobTargetAndTarget(Matrix4 frame, RsTask task, RsWorkObject wobj)
        {
            if (!_targetNumberInitialized)
            {
                InitializeTargetNumber(task);
            }
            var robTarget = new RsRobTarget();

            robTarget.Frame.GlobalMatrix = frame;
            robTarget.Name = TargetNamePrefix + _targetNumber++;
            // HACK: Ensure that eax values are set for conveyor. *Will* lead to issues with other
            // external axes.
            robTarget.SetExternalAxes(new ExternalAxisValues
            {
                Eax_a = 0,
                Eax_b = 0,
                Eax_c = 0,
                Eax_d = 0,
                Eax_e = 0,
                Eax_f = 0
            }, false);
            task.DataDeclarations.Add(robTarget);

            var target = new RsTarget(wobj, robTarget);

            target.Transform.GlobalMatrix = frame;

            task.Targets.Add(target);
            return(robTarget);
        }
Ejemplo n.º 3
0
        private void ShowDialog(object sender, CancelEventArgs e)
        {
            Logger.AddMessage(new LogMessage("Your import of file: " + openFileDialog1.FileName + " has started.", LogMessageSeverity.Information));


            Cursor.Current = Cursors.WaitCursor;
            Station station = Project.ActiveProject as Station;

            string fileExtension = System.IO.Path.GetExtension(openFileDialog1.FileName);
            string Path          = openFileDialog1.InitialDirectory + openFileDialog1.FileName;
            string Name          = System.IO.Path.GetFileName(openFileDialog1.FileName);

            if (fileExtension == ".nc" | fileExtension == ".gcode" | fileExtension == ".cnc")
            {
                Zone       = comboBoxZone.SelectedItem.ToString();
                Speed      = comboBoxSpeed.SelectedItem.ToString();
                Resolution = comboBoxResolution.SelectedItem.ToString();
                RotXvar    = RotX.Text;
                RotYvar    = RotY.Text;
                RotZvar    = RotZ.Text;

                RsToolData   robotToolData = new RsToolData();
                RsWorkObject robotWorkObj  = new RsWorkObject();



                foreach (RsDataDeclaration rsd in station.ActiveTask.DataDeclarations)
                {
                    if (rsd is RsToolData)
                    {
                        if (rsd.Name == Tool)
                        {
                            robotToolData = rsd as RsToolData;
                        }
                    }
                    station.ActiveTask.ActiveTool = robotToolData;
                    if (rsd is RsWorkObject)
                    {
                        if (rsd.Name == WorkObj)
                        {
                            robotWorkObj = rsd as RsWorkObject;
                            station.ActiveTask.ActiveWorkObject = robotWorkObj;
                        }
                    }
                }

                Read read1 = new Read();
                read1.ReadGcode(Path, Name, Globals.positions, robotToolData, robotWorkObj, Speed, Zone, Resolution, RotXvar, RotYvar, RotZvar);
                // read1.CreatePath(Name, Globals.positions, robotToolData, robotWorkObj, Speed, Zone);
                // THen do the import
                Logger.AddMessage(new LogMessage("Enjoy your new auto generated targets and paths." + "\n" + "They are now ready!"));
            }

            else
            {
                Logger.AddMessage(new LogMessage("Ooops.. The file import failed due to file problems... Please check that the fileformat is correct and that the file isn't corrupted"));
                //Show message not correct file...
            }
        }
Ejemplo n.º 4
0
        private void CreateRsWorkobject(string wobjName = "myWobj")
        {
            try
            {
                #region RsWorkObjectPoint1
                // Create a RsWorkObject.
                RsWorkObject newWobj = new RsWorkObject();

                // Get a valid RAPID name for the workobject and assign it.
                newWobj.Name = rsTask.GetValidRapidName(wobjName, "_", 1);
                #endregion

                // Set the frame size to twice the default size.
                newWobj.FrameSize = newWobj.FrameSize * 2;

                // Set the userframe to be a fixed coordinate system.
                newWobj.UserFrameProgrammed = true;

                // Translate the user frame.
                newWobj.UserFrame.X = 0.5;
                newWobj.UserFrame.Y = 0.2;
                newWobj.UserFrame.Z = 0.2;

                #region RsWorkobjectPoint2
                // Translate the object frame.
                newWobj.ObjectFrame.X = 0.5;
                newWobj.ObjectFrame.Y = 0.5;
                newWobj.ObjectFrame.Z = 0.5;

                // Rotate the object frame (pi radians around each axis).
                newWobj.ObjectFrame.RX = Math.PI;
                newWobj.ObjectFrame.RY = Math.PI;
                newWobj.ObjectFrame.RZ = Math.PI;
                #endregion

                // Display the wobj in the graphics.
                newWobj.Visible = true;

                // Display the name of the wobj in the graphics.
                newWobj.ShowName = true;

                // The wobj is not held by the robot.
                newWobj.RobotHold = false;

                rsWobj = newWobj;
                #region RsWorkobjectPoint3
                // Add the wobj to the DataDeclarations of the ActiveTask.
                rsTask.DataDeclarations.Add(newWobj);

                // Set the wobj as the active workobject of the ActiveTask.
                rsTask.ActiveWorkObject =
                    (RsWorkObject)rsTask.FindDataDeclarationFromModuleScope(newWobj.Name, newWobj.ModuleName);
                #endregion
            }
            catch
            {
            }
        }
Ejemplo n.º 5
0
        public static void ObtainPosition()
        {
            #region Get the position of the selected object
            Project.UndoContext.BeginUndoStep("Get the position of the selected object");
            try
            {
                // Get the selected Part.
                #region SelectPart1
                Part selectedPart = Selection.SelectedObjects.SingleSelectedObject as Part;
                #endregion

                // Get the selected WorkObject.
                #region SelectWorkObject1
                RsWorkObject selectedWorkObject = Selection.SelectedObjects.SingleSelectedObject as RsWorkObject;
                #endregion

                // Get the selected RsTarget.
                #region SelectRsTarget1
                RsTarget selectedRsTarget = Selection.SelectedObjects.SingleSelectedObject as RsTarget;
                #endregion

                // Check if there is a part selected.
                #region SelectPart2
                if (selectedPart != null)
                {
                    // Asign the object position and orientation values to the vars
                    PosX = selectedPart.Transform.X;
                    PosY = selectedPart.Transform.Y;
                    PosZ = selectedPart.Transform.Z;

                    DegX = selectedPart.Transform.RX;
                    DegY = selectedPart.Transform.RY;
                    DegZ = selectedPart.Transform.RZ;

                    Logger.AddMessage(new LogMessage(selectedPart.Name.ToString() + " Position copied" +
                                                     " [X = " + selectedPart.Transform.X * 1000 +
                                                     ", Y = " + selectedPart.Transform.Y * 1000 +
                                                     ", Z = " + selectedPart.Transform.Z * 1000 +
                                                     ", Rx = " + Globals.RadToDeg(selectedPart.Transform.RX) +
                                                     ", Ry = " + Globals.RadToDeg(selectedPart.Transform.RY) +
                                                     ", Rz = " + Globals.RadToDeg(selectedPart.Transform.RZ) +
                                                     "]", "Puime's Add-in"));
                    return;
                }
                #endregion

                // Check if there is a RsTarget selected.
                #region SelectRsTarget2
                if (selectedRsTarget != null)
                {
                    // The position obtained in RsRobTarget is relative to its WorkObject and we want it from the station origin (World).
                    // We can get the relative distance betwen the Target and the station origin with "GetRelativeTrasform"
                    RsWorkObject myWobj        = new RsWorkObject();                  // New WorkObject without position (it'll be created at 0,0,0) to define the RsTarget
                    RsRobTarget  myRsRobTarget = new RsRobTarget();                   // New RsRobTarget without position to define the RsTarget.
                    RsTarget     myRsTarget    = new RsTarget(myWobj, myRsRobTarget); // New RsTarget to use in the "GetRelativeTransform"

                    Matrix4 relMx = (selectedRsTarget.Transform.GetRelativeTransform(myRsTarget));

                    // Asing the objetc values to the position and orientation vars
                    PosX = relMx.Translation.x;
                    PosY = relMx.Translation.y;
                    PosZ = relMx.Translation.z;

                    DegX = relMx.EulerZYX.x;
                    DegY = relMx.EulerZYX.y;
                    DegZ = relMx.EulerZYX.z;

                    // RsTarget copied message
                    Logger.AddMessage(new LogMessage(selectedRsTarget.Name.ToString() + " Position copied" +
                                                     " [X = " + relMx.Translation.x * 1000 +
                                                     ", Y = " + relMx.Translation.y * 1000 +
                                                     ", Z = " + relMx.Translation.z * 1000 +
                                                     ", Rx = " + Globals.RadToDeg(relMx.EulerZYX.x) +
                                                     ", Ry = " + Globals.RadToDeg(relMx.EulerZYX.y) +
                                                     ", Rz = " + Globals.RadToDeg(relMx.EulerZYX.z) +
                                                     "]", "Puime's Add-in"));
                    return;
                }
                #endregion

                // Check if there is a WorkObject selected.
                #region SelectedWorkObject2
                if (selectedWorkObject != null)
                {
                    // Asign the object position and orientation values to the vars
                    PosX = selectedWorkObject.UserFrame.X;
                    PosY = selectedWorkObject.UserFrame.Y;
                    PosZ = selectedWorkObject.UserFrame.Z;

                    DegX = selectedWorkObject.UserFrame.RX;
                    DegY = selectedWorkObject.UserFrame.RY;
                    DegZ = selectedWorkObject.UserFrame.RZ;

                    Logger.AddMessage(new LogMessage(selectedWorkObject.Name.ToString() + " Position copied" +
                                                     " [X = " + selectedWorkObject.UserFrame.X * 1000 +
                                                     ", Y = " + selectedWorkObject.UserFrame.Y * 1000 +
                                                     ", Z = " + selectedWorkObject.UserFrame.Z * 1000 +
                                                     ", Rx = " + Globals.RadToDeg(selectedWorkObject.UserFrame.RX) +
                                                     ", Ry = " + Globals.RadToDeg(selectedWorkObject.UserFrame.RY) +
                                                     ", Rz = " + Globals.RadToDeg(selectedWorkObject.UserFrame.RZ) +
                                                     "]", "Puime's Add-in"));
                    return;
                }

                else
                {
                    MessageBox.Show("Please, select a Part, a Target or a WorkObject.");
                }
            }
            catch
            {
                Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
                throw;
            }
            finally
            {
                Project.UndoContext.EndUndoStep();
            }
            #endregion

            #endregion
        }
Ejemplo n.º 6
0
        public static void SetPosition()
        {
            #region Set the position of the selected object
            Project.UndoContext.BeginUndoStep("Set the position of the selected object");
            try
            {
                // Get the selected Part.
                #region SelectPart1
                Part selectedPart = Selection.SelectedObjects.SingleSelectedObject as Part;
                #endregion

                // Get the selected WorkObject.
                #region SelectWorkObject1
                RsWorkObject selectedWorkObject = Selection.SelectedObjects.SingleSelectedObject as RsWorkObject;
                #endregion

                // Get the selected RsTarget.
                #region SelectRsTarget1
                RsTarget selectedRsTarget = Selection.SelectedObjects.SingleSelectedObject as RsTarget;
                #endregion

                // Check if there is a part selected.
                #region SelectPart2
                if (selectedPart != null)

                {
                    #region Log Position and Orientation
                    // Asign the var values to the object position and orientation
                    selectedPart.Transform.X = PosX;
                    selectedPart.Transform.Y = PosY;
                    selectedPart.Transform.Z = PosZ;

                    selectedPart.Transform.RX = DegX;
                    selectedPart.Transform.RY = DegY;
                    selectedPart.Transform.RZ = DegZ;
                    #endregion

                    Logger.AddMessage(new LogMessage("Position applied to " + selectedPart.Name.ToString() +
                                                     " [X = " + selectedPart.Transform.X * 1000 +
                                                     ", Y = " + selectedPart.Transform.Y * 1000 +
                                                     ", Z = " + selectedPart.Transform.Z * 1000 +
                                                     ", Rx = " + Globals.RadToDeg(selectedPart.Transform.RX) +
                                                     ", Ry = " + Globals.RadToDeg(selectedPart.Transform.RY) +
                                                     ", Rz = " + Globals.RadToDeg(selectedPart.Transform.RZ) +
                                                     "]", "Puime's Add-in"));
                    return;
                }
                #endregion


                // Check if there is a RsTarget selected.
                #region SelectRsTarget2
                if (selectedRsTarget != null)
                {
                    RsWorkObject myWobj_origen        = selectedRsTarget.WorkObject;
                    RsRobTarget  myRsRobTarget_origen = new RsRobTarget();
                    RsTarget     myRsTarget_origen    = new RsTarget(myWobj_origen, myRsRobTarget_origen);

                    RsWorkObject myWobj_dest        = new RsWorkObject();
                    RsRobTarget  myRsRobTarget_dest = new RsRobTarget();
                    myRsRobTarget_dest.Frame.X  = PosX;
                    myRsRobTarget_dest.Frame.Y  = PosY;
                    myRsRobTarget_dest.Frame.Z  = PosZ;
                    myRsRobTarget_dest.Frame.RX = DegX;
                    myRsRobTarget_dest.Frame.RY = DegY;
                    myRsRobTarget_dest.Frame.RZ = DegZ;
                    RsTarget myRsTarget_dest = new RsTarget(myWobj_dest, myRsRobTarget_dest);

                    Matrix4 relMx = (myRsTarget_dest.Transform.GetRelativeTransform(myRsTarget_origen));

                    // Asign the var values to the object position and orientation
                    selectedRsTarget.Transform.X = relMx.Translation.x;
                    selectedRsTarget.Transform.Y = relMx.Translation.y;
                    selectedRsTarget.Transform.Z = relMx.Translation.z;

                    selectedRsTarget.Transform.RX = relMx.EulerZYX.x;
                    selectedRsTarget.Transform.RY = relMx.EulerZYX.y;
                    selectedRsTarget.Transform.RZ = relMx.EulerZYX.z;

                    Logger.AddMessage(new LogMessage("Position applied to " + selectedRsTarget.Name.ToString() +
                                                     " [X = " + myRsTarget_dest.Transform.X * 1000 +
                                                     ", Y = " + myRsTarget_dest.Transform.Y * 1000 +
                                                     ", Z = " + myRsTarget_dest.Transform.Z * 1000 +
                                                     ", Rx = " + Globals.RadToDeg(myRsTarget_dest.Transform.RX) +
                                                     ", Ry = " + Globals.RadToDeg(myRsTarget_dest.Transform.RY) +
                                                     ", Rz = " + Globals.RadToDeg(myRsTarget_dest.Transform.RZ) +
                                                     "]", "Puime's Add-in"));
                    return;
                }
                #endregion

                // Check if there is a WorkObject selected.
                #region SelectedWorkObject2
                if (selectedWorkObject != null)
                {
                    // Asign the object values to the vars position and orientation
                    selectedWorkObject.UserFrame.X = PosX;
                    selectedWorkObject.UserFrame.Y = PosY;
                    selectedWorkObject.UserFrame.Z = PosZ;

                    selectedWorkObject.UserFrame.RX = DegX;
                    selectedWorkObject.UserFrame.RY = DegY;
                    selectedWorkObject.UserFrame.RZ = DegZ;

                    Logger.AddMessage(new LogMessage("Position applied to " + selectedWorkObject.Name.ToString() +
                                                     " [X = " + selectedWorkObject.UserFrame.X * 1000 +
                                                     ", Y = " + selectedWorkObject.UserFrame.Y * 1000 +
                                                     ", Z = " + selectedWorkObject.UserFrame.Z * 1000 +
                                                     ", Rx = " + Globals.RadToDeg(selectedWorkObject.UserFrame.RX) +
                                                     ", Ry = " + Globals.RadToDeg(selectedWorkObject.UserFrame.RY) +
                                                     ", Rz = " + Globals.RadToDeg(selectedWorkObject.UserFrame.RZ) +
                                                     "]", "Puime's Add-in"));
                    return;
                }
                #endregion

                else
                {
                    MessageBox.Show("Please, select a Part, a Target or a WorkObject.");
                }
            }
            catch (Exception execption)
            {
                Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
                Logger.AddMessage(new LogMessage(execption.Message.ToString()));
                throw;
            }
            finally
            {
                Project.UndoContext.EndUndoStep();
            }
            #endregion
        }
Ejemplo n.º 7
0
        private static void CreatePath(RsToolData SelectedToolData, RsWorkObject SelectedWorkObject, string speed, string zone)
        {
            Project.UndoContext.BeginUndoStep("RsPathProcedure Create");

            try
            {
                //Get the active Station
                Station station = Project.ActiveProject as Station;
                // Create a PathProcedure.

                RsPathProcedure myPath = new RsPathProcedure("AutoPath" + pathnumber);

                // Add the path to the ActiveTask.
                station.ActiveTask.PathProcedures.Add(myPath);
                myPath.ModuleName  = "module1";
                myPath.ShowName    = true;
                myPath.Synchronize = true;
                myPath.Visible     = true;

                //Make the path procedure as active path procedure
                station.ActiveTask.ActivePathProcedure = myPath;
                int i = 0;
                //Create Path
                foreach (RsTarget target in station.ActiveTask.Targets)
                {
                    if (i == 0)
                    {
                        // new RsMoveInstruction(station.ActiveTask, "Move", "Default",
//MotionType.Joint, station.ActiveTask.ActiveWorkObject.Name, target.Name, station.ActiveTask.ActiveTool.Name);

                        RsMoveInstruction moveInstruction =
                            new RsMoveInstruction(station.ActiveTask, "Move", "Default",
                                                  MotionType.Joint, SelectedWorkObject.Name, target.Name, SelectedToolData.Name);
                        moveInstruction.InstructionArguments["Speed"].Value = speed;
                        moveInstruction.InstructionArguments["Zone"].Value  = zone;

                        myPath.Instructions.Add(moveInstruction);
                    }
                    else
                    {
                        RsMoveInstruction moveInstruction =
                            new RsMoveInstruction(station.ActiveTask, "Move", "Default", MotionType.Linear, SelectedWorkObject.Name,
                                                  target.Name, SelectedToolData.Name);
                        moveInstruction.InstructionArguments["Speed"].Value = speed;
                        moveInstruction.InstructionArguments["Zone"].Value  = zone;
                        myPath.Instructions.Add(moveInstruction);
                    }
                    i++;
                    pathnumber++;
                }
            }
            catch (Exception ex)
            {
                Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
                Logger.AddMessage(new LogMessage(ex.Message.ToString()));
            }
            finally
            {
                Project.UndoContext.EndUndoStep();
            }
        }
Ejemplo n.º 8
0
        public void ReadGcode(string FilePath, string fileName, Double[] Positions,
                              RsToolData toolData, RsWorkObject workObject, string speed, string zone, string resolution, string Xrot, string Yrot, string Zrot)
        {
            arrPositions = new Double[11] {
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
            };
            lastPos = new Double[11] {
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
            };
            AbsPos = new Double[11] {
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
            };

            spd  = speed;
            res  = resolution;
            xrot = Xrot;

            for (int t = 0; t < 8;)
            {
                arrPositions[t] = 0;
                t++;
            }
            ;

            // Initiates a new streamreader
            StreamReader sr = new StreamReader(FilePath);
            //foreach (string line in File.ReadLines(@"C:\Users\dani0007\Documents\Gcode.txt", Encoding.UTF8))
            // string Saved;
            string input;
            // The pattern searches for the letters [ngxyzijkf] followed by a + or - if they exist followed by one or more digits. then if zero or more dots followed by one or more digits, this to exclude the number from ending with a dot.

            string Pattern = @"[ngxyzijkfabc][+-]?(\d+)(.\d+)*";

            if (sr.Peek() <= 0)
            {
                EndOfDocument = true;
            }
            while (sr.Peek() >= 0)
            {
                input = sr.ReadLine();

                Regex           rgx     = new Regex(Pattern, RegexOptions.IgnoreCase);
                MatchCollection matches = rgx.Matches(input);

                if (matches.Count > 0)
                {
                    string[] substrings = Regex.Split(input, @"/n");

                    foreach (string match in substrings)
                    {
                        //Console.WriteLine("Splittar: " + "'{0}'", match);
                    }

                    //Console.WriteLine("{");
                    for (int ctr = 0; ctr < substrings.Length; ctr++)
                    {
                        //Console.WriteLine(substrings[ctr]);


                        Regex           rgx2     = new Regex(Pattern, RegexOptions.IgnoreCase);
                        MatchCollection matches2 = rgx.Matches(substrings[ctr]);

                        #region  Loop that Sorts the values to differnt locations in the Array arrPositions[]
                        foreach (Match match in matches2)
                        {
                            if (Absolute == false)
                            {
                                Logger.AddMessage(new LogMessage("Value is false"));
                            }
                            if (Absolute == true)
                            {
                                Logger.AddMessage(new LogMessage("Value is true"));
                            }

                            if (match.Value == "G02" | match.Value == "G2" | match.Value == "G03" | match.Value == "G3")
                            {
                                arrPositions[4] = 0;
                                arrPositions[5] = 0;
                                arrPositions[6] = 0;
                            }

                            if (Absolute == false && (match.Value == "G0" | match.Value == "G01" | match.Value == "G1" | match.Value == "G02" | match.Value == "G2" | match.Value == "G03" | match.Value == "G3"))
                            {
                                arrPositions[1] = 0;
                                arrPositions[2] = 0;
                                arrPositions[3] = 0;
                            }

                            if (match.Value == "G0" | match.Value == "G01" | match.Value == "G1" | match.Value == "G02" | match.Value == "G2" | match.Value == "G03" | match.Value == "G3" | match.Value == "G90" | match.Value == "G91")
                            {
                                int    StartG  = match.Index + 1;
                                int    LengthG = match.Length;
                                int    EndG    = (match.Index + match.Length);
                                string ValueG  = match.Value.Remove(0, 1);
                                Double DoubleG = Double.Parse(ValueG, CultureInfo.InvariantCulture);
                                arrPositions[0] = DoubleG;
                                if (Absolute == true)
                                {
                                    Logger.AddMessage(new LogMessage("Value: " + match.Value));
                                }
                            }


                            if (match.Value.StartsWith("X") | match.Value.StartsWith("x"))
                            {
                                int    StartX  = match.Index + 1;
                                int    LengthX = match.Length;
                                int    EndX    = (match.Index + match.Length);
                                string ValueX  = match.Value.Remove(0, 1);
                                Double DoubleX = Double.Parse(ValueX, CultureInfo.InvariantCulture);

                                arrPositions[1] = DoubleX;
                            }


                            if (match.Value.StartsWith("Y") | match.Value.StartsWith("y"))
                            {
                                int    StartY  = match.Index + 1;
                                int    LengthY = match.Length;
                                int    EndY    = (match.Index + match.Length);
                                string ValueY  = match.Value.Remove(0, 1);
                                Double DoubleY = Double.Parse(ValueY, CultureInfo.InvariantCulture);

                                arrPositions[2] = DoubleY;
                            }


                            if (match.Value.StartsWith("Z") | match.Value.StartsWith("z"))
                            {
                                int    StartZ  = match.Index + 1;
                                int    LengthZ = match.Length;
                                int    EndZ    = (match.Index + match.Length);
                                string ValueZ  = match.Value.Remove(0, 1);
                                Double DoubleZ = Double.Parse(ValueZ, CultureInfo.InvariantCulture);

                                arrPositions[3] = DoubleZ;
                            }


                            if (match.Value.StartsWith("I") | match.Value.StartsWith("i"))
                            {
                                int    StartI  = match.Index + 1;
                                int    LengthI = match.Length;
                                int    EndI    = (match.Index + match.Length);
                                string ValueI  = match.Value.Remove(0, 1);
                                Double DoubleI = Double.Parse(ValueI, CultureInfo.InvariantCulture);

                                arrPositions[4] = DoubleI;
                            }


                            if (match.Value.StartsWith("J") | match.Value.StartsWith("j"))
                            {
                                int    StartJ  = match.Index + 1;
                                int    LengthJ = match.Length;
                                int    EndJ    = (match.Index + match.Length);
                                string ValueJ  = match.Value.Remove(0, 1);
                                Double DoubleJ = Double.Parse(ValueJ, CultureInfo.InvariantCulture);

                                arrPositions[5] = DoubleJ;
                            }


                            if (match.Value.StartsWith("K") | match.Value.StartsWith("k"))
                            {
                                int    StartK  = match.Index + 1;
                                int    LengthK = match.Length;
                                int    EndK    = (match.Index + match.Length);
                                string ValueK  = match.Value.Remove(0, 1);
                                Double DoubleK = Double.Parse(ValueK, CultureInfo.InvariantCulture);

                                arrPositions[6] = DoubleK;
                            }

                            if (match.Value.StartsWith("F") | match.Value.StartsWith("f"))
                            {
                                int    StartF  = match.Index + 1;
                                int    LengthF = match.Length;
                                int    EndF    = (match.Index + match.Length);
                                string ValueF  = match.Value.Remove(0, 1);
                                Double DoubleF = Double.Parse(ValueF, CultureInfo.InvariantCulture);

                                arrPositions[7] = DoubleF;
                            }

                            if (match.Value.StartsWith("A") | match.Value.StartsWith("a"))
                            {
                                /* int StartF = match.Index + 1;
                                 * int LengthF = match.Length;
                                 * int EndF = (match.Index + match.Length);
                                 * string ValueA = match.Value.Remove(0, 1);
                                 * Double DoubleA = Double.Parse(ValueA, CultureInfo.InvariantCulture);
                                 *
                                 * arrPositions[8] = DoubleA;*/
                            }

                            if (match.Value.StartsWith("B") | match.Value.StartsWith("b"))
                            {
                                /*int StartF = match.Index + 1;
                                 * int LengthF = match.Length;
                                 * int EndF = (match.Index + match.Length);
                                 * string ValueB = match.Value.Remove(0, 1);
                                 * Double DoubleB = Double.Parse(ValueB, CultureInfo.InvariantCulture);
                                 *
                                 * arrPositions[9] = DoubleB;*/
                            }

                            if (match.Value.StartsWith("C") | match.Value.StartsWith("c"))
                            {
                                /*int StartF = match.Index + 1;
                                 * int LengthF = match.Length;
                                 * int EndF = (match.Index + match.Length);
                                 * string ValueC = match.Value.Remove(0, 1);
                                 * Double DoubleC = Double.Parse(ValueC, CultureInfo.InvariantCulture);
                                 *
                                 * arrPositions[10] = DoubleC;*/
                            }
                        }
                        #endregion

                        if (Xrot != "0" | Yrot != "0" | Zrot != "0")
                        {
                            arrPositions[8]  = Double.Parse(Xrot, CultureInfo.InvariantCulture);
                            arrPositions[9]  = Double.Parse(Yrot, CultureInfo.InvariantCulture);
                            arrPositions[10] = Double.Parse(Zrot, CultureInfo.InvariantCulture);
                        }

                        if (arrPositions[0] == 90)     // Sets absoulte coordintes to true
                        {
                            Absolute = true;
                        }
                        else if (arrPositions[0] == 91)     // Sets incremental coordinates to true
                        {
                            Absolute = false;
                        }
                        Globals.positions = arrPositions;
                        #region Handles Absolut or incremental Coordinate system switching

                        if (Absolute == false && (arrPositions[0] == 00 | arrPositions[0] == 0 | arrPositions[0] == 01 | arrPositions[0] == 1 | arrPositions[0] == 02 | arrPositions[0] == 2 | arrPositions[0] == 03 | arrPositions[0] == 3))
                        {
                            arrPositions[1] = arrPositions[1] + lastPos[1];
                            arrPositions[2] = arrPositions[2] + lastPos[2];
                            arrPositions[3] = arrPositions[3] + lastPos[3];

                            //Globals.positions = arrPositions;
                            if (arrPositions[0] == 00 | arrPositions[0] == 0 | arrPositions[0] == 01 | arrPositions[0] == 1)
                            {
                                CreateTargets(arrPositions);
                                for (int i = 0; i < arrPositions.Length; i++)
                                {
                                    lastPos[i] = arrPositions[i];
                                }
                            }
                            else
                            {
                                arrPositions[4] = arrPositions[4] + lastPos[4];
                                arrPositions[5] = arrPositions[5] + lastPos[5];
                                arrPositions[6] = arrPositions[6] + lastPos[6];
                                Parameterize(arrPositions, lastPos, resolution);
                                for (int i = 0; i < arrPositions.Length; i++)
                                {
                                    lastPos[i] = arrPositions[i];
                                }
                            }
                        }



                        //Logger.AddMessage(new LogMessage("if(abs=false & G00/G01) "));


                        else
                        {
                            Globals.positions = arrPositions;
                            if (arrPositions[0] == 00 | arrPositions[0] == 0 | arrPositions[0] == 01 | arrPositions[0] == 1)
                            {
                                CreateTargets(arrPositions);
                                for (int i = 0; i < arrPositions.Length; i++)
                                {
                                    lastPos[i] = arrPositions[i];
                                }
                            }
                            else
                            {
                                Parameterize(arrPositions, lastPos, resolution);
                                for (int i = 0; i < arrPositions.Length; i++)
                                {
                                    lastPos[i] = arrPositions[i];
                                }
                            }
                        }
                        #endregion
                    }
                }
            }
            //a++;
            sr.Close();
            CreatePath(toolData, workObject, speed, zone);
        }
Ejemplo n.º 9
0
        public static void ObtainPosition()
        {
            #region Get the position of the selected object
            Project.UndoContext.BeginUndoStep("Get the position of the selected object");
            try
            {
                // Get the selected Part.
                #region SelectPart1
                Part selectedPart = Selection.SelectedObjects.SingleSelectedObject as Part;
                #endregion

                // Get the selected WorkObject.
                #region SelectWorkObject1
                RsWorkObject selectedWorkObject = Selection.SelectedObjects.SingleSelectedObject as RsWorkObject;
                #endregion

                // Get the selected RsTarget.
                #region SelectRsTarget1
                RsTarget selectedRsTarget = Selection.SelectedObjects.SingleSelectedObject as RsTarget;
                #endregion

                // Check if there is a part selected.
                #region SelectPart2
                if (selectedPart != null)
                {
                    // Asignamos los valores del objeto a las variables de posición y orientación
                    PosX = selectedPart.Transform.X;
                    PosY = selectedPart.Transform.Y;
                    PosZ = selectedPart.Transform.Z;

                    DegX = selectedPart.Transform.RX;
                    DegY = selectedPart.Transform.RY;
                    DegZ = selectedPart.Transform.RZ;

                    // Mensaje del part copiado
                    // (rselectedPart.Transform.RX * 180) / System.Math.PI
                    // Globals.RadToDeg(selectedPart.Transform.RX)

                    Logger.AddMessage(new LogMessage(selectedPart.Name.ToString() + " Position copied" +
                                                     " [X = " + selectedPart.Transform.X * 1000 +
                                                     ", Y = " + selectedPart.Transform.Y * 1000 +
                                                     ", Z = " + selectedPart.Transform.Z * 1000 +
                                                     ", Rx = " + Globals.RadToDeg(selectedPart.Transform.RX) +
                                                     ", Ry = " + Globals.RadToDeg(selectedPart.Transform.RY) +
                                                     ", Rz = " + Globals.RadToDeg(selectedPart.Transform.RZ) +
                                                     "]", "Puime's Add-in"));
                    return;
                }
                #endregion

                // Check if there is a RsTarget selected.
                #region SelectRsTarget2
                if (selectedRsTarget != null)
                {
                    // La posición que nos muestra directamenta el RsRobTarget es relativo a su WorkObject y nosotros lo queremos
                    // relativo al origen de la estación (mundo).
                    // Obtenemos la distancia relativa entre el punto y el origen de la estación con "GetRelativeTransform"

                    RsWorkObject myWobj        = new RsWorkObject();                  // Declaramos un WorkObject sin definirle posición para que lo cree en el 0,0,0 (para definir el RsTarget)
                    RsRobTarget  myRsRobTarget = new RsRobTarget();                   // Declaramos un RsRobTarget sin posición (para definir el RsTarget)
                    RsTarget     myRsTarget    = new RsTarget(myWobj, myRsRobTarget); // Declaramos el RsTarget para utilizarlo en "GetRelativeTransform"

                    Matrix4 relMx = (selectedRsTarget.Transform.GetRelativeTransform(myRsTarget));

                    // Asignamos los valores del objeto a las variables de posición y orientación

                    PosX = relMx.Translation.x;
                    PosY = relMx.Translation.y;
                    PosZ = relMx.Translation.z;

                    DegX = relMx.EulerZYX.x;
                    DegY = relMx.EulerZYX.y;
                    DegZ = relMx.EulerZYX.z;

                    // Mensaje del RsTarget copiado

                    Logger.AddMessage(new LogMessage(selectedRsTarget.Name.ToString() + " Position copied" +
                                                     " [X = " + relMx.Translation.x * 1000 +
                                                     ", Y = " + relMx.Translation.y * 1000 +
                                                     ", Z = " + relMx.Translation.z * 1000 +
                                                     ", Rx = " + Globals.RadToDeg(relMx.EulerZYX.x) +
                                                     ", Ry = " + Globals.RadToDeg(relMx.EulerZYX.y) +
                                                     ", Rz = " + Globals.RadToDeg(relMx.EulerZYX.z) +
                                                     "]", "Puime's Add-in"));
                    return;
                }
                #endregion

                // Check if there is a WorkObject selected.
                #region SelectedWorkObject2
                if (selectedWorkObject != null)
                {
                    // Asignamos los valores del objeto a las variables de posición y orientación
                    PosX = selectedWorkObject.UserFrame.X;
                    PosY = selectedWorkObject.UserFrame.Y;
                    PosZ = selectedWorkObject.UserFrame.Z;

                    DegX = selectedWorkObject.UserFrame.RX;
                    DegY = selectedWorkObject.UserFrame.RY;
                    DegZ = selectedWorkObject.UserFrame.RZ;

                    // Mensaje del WorkObject copiado
                    Logger.AddMessage(new LogMessage(selectedWorkObject.Name.ToString() + " Position copied" +
                                                     " [X = " + selectedWorkObject.UserFrame.X * 1000 +
                                                     ", Y = " + selectedWorkObject.UserFrame.Y * 1000 +
                                                     ", Z = " + selectedWorkObject.UserFrame.Z * 1000 +
                                                     ", Rx = " + Globals.RadToDeg(selectedWorkObject.UserFrame.RX) +
                                                     ", Ry = " + Globals.RadToDeg(selectedWorkObject.UserFrame.RY) +
                                                     ", Rz = " + Globals.RadToDeg(selectedWorkObject.UserFrame.RZ) +
                                                     "]", "Puime's Add-in"));
                    return;
                }

                else
                {
                    MessageBox.Show("Please, select a Part, a Target or a WorkObject.");
                }
            }
            catch
            {
                Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
                throw;
            }
            finally
            {
                Project.UndoContext.EndUndoStep();
            }
            #endregion

            #endregion
        }