コード例 #1
0
        /// <summary>
        /// Creates a new joint editor proptery manager page that allows the user to edit joint properties.
        /// </summary>
        /// <param name="robot">Active robot model</param>
        /// <param name="joint">Joint to be edited</param>
        /// <param name="document">Active assembly document</param>
        /// <param name="swApp">Solidworks application environment</param>
        public JointPMPage(RobotModel robot, Joint joint, AssemblyDoc document, SldWorks swApp)
        {
            //Validate parameters
            if (robot == null)
                throw new ProgramErrorException("Tried to create a JointPMPage with a null robot model.");
            if (document == null)
                throw new ProgramErrorException("Tried to create a JointPMPage with a null assembly document.");
            if (swApp == null)
                throw new ProgramErrorException("Tried to create a JointPMPage with a null solidworks application interface.");

            //Initialize fields
            this.robot = robot;
            this.swApp = swApp;
            currentJoint = joint;
            mathUtil = ((IMathUtility)swApp.GetMathUtility());

            //AssemblyDoc inherits ModelDoc2 but the relationship dosn't carry through the COM interface
            //Having two fields prevents having to cast half of the time
            modelDoc = (ModelDoc2)document;
            assemblyDoc = document;

            //Setup the page, its controls and their visual layout
            SetupPage();

            SelectionObservers = new List<SelectionObserver>();
            ButtonObservers = new List<ButtonObserver>();
            CheckboxObservers = new List<CheckboxObserver>();
        }
コード例 #2
0
        public bool ConnectToSW(object ThisSW, int Cookie)
        {
            _swApp    = (SldWorks)ThisSW;
            mSWCookie = Cookie;
            // Set-up add-in call back info
            bool result = _swApp.SetAddinCallbackInfo(0, this, Cookie);

            swMathUtility = (MathUtility)_swApp.GetMathUtility();
            orientation   = swMathUtility.CreateTransform(new double[1]);
            this.UISetup();
            _swApp.SendMsgToUser2("timer started",
                                  (int)swMessageBoxIcon_e.swMbInformation,
                                  (int)swMessageBoxBtn_e.swMbOk);
            return(true);
        }
