/* Straight forward method, opens the doc in the way we want it, debugs any errors */
        //Returns null on failure
        static SldWorks.ModelDoc2 OpenDoc(SldWorks.SldWorks app, string filePath)
        {
            int errors   = 0;
            int warnings = 0;

            Console.WriteLine("Opening Doc: " + filePath);
            SldWorks.ModelDoc2 doc = app.OpenDoc6(
                filePath,
                (int)(SwConst.swDocumentTypes_e.swDocASSEMBLY),
                (int)(SwConst.swOpenDocOptions_e.swOpenDocOptions_Silent | SwConst.swOpenDocOptions_e.swOpenDocOptions_ReadOnly),
                "default",
                ref errors,
                ref warnings);

            if (errors != 0)
            {
                Console.WriteLine("Error: " + errors);
            }
            if (warnings != 0)
            {
                Console.WriteLine("Warnings: " + warnings);
            }

            return(doc);
        }
        static void Main(string[] args)
        {
            if (args.Length != 2 || args[0] == "-h")
            {
                PrintUsage();
                return;
            }

            List <string> filesToParse = new List <string>();
            List <string> meshTitles   = new List <string>();

            if (!ParseIndexFile(args[0], ref filesToParse, ref meshTitles))
            {
                Console.WriteLine("Couldn't read index file");
                return;
            }

            if (filesToParse.Count != meshTitles.Count)
            {
                Console.WriteLine("Something amiss: Had different number of files than mesh names. Maybe the index file specified is malformed?");
                Console.WriteLine("Num Files: " + filesToParse.Count + ", Num Mesh Names: " + meshTitles.Count);
                return;
            }

            SldWorks.SldWorks swApp = new SldWorks.SldWorks();

            List <string> xmlTags = new List <string>();

            try {
                for (int i = 0; i < filesToParse.Count; i++)
                {
                    SldWorks.ModelDoc2 doc = OpenDoc(swApp, filesToParse[i]);
                    if (doc == null)
                    {
                        Console.WriteLine("Null Doc: " + filesToParse[i]);
                        Console.WriteLine("Check that the index file specified is properly formed.");
                    }
                    else
                    {
                        MassPropertySet mpSet = GetMassPropertiesFromDoc(doc);
                        xmlTags.AddRange(GenerateXMLTags(meshTitles[i], mpSet));

                        /*  It makes the most sense to close the solidworks document at this point...
                         *  but for some reason that was giving errors... maybe something about lazy loading?
                         *  So instead we leave them all open until we are done with them                         */
                        // doc.Close();
                    }
                }
            }
            catch
            {
                Console.WriteLine("Problem while reading from solidworks files");
            }

            swApp.ExitApp();
            swApp = null;

            Console.WriteLine("Outputting to xacro");
            OutputToXacroFile(args[1], xmlTags);
        }
 internal static void Dispose()
 {
     if (swApp != null)
     {
         swApp.ExitApp();
         swApp = null;
     }
 }
示例#4
0
        static void Main(string[] args)
        {
            SldWorks.SldWorks swApp;

            swApp = new SldWorks.SldWorks();

            swApp.ExitApp();
            swApp = null;
        }
 internal static SldWorks.SldWorks Get_swApp()
 {
     if (swApp == null)
     {
         swApp         = Activator.CreateInstance(Type.GetTypeFromProgID("SldWorks.Application")) as SldWorks.SldWorks;
         swApp.Visible = true;
         return(swApp);
     }
     return(swApp);
 }
 internal async static Task <SldWorks.SldWorks> Get_swAppAsync()
 {
     if (swApp == null)
     {
         return(await Task.Run(() => {
             swApp = Activator.CreateInstance(Type.GetTypeFromProgID("SldWorks.Application")) as SldWorks.SldWorks;
             swApp.Visible = true;
             return swApp;
         }));
     }
     return(swApp);
 }