コード例 #3
0
        public AssemblyContext(string assemblyPath)
        {
            //var sw = Activator.GetObject(Type.GetTypeFromProgID("SldWorks.Application")) as SldWorks;
            //var sw = (SldWorks)System.Runtime.InteropServices.Marshal.GetActiveObject("SldWorks.Application");
            sw            = new SldWorks();
            sw.Visible    = true;
            workingFolder = Path.GetDirectoryName(assemblyPath);
            sw.SetCurrentWorkingDirectory(workingFolder);

            var filePath = assemblyPath;

            doc = sw.OpenDoc6(filePath,
                              (int)swDocumentTypes_e.swDocASSEMBLY,
                              (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "",
                              ref error, ref warning);

            drag = (DragOperator)((AssemblyDoc)doc).GetDragOperator();
            math = (MathUtility)sw.GetMathUtility();
        }
コード例 #4
0
        public AssemblyContext(string assemblyPath)
        {
            //var sw = Activator.GetObject(Type.GetTypeFromProgID("SldWorks.Application")) as SldWorks;
            //var sw = (SldWorks)System.Runtime.InteropServices.Marshal.GetActiveObject("SldWorks.Application");
            sw = new SldWorks();
            sw.Visible = true;
            workingFolder = Path.GetDirectoryName(assemblyPath);
            sw.SetCurrentWorkingDirectory(workingFolder);

            var filePath = assemblyPath;

            doc = sw.OpenDoc6(filePath,
                (int)swDocumentTypes_e.swDocASSEMBLY,
                (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "",
                ref error, ref warning);

            drag = (DragOperator)((AssemblyDoc)doc).GetDragOperator();
            math = (MathUtility)sw.GetMathUtility();
        }
コード例 #5
0
        internal static bool processModel(SldWorks swApp, string file, string targetFile, string calcFile, CancellationToken cancellationToken)
        {
            // Initiate variables
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-GB");
            StreamWriter toFile = new StreamWriter(targetFile);

            toFile.AutoFlush = true;
            StreamWriter toCalc = new StreamWriter(calcFile);

            toCalc.AutoFlush = true;
            MathUtility swMathUtil = default(MathUtility);
            ModelDoc2   swModel    = default(ModelDoc2);
            Feature     swFeat     = default(Feature);
            Feature     swMateFeat = null;
            Feature     swSubFeat  = default(Feature);
            Mate2       swMate     = default(Mate2);
            Component2  swComp     = default(Component2);

            MateEntity2[] swMateEnt  = new MateEntity2[3];
            MathTransform swTrans    = default(MathTransform);
            MathPoint     swOrig     = default(MathPoint);
            AssemblyDoc   swAssembly = default(AssemblyDoc);

            double[] corners   = new double[6];
            int[]    swAssyDir = new int[6];
            double[] nPt       = new double[3];
            object   vPt       = null;
            double   height    = 0;
            double   width     = 0;
            double   depth     = 0;
            int      Warning   = 0;
            int      Error     = 0;
            int      i         = 0;

            double[] entityParameters = new double[8];
            // Start function
            try
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    return(false);
                }
                string extention = Path.GetExtension(file);
                int    type      = 0;
                if (extention.ToLower().Contains("sldprt"))
                {
                    type = (int)swDocumentTypes_e.swDocPART;
                }
                else
                {
                    type = (int)swDocumentTypes_e.swDocASSEMBLY;
                }
                // Get assembly model
                swModel = swApp.OpenDoc6(file, type, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref Error, ref Warning) as ModelDoc2;
                if (Error != 0)
                {
                    return(false);
                }
                if (swModel == null)
                {
                    return(false);
                }
                swModel.Visible = true;
                // Get first assembly feature
                swFeat = (Feature)swModel.FirstFeature();
                // Iterate over features in FeatureManager design tree
                while ((swFeat != null))
                {
                    if ("MateGroup" == swFeat.GetTypeName())
                    {
                        swMateFeat = swFeat;
                        break;
                    }
                    swFeat = swFeat = swFeat.GetNextFeature();
                }
                toFile.WriteLine(" " + swMateFeat.Name);
                toFile.WriteLine("");
                // Get first mate, which is a subfeature
                swSubFeat = (Feature)swMateFeat.GetFirstSubFeature();
                while ((swSubFeat != null))
                {
                    swMate = (Mate2)swSubFeat.GetSpecificFeature2();
                    if ((swMate != null))
                    {
                        for (i = 0; i <= 1; i++)
                        {
                            swMateEnt[i] = swMate.MateEntity(i);
                            swComp       = swMateEnt[i].ReferenceComponent;
                            // Initate point
                            nPt[0] = 0.0;
                            nPt[1] = 0.0;
                            nPt[2] = 0.0;
                            vPt    = nPt;
                            // Get component origin point
                            swTrans    = swComp.Transform2;
                            swMathUtil = (MathUtility)swApp.GetMathUtility();
                            swOrig     = (MathPoint)swMathUtil.CreatePoint(vPt);
                            swOrig     = (MathPoint)swOrig.MultiplyTransform(swTrans);
                            // Write parameters to readable ASCII file
                            toFile.WriteLine("    " + swSubFeat.Name);
                            toFile.WriteLine("      Type              = " + swMate.Type);
                            toFile.WriteLine("      Alignment         = " + swMate.Alignment);
                            toFile.WriteLine("      Can be flipped    = " + swMate.CanBeFlipped);
                            toFile.WriteLine("");
                            toFile.WriteLine("      Component         = " + swComp.Name2);
                            toFile.WriteLine("      Origin            = (" + ((double[])swOrig.ArrayData)[0] * 1000.0 + ", " + ((double[])swOrig.ArrayData)[1] * 1000.0 + ", " + ((double[])swOrig.ArrayData)[2] * 1000.0 + ")");
                            toFile.WriteLine("      Mate enity type   = " + swMateEnt[i].ReferenceType);
                            entityParameters = (double[])swMateEnt[i].EntityParams;
                            toFile.WriteLine("      (x,y,z)           = (" + entityParameters[0] * 1000 + ", " + entityParameters[1] * 1000 + ", " + entityParameters[2] * 1000 + ")");
                            toFile.WriteLine("      (i,j,k)           = (" + entityParameters[3] + ", " + entityParameters[4] + ", " + entityParameters[5] + ")");
                            toFile.WriteLine("      Radius 1          = " + entityParameters[6] * 1000);
                            toFile.WriteLine("      Radius 2          = " + entityParameters[7] * 1000);
                            toFile.WriteLine("");
                            // Write parameters to a simplified ASCII file for computation
                            toCalc.Write(swSubFeat.Name);
                            toCalc.Write(" " + swMate.Type);
                            toCalc.Write(" " + swMate.Alignment);
                            toCalc.Write(" " + swMate.CanBeFlipped);
                            toCalc.Write(" " + swComp.Name2);
                            toCalc.Write(" " + ((double[])swOrig.ArrayData)[0] * 1000.0 + "," + ((double[])swOrig.ArrayData)[1] * 1000.0 + "," + ((double[])swOrig.ArrayData)[2] * 1000.0);
                            toCalc.Write(" " + swMateEnt[i].ReferenceType);
                            toCalc.Write(" " + entityParameters[0] * 1000.0 + "," + entityParameters[1] * 1000.0 + "," + entityParameters[2] * 1000.0);
                            toCalc.Write(" " + entityParameters[3] + "," + entityParameters[4] + "," + entityParameters[5]);
                            toCalc.Write(" " + entityParameters[6] * 1000.0);
                            toCalc.WriteLine(" " + entityParameters[7] * 1000.0);
                        }
                        toFile.WriteLine(" ");
                    }
                    // Get the next mate in MateGroup
                    swSubFeat = (Feature)swSubFeat.GetNextSubFeature();
                }
                // Get bounding box around assembly
                swAssembly = (AssemblyDoc)swModel;
                corners    = swAssembly.GetBox(1);
                height     = (corners[4] - corners[1]) * 1000.0;
                width      = (corners[3] - corners[0]) * 1000.0;
                depth      = (corners[5] - corners[2]) * 1000.0;
                // Write to file
                toFile.WriteLine("Aprx. assembly dimensions");
                toFile.WriteLine("(Height, Width, Depth) = (" + height + ", " + width + ", " + depth + ")");
                toFile.WriteLine(" ");
                toCalc.WriteLine("dims(hwd) " + height + " " + width + " " + depth);
                // Get Possible Assembly Directions with interferenceDir function
                interference inter = new interference();
                swAssyDir = inter.interferenceDir(swApp, swModel, swMateFeat, swMateEnt);
                // Write swAssyDir to file
                toFile.WriteLine("(x+, x-, y+, y-, z+, z-) = (" + swAssyDir[0] + ", " + swAssyDir[1] + ", " + swAssyDir[2] + ", " + swAssyDir[3] + ", " + swAssyDir[4] + ", " + swAssyDir[5] + ") ");
                toFile.WriteLine("1 is possible, 0 is not possible");
                toFile.WriteLine("");
                toFile.WriteLine("All dimensions are in mm");
                toCalc.Write("dir " + swAssyDir[0] + " " + swAssyDir[1] + " " + swAssyDir[2] + " " + swAssyDir[3] + " " + swAssyDir[4] + " " + swAssyDir[5]);
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
コード例 #6
0
 /// <summary>
 /// Sets the various properties of the current robot
 /// </summary>
 /// <param name="swApp">The solidworks application</param>
 /// <param name="asmDoc">The current assembly</param>
 /// <param name="swData">The current storage model</param>
 /// <param name="robot">the current robot</param>
 public static void SetProperties(SldWorks swApp, AssemblyDoc asmDoc, StorageModel swData, RobotModel robot)
 {
     SwApp = swApp;
     ModelDoc = (ModelDoc2)asmDoc;
     AssemDoc = asmDoc;
     SwData = swData;
     Robot = robot;
     mathUtil = SwApp.GetMathUtility();
 }
コード例 #7
0
        /// <summary>
        /// Constructs a new IJointAxis
        /// </summary>
        /// <param name="path">Path to this joint's storage</param>
        /// <param name="current">The joint that this axis is contained in</param>
        public IJointAxis(string path, Joint current)
        {
            this.swApp = RobotInfo.SwApp;
            this.modelDoc = RobotInfo.ModelDoc;
            this.swData = RobotInfo.SwData;
            this.path = path;
            this.owner = current;
            this.robot = RobotInfo.Robot;

            if (EffortLimit == 0)
            {
                this.EffortLimit = 1;
            }

            if (Axis != null)
            {
                CalcAxisVector();
            }
            mathUtil = (MathUtility)swApp.GetMathUtility();
        }
コード例 #8
0
        public int[] interferenceDir(SldWorks swApp, ModelDoc2 swModel, Feature swMateFeat, MateEntity2[] swMateEnt)
        {
            // Initiate variables
            MathUtility       swMathUtil    = default(MathUtility);
            AssemblyDoc       swAssembly    = default(AssemblyDoc);
            ModelDocExtension swModelDocExt = default(ModelDocExtension);
            DragOperator      swDragOp      = default(DragOperator);
            MathTransform     swXform       = default(MathTransform);
            Feature           swSubFeat     = default(Feature);
            Component2        swComp0       = default(Component2);
            Component2        swComp1       = default(Component2);
            SelectionMgr      swSelMgr      = default(SelectionMgr);

            Component2[] EntityArray;
            bool         supstat = false;
            bool         bRet    = false;
            int          i       = 0;
            int          j       = 0;
            int          k       = 0;

            double[] dir;
            double[] entityParameters = new double[8];
            int[]    swAssyDir        = new int[6];
            double[] trans            = new double[16];
            // Get accesss to the model
            swModelDocExt = swModel.Extension;
            // Suppressing mates to be able to move them
            swSubFeat = (Feature)swMateFeat.GetFirstSubFeature();
            while ((swSubFeat != null))
            {
                supstat   = swModelDocExt.SelectByID2(swSubFeat.Name, "MATE", 0, 0, 0, false, 0, null, 0);
                supstat   = swModel.EditSuppress2();
                swSubFeat = (Feature)swSubFeat.GetNextSubFeature();
            }
            // Get parts
            swComp0 = swMateEnt[0].ReferenceComponent;
            swComp1 = swMateEnt[1].ReferenceComponent;
            // Run .stl meshing function
            save.saveAs(swApp, swComp0, swComp1, swModelDocExt);
            // Define variables
            swAssembly  = (AssemblyDoc)swModel;
            swDragOp    = (DragOperator)swAssembly.GetDragOperator();
            swMathUtil  = (MathUtility)swApp.GetMathUtility();
            swSelMgr    = swModel.SelectionManager;
            EntityArray = new Component2[] { swComp0, swComp1 };
            // Decide parameters for DragOperator interface
            bRet = swDragOp.AddComponent(swComp1, false);
            bRet = swDragOp.CollisionDetection(EntityArray, true, true);
            swDragOp.CollisionDetectionEnabled = true;
            swDragOp.DynamicClearanceEnabled   = false;
            swDragOp.UseAbsoluteTransform      = false;
            swDragOp.IgnoreComplexSurfaces     = true;
            swDragOp.HearClashes      = false;
            swDragOp.HighlightClashes = false;
            swDragOp.TransformType    = 0;
            swDragOp.DragMode         = 0;
            // Begin moving component
            bRet = swDragOp.BeginDrag();
            for (i = 0; i < 6; i++)
            {
                if (i == 0)
                {
                    dir = new double[] { 0.005, 0, 0 }
                }
                ;
                else if (i == 1)
                {
                    dir = new double[] { -0.005, 0, 0 }
                }
                ;
                else if (i == 2)
                {
                    dir = new double[] { 0, 0.005, 0 }
                }
                ;
                else if (i == 3)
                {
                    dir = new double[] { 0, -0.005, 0 }
                }
                ;
                else if (i == 4)
                {
                    dir = new double[] { 0, 0, 0.005 }
                }
                ;
                else
                {
                    dir = new double[] { 0, 0, -0.005 }
                };
                // Move up to five steps along vector (dir)
                for (j = 0; j < 5; j++)
                {
                    trans   = new double[] { 1, 0, 0, 0, 1, 0, 0, 0, 1, dir[0], dir[1], dir[2], 1, 0, 0, 0 };
                    swXform = (MathTransform)swMathUtil.CreateTransform(trans);
                    bRet    = swDragOp.Drag(swXform);
                    // Check return status of interference detector
                    k = j + 1;
                    if (bRet == true)
                    {
                        swAssyDir[i] = 1;
                    }
                    else
                    {
                        swAssyDir[i] = 0;
                        break;
                    }
                }
                // Move back the number of steps moved
                if (swAssyDir[i] == 1)
                {
                    trans[9]  = trans[9] * (-k);
                    trans[10] = trans[10] * (-k);
                    trans[11] = trans[11] * (-k);
                    swXform   = (MathTransform)swMathUtil.CreateTransform(trans);
                    bRet      = swDragOp.Drag(swXform);
                }
            }
            bRet = swDragOp.EndDrag();
            // Unsuppress mates
            swSubFeat = (Feature)swMateFeat.GetFirstSubFeature();
            while ((swSubFeat != null))
            {
                supstat   = swModelDocExt.SelectByID2(swSubFeat.Name, "MATE", 0, 0, 0, false, 0, null, 0);
                supstat   = swModel.EditUnsuppress2();
                swSubFeat = (Feature)swSubFeat.GetNextSubFeature();
            }
            // Return interference vector
            return(swAssyDir);
        }
    }