示例#7
0
        static void Main(string[] args)
        {
            SldWorks.SldWorks swApp;
            swApp = new SldWorks.SldWorks();

            ModelDoc2   swModel = default(ModelDoc2);
            Component2  swComponent;
            AssemblyDoc swAssembly;

            object[]    Components       = null;
            object[]    swMateEntityList = null;
            MateEntity2 swMateEntity;
            Mate2       swMate;
            MateInPlace swMateInPlace;
            int         numMateEntities = 0;
            int         i = 0;
            dynamic     temp;
            Component2  temp2;

            Feature swFeat = default(Feature);
            Feature swSubFeat;
            string  Filename = null;
            int     errors   = 0;
            int     warnings = 0;

            Filename = "F:\\solidWorksAPI\\TEST_20180105\\Assembly_20180105.sldasm";

            // Open document
            swApp.OpenDoc6(Filename, (int)swDocumentTypes_e.swDocASSEMBLY, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);
            swModel    = (ModelDoc2)swApp.ActiveDoc;
            swAssembly = (AssemblyDoc)swModel;

            /*           // Iterate through parts document and list concentric mate. Would Get repeating ones.
             *          Components = (Object[])swAssembly.GetComponents(false);
             *          foreach (Object SingleComponent in Components)
             *          {
             *              swComponent = (Component2)SingleComponent;
             *              Console.WriteLine("Name of component: " + swComponent.Name2);
             *              Mates = (Object[])swComponent.GetMates();
             *              if (Mates != null)
             *              {
             *                  foreach (Object SingleMate in Mates)
             *                  {
             *                      if (SingleMate is SolidWorks.Interop.sldworks.Mate2)
             *                      {
             *                          swMate = (Mate2)SingleMate;
             *                          if (swMate.Type == 1)
             *                              Console.WriteLine("Found one concentric mate.");
             *
             *                      }
             *
             *
             *                      if (SingleMate is SolidWorks.Interop.sldworks.MateInPlace)
             *
             *                      {
             *
             *                          swMateInPlace = (MateInPlace)SingleMate;
             *
             *                          numMateEntities = swMateInPlace.GetMateEntityCount();
             *
             *                          for (i = 0; i <= numMateEntities - 1; i++)
             *
             *                          {
             *
             *                              Console.WriteLine(" Mate component name: " + swMateInPlace.get_MateComponentName(i));
             *
             *                              Console.WriteLine(" Type of mate inplace: " + swMateInPlace.get_MateEntityType(i));
             *
             *                          }
             *                      }
             *                  }
             *
             *              }
             *          }
             *
             */
            // Get first feature in swModel
            swFeat = (Feature)swModel.FirstFeature();
            // Iterate over features in this part document in
            // FeatureManager design tree

            while ((swFeat != null))
            {
                // Write the name of the feature and its
                // creator to the Immediate window
                Console.WriteLine("  Feature " + swFeat.Name + " created by " + swFeat.GetTypeName());

                if (swFeat.GetTypeName() == "MateGroup")
                {
                    // Get first mate, which is a subfeature
                    swSubFeat = (Feature)swFeat.GetFirstSubFeature();

                    while (swSubFeat != null)
                    {
                        swMate = swSubFeat.GetSpecificFeature2();
                        // Go further analysis if swMate is of concentric type
                        if (swMate != null & swMate.Type == (int)swMateType_e.swMateCONCENTRIC)
                        {
                            Console.WriteLine(swSubFeat.Name);
                            Console.WriteLine("Num of Entity envolved: " + swMate.GetMateEntityCount());
                            //Console.WriteLine(swMate.MateEntity(2).GetEntityParamsSize());
                            for (i = 0; i <= 1; i++)
                            {
                                swMateEntity = swMate.MateEntity(i);
                                // Can't watch entity params in the watch window but works if setting a new variable.
                                temp = swMateEntity.EntityParams;
示例#8
0
 public ExportPoints(SldWorks.SldWorks swApp) :
     base(swApp)
 {
      listOfSketchPoints  = new List<SldWorks.SketchPoint>();
 }
示例#9
0
        private void Button1_Click(object sender, EventArgs e)
        {
            // Declaration of all global variable
            SldWorks.SldWorks swApp;
            var errors   = default(long);
            var warnings = default(long);

            SldWorks.ModelDoc2 swModel;
            object             result;
            Array  moiArray;
            string listBoxVal;

            // Connecting to the Solidworks Application
            swApp = new SldWorks.SldWorks();

            // Storing the file in global swModel
            SldWorks.ModelDoc2 localOpenDoc6()
            {
                int argErrors = Conversions.ToInteger(errors); int argWarnings = Conversions.ToInteger(warnings); var ret = swApp.OpenDoc6(@"E:\Tandemloop\Project\3d-local\Door.SLDPRT", (int)SwConst.swDocumentTypes_e.swDocPART, (int)SwConst.swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref argErrors, ref argWarnings); return(ret);
            }

            swModel = localOpenDoc6();
            if (this.ComboBox1.SelectedIndex == 0)
            {
                result     = COM(swModel);
                listBoxVal = "COM " + result.ToString();
                this.ListBox1.Items.Add(listBoxVal);
                this.ListBox1.Items.Add("");
                this.ListBox1.TopIndex = this.ListBox1.Items.Count - 1;
            }

            if (this.ComboBox1.SelectedIndex == 1)
            {
                // Calling the Density function and storing the double value to the variable as Result.

                result     = Density(swModel);
                listBoxVal = "Density for the model is " + result.ToString();
                this.ListBox1.Items.Add(listBoxVal);
                this.ListBox1.Items.Add("");
                this.ListBox1.TopIndex = this.ListBox1.Items.Count - 1;
            }

            if (this.ComboBox1.SelectedIndex == 2)
            {
                // Calling the Volume function and storing the double value to the variable as Result.

                result     = Volume(swModel);
                listBoxVal = "Volume for the model is " + result.ToString();
                this.ListBox1.Items.Add(listBoxVal);
                this.ListBox1.Items.Add("");
                this.ListBox1.TopIndex = this.ListBox1.Items.Count - 1;
            }

            if (this.ComboBox1.SelectedIndex == 3)
            {
                // Calling the Mass function and storing the double value to the variable as Result.

                result     = Mass(swModel);
                listBoxVal = "Mass for the model is " + result.ToString();
                this.ListBox1.Items.Add(listBoxVal);
                this.ListBox1.Items.Add("");
                this.ListBox1.TopIndex = this.ListBox1.Items.Count - 1;
            }

            if (this.ComboBox1.SelectedIndex == 4)
            {
                // Calling the surfaceArea function and storing the double value to the variable as Result.

                result     = surfaceArea(swModel);
                listBoxVal = "Surface Area for the model is " + result.ToString();
                this.ListBox1.Items.Add(listBoxVal);
                this.ListBox1.Items.Add("");
                this.ListBox1.TopIndex = this.ListBox1.Items.Count - 1;
            }

            if (this.ComboBox1.SelectedIndex == 5)
            {
                moiArray = MOI(swModel);
                this.ListBox1.Items.Add("Moment of Inertia of the Model is");
                listBoxVal = "Lxx =" + moiArray(6).ToString() + " " + "m4";
                this.ListBox1.Items.Add(listBoxVal);
                listBoxVal = "Lyy =" + moiArray(7).ToString() + " " + "m4";
                this.ListBox1.Items.Add(listBoxVal);
                listBoxVal = "Lzz =" + moiArray(8).ToString() + " " + "m4";
                this.ListBox1.Items.Add(listBoxVal);
                listBoxVal = "Lxy =" + moiArray(9).ToString() + " " + "m4";
                this.ListBox1.Items.Add(listBoxVal);
                listBoxVal = "Lxz =" + moiArray(10).ToString() + " " + "m4";
                this.ListBox1.Items.Add(listBoxVal);
                listBoxVal = "Lyz =" + moiArray(11).ToString() + " " + "m4";
                this.ListBox1.Items.Add(listBoxVal);
                this.ListBox1.Items.Add("");
                this.ListBox1.TopIndex = this.ListBox1.Items.Count - 1;
            }

            if (this.ComboBox1.SelectedIndex == 6)
            {
                // Calling the path function and storing the double value to the variable as Result.

                result     = path(swModel);
                listBoxVal = (string)Operators.AddObject("Path of the file is :", result);
                this.ListBox1.Items.Add(listBoxVal);
                this.ListBox1.Items.Add("");
                this.ListBox1.TopIndex = this.ListBox1.Items.Count - 1;
            }

            if (this.ComboBox1.SelectedIndex == 7)
            {
                listBoxVal = "FIle Details are ";
                this.ListBox1.Items.Add(listBoxVal);
                fileDetails(swModel);
                this.ListBox1.Items.Add("");
                this.ListBox1.TopIndex = this.ListBox1.Items.Count - 1;
            }

            if (this.ComboBox1.SelectedIndex == 8)
            {
                configuration(swModel);
            }

            if (this.ComboBox1.SelectedIndex == 9)
            {
                colorDetails(swModel);
            }

            if (this.ComboBox1.SelectedIndex == 10)
            {
                scaleInfo(swModel);
            }
        }