Ejemplo n.º 1
0
        /// <summary>
        /// Find the SW attribute that contains the URDF configuration serialized string
        /// </summary>
        /// <param name="model">ModelDoc model to load URDF configuration from</param>
        /// <param name="version">Output parameter of the serialization version</param>
        /// <returns>Serialized data string</returns>
        private static string GetConfigTreeData(ModelDoc2 model, out double version)
        {
            string data = "";

            version = 0.0;

            // Check for most recent serialization version
            SolidWorks.Interop.sldworks.Attribute swAtt =
                FindSWSaveAttribute(model, UrdfConfigurationSwAttributeName);

            // If not found, check for an older version
            if (swAtt == null)
            {
                swAtt = CheckForOldAttributes(model);
            }

            if (swAtt != null)
            {
                Parameter param = swAtt.GetParameter("data");
                data = param.GetStringValue();
                logger.Info("URDF Configuration found\n" + data);

                param   = swAtt.GetParameter("exporterVersion");
                version = param.GetDoubleValue();
            }

            return(data);
        }
Ejemplo n.º 2
0
        CreateSWSaveAttribute(SldWorks swApp, ModelDoc2 model, string name)
        {
            SolidWorks.Interop.sldworks.Attribute existingAttribute =
                FindSWSaveAttribute(model, name);
            if (existingAttribute != null)
            {
                return(existingAttribute);
            }

            int ConfigurationOptions = (int)swInConfigurationOpts_e.swAllConfiguration;

            int          Options = 0;
            AttributeDef saveConfigurationAttributeDef;

            saveConfigurationAttributeDef = swApp.DefineAttribute(URDF_CONFIGURATION_SW_ATTRIBUTE_NAME);

            saveConfigurationAttributeDef.AddParameter(
                "data", (int)swParamType_e.swParamTypeString, 0, Options);
            saveConfigurationAttributeDef.AddParameter(
                "name", (int)swParamType_e.swParamTypeString, 0, Options);
            saveConfigurationAttributeDef.AddParameter(
                "date", (int)swParamType_e.swParamTypeString, 0, Options);
            saveConfigurationAttributeDef.AddParameter(
                "exporterVersion", (int)swParamType_e.swParamTypeDouble, SERIALIZATION_VERSION, Options);
            saveConfigurationAttributeDef.Register();

            SolidWorks.Interop.sldworks.Attribute saveExporterAttribute =
                saveConfigurationAttributeDef.CreateInstance5(
                    model, null, URDF_CONFIGURATION_SW_ATTRIBUTE_NAME, Options, ConfigurationOptions);
            return(saveExporterAttribute);
        }
Ejemplo n.º 3
0
        private static Parameter eAttributListeLgProfils(this ModelDoc2 mdl)
        {
            if (AttDef.IsNull())
            {
                AttDef = App.Sw.DefineAttribute(ATTRIBUT_NOM);
                AttDef.AddParameter(ATTRIBUT_PARAM, (int)swParamType_e.swParamTypeString, 0, 0);
                AttDef.Register();
            }

            // Recherche de l'attribut dans la piece
            SolidWorks.Interop.sldworks.Attribute Att = null;
            Parameter P = null;
            Feature   F = mdl.eChercherFonction(f => { return(f.Name == ATTRIBUT_NOM); });

            if (F.IsRef())
            {
                Att = F.GetSpecificFeature2();

                P = (Parameter)Att.GetParameter(ATTRIBUT_PARAM);

                if (P.IsNull())
                {
                    Att.Delete(false);
                    Att = null;
                }
            }

            if (Att.IsNull())
            {
                Att = AttDef.CreateInstance5(mdl, null, ATTRIBUT_NOM, 1, (int)swInConfigurationOpts_e.swAllConfiguration);
                P   = (Parameter)Att.GetParameter(ATTRIBUT_PARAM);
            }

            return(P);
        }
        private SolidWorks.Interop.sldworks.Attribute createSWSaveAttribute(string name)
        {
            int Options = 0;

            if (saveConfigurationAttributeDef == null)
            {
                saveConfigurationAttributeDef = swApp.DefineAttribute("URDF Export Configuration");

                saveConfigurationAttributeDef.AddParameter("data", (int)swParamType_e.swParamTypeString, 0, Options);
                saveConfigurationAttributeDef.AddParameter("name", (int)swParamType_e.swParamTypeString, 0, Options);
                saveConfigurationAttributeDef.AddParameter("date", (int)swParamType_e.swParamTypeString, 0, Options);
                saveConfigurationAttributeDef.AddParameter("exporterVersion", (int)swParamType_e.swParamTypeDouble, 1.0, Options);
                saveConfigurationAttributeDef.Register();
            }

            int       ConfigurationOptions = (int)swInConfigurationOpts_e.swAllConfiguration;
            ModelDoc2 modeldoc             = swApp.ActiveDoc;

            Object[] objects = modeldoc.FeatureManager.GetFeatures(true);
            foreach (Object obj in objects)
            {
                Feature feat = (Feature)obj;
                string  t    = feat.GetTypeName2();
                if (feat.GetTypeName2() == "Attribute")
                {
                    SolidWorks.Interop.sldworks.Attribute att = (SolidWorks.Interop.sldworks.Attribute)feat.GetSpecificFeature2();
                    if (att.GetName() == name)
                    {
                        return(att);
                    }
                }
            }
            SolidWorks.Interop.sldworks.Attribute saveExporterAttribute = saveConfigurationAttributeDef.CreateInstance5(ActiveSWModel, null, "URDF Export Configuration", Options, ConfigurationOptions);
            return(saveExporterAttribute);
        }
        private SolidWorks.Interop.sldworks.Attribute CreateSWSaveAttribute(ISldWorks iSwApp, string name)
        {
            int       Options = 0;
            int       ConfigurationOptions = (int)swInConfigurationOpts_e.swAllConfiguration;
            ModelDoc2 ActiveSWModel        = iSwApp.ActiveDoc;

            Object[] objects = ActiveSWModel.FeatureManager.GetFeatures(true);
            foreach (Object obj in objects)
            {
                Feature feat = (Feature)obj;
                string  t    = feat.GetTypeName2();
                if (feat.GetTypeName2() == "Attribute")
                {
                    SolidWorks.Interop.sldworks.Attribute att =
                        (SolidWorks.Interop.sldworks.Attribute)feat.GetSpecificFeature2();
                    if (att.GetName() == name)
                    {
                        return(att);
                    }
                }
            }

            SolidWorks.Interop.sldworks.Attribute saveExporterAttribute =
                saveConfigurationAttributeDef.CreateInstance5(ActiveSWModel, null,
                                                              Serialization.URDF_CONFIGURATION_SW_ATTRIBUTE_NAME, Options, ConfigurationOptions);
            return(saveExporterAttribute);
        }
Ejemplo n.º 6
0
        private URDFExporter loadConfigFile()
        {
            ModelDoc2 modeldoc = iSwApp.ActiveDoc;


            Object[] objects = modeldoc.FeatureManager.GetFeatures(true);
            string   data    = "";

            foreach (Object obj in objects)
            {
                Feature feat = (Feature)obj;
                string  t    = feat.GetTypeName2();
                if (feat.GetTypeName2() == "Attribute")
                {
                    SolidWorks.Interop.sldworks.Attribute att = (SolidWorks.Interop.sldworks.Attribute)feat.GetSpecificFeature2();
                    if (att.GetName() == "URDF Export Configuration")
                    {
                        Parameter param = att.GetParameter("data");
                        data = param.GetStringValue();
                    }
                }
            }
            if (!data.Equals(""))
            {
                URDFExporter Exporter;

                XmlSerializer serializer = new XmlSerializer(typeof(URDFExporter));
                XmlTextReader textReader = new XmlTextReader(new StringReader(data));
                Exporter = (URDFExporter)serializer.Deserialize(textReader);
                textReader.Close();

                return(Exporter);
            }
            return(null);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Find the SW attribute that contains the URDF configuration serialized string
        /// </summary>
        /// <param name="model">ModelDoc model to load URDF configuration from</param>
        /// <param name="version">Output parameter of the serialization version</param>
        /// <returns>Serialized data string</returns>
        private static string GetConfigTreeData(ModelDoc2 model, out double version)
        {
            object[] objects = model.FeatureManager.GetFeatures(true);
            string   data    = "";

            version = 0.0;

            // Check for most recent serialization version
            SolidWorks.Interop.sldworks.Attribute swAtt =
                FindSWSaveAttribute(model, URDF_CONFIGURATION_SW_ATTRIBUTE_NAME);

            // If not found, check for an older version
            if (swAtt == null)
            {
                swAtt = CheckForOldAttributes(model);
            }

            if (swAtt != null)
            {
                Parameter param = swAtt.GetParameter("data");
                data = param.GetStringValue();
                logger.Info("URDF Configuration found\n" + data);

                param   = swAtt.GetParameter("exporterVersion");
                version = param.GetDoubleValue();
            }

            return(data);
        }
Ejemplo n.º 8
0
        CreateSWSaveAttribute(SldWorks swApp, ModelDoc2 model, string name)
        {
            SolidWorks.Interop.sldworks.Attribute existingAttribute =
                FindSWSaveAttribute(model, name);
            if (existingAttribute != null)
            {
                return(existingAttribute);
            }

            int ConfigurationOptions = (int)swInConfigurationOpts_e.swAllConfiguration;

            int          Options = 0;
            AttributeDef saveConfigurationAttributeDef;

            saveConfigurationAttributeDef = swApp.DefineAttribute(UrdfConfigurationSwAttributeName);

            saveConfigurationAttributeDef.AddParameter(
                "data", (int)swParamType_e.swParamTypeString, 0, Options);
            saveConfigurationAttributeDef.AddParameter(
                "name", (int)swParamType_e.swParamTypeString, 0, Options);
            saveConfigurationAttributeDef.AddParameter(
                "date", (int)swParamType_e.swParamTypeString, 0, Options);
            saveConfigurationAttributeDef.AddParameter(
                "exporterVersion", (int)swParamType_e.swParamTypeDouble, SerializationVersion, Options);
            saveConfigurationAttributeDef.Register();

            SolidWorks.Interop.sldworks.Attribute saveExporterAttribute =
                saveConfigurationAttributeDef.CreateInstance5(
                    model, null, UrdfConfigurationSwAttributeName, Options, ConfigurationOptions);
            return(saveExporterAttribute);
        }
Ejemplo n.º 9
0
        public void saveConfigTree(ModelDoc2 model, LinkNode BaseNode, bool warnUser)
        {
            Object[]  objects = model.FeatureManager.GetFeatures(true);
            string    oldData = "";
            Parameter param;

            foreach (Object obj in objects)
            {
                Feature feat = (Feature)obj;
                string  t    = feat.GetTypeName2();
                if (feat.GetTypeName2() == "Attribute")
                {
                    SolidWorks.Interop.sldworks.Attribute att = (SolidWorks.Interop.sldworks.Attribute)feat.GetSpecificFeature2();
                    if (att.GetName() == "URDF Export Configuration")
                    {
                        param   = att.GetParameter("data");
                        oldData = param.GetStringValue();
                    }
                }
            }
            //moveComponentsToFolder((LinkNode)tree.Nodes[0]);
            retrieveSWComponentPIDs(BaseNode);
            SerialNode    sNode = new SerialNode(BaseNode);
            StringWriter  stringWriter;
            XmlSerializer serializer = new XmlSerializer(typeof(SerialNode));

            stringWriter = new StringWriter();
            serializer.Serialize(stringWriter, sNode);
            stringWriter.Flush();
            stringWriter.Close();

            string newData = stringWriter.ToString();

            if (oldData != newData)
            {
                if (!warnUser ||
                    (warnUser &&
                     MessageBox.Show("The configuration has changed, would you like to save?", "Save Export Configuration",
                                     MessageBoxButtons.YesNo) == DialogResult.Yes))
                {
                    int ConfigurationOptions = (int)swInConfigurationOpts_e.swAllConfiguration;
                    SolidWorks.Interop.sldworks.Attribute saveExporterAttribute = createSWSaveAttribute("URDF Export Configuration");
                    param = saveExporterAttribute.GetParameter("data");
                    param.SetStringValue2(stringWriter.ToString(), ConfigurationOptions, "");
                    param = saveExporterAttribute.GetParameter("name");
                    param.SetStringValue2("config1", ConfigurationOptions, "");
                    param = saveExporterAttribute.GetParameter("date");
                    param.SetStringValue2(DateTime.Now.ToString(), ConfigurationOptions, "");
                    param = saveExporterAttribute.GetParameter("exporterVersion");
                    param.SetStringValue2("1.1", ConfigurationOptions, "");
                }
            }
        }
Ejemplo n.º 10
0
 /// <summary>
 /// For the future, if serialization is upgraded again, this might look for several versions
 /// </summary>
 /// <param name="model">ModelDoc to look through</param>
 /// <returns>SolidWorks Attribute with older serialization schemes if found, otherwise null.</returns>
 private static SolidWorks.Interop.sldworks.Attribute CheckForOldAttributes(ModelDoc2 model)
 {
     foreach (string configurationName in PREVIOUS_URDF_CONFIGURATION_NAMES)
     {
         SolidWorks.Interop.sldworks.Attribute swAtt = FindSWSaveAttribute(model, configurationName);
         if (swAtt != null)
         {
             return(swAtt);
         }
     }
     return(null);
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Saves a string of data to the SWModelDoc
        /// </summary>
        /// <param name="swApp">SolidWorks Application</param>
        /// <param name="model">ModelDoc model to save data string to</param>
        /// <param name="data">string to save</param>
        /// <param name="attributeName">Name of attribute to save to</param>
        private static void SaveDataToModelDoc(SldWorks swApp, ModelDoc2 model,
                                               string data, string archivedData = null)
        {
            int ConfigurationOptions = (int)swInConfigurationOpts_e.swAllConfiguration;

            SolidWorks.Interop.sldworks.Attribute saveExporterAttribute =
                CreateSWSaveAttribute(swApp, model, URDF_CONFIGURATION_SW_ATTRIBUTE_NAME);

            Parameter param = saveExporterAttribute.GetParameter("data");

            param.SetStringValue2(data, ConfigurationOptions, "");
            param = saveExporterAttribute.GetParameter("name");
            param.SetStringValue2("config1", ConfigurationOptions, "");
            param = saveExporterAttribute.GetParameter("date");
            param.SetStringValue2(DateTime.Now.ToString(), ConfigurationOptions, "");
            param = saveExporterAttribute.GetParameter("exporterVersion");
            param.SetDoubleValue2(SERIALIZATION_VERSION, ConfigurationOptions, "");
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Saves a string of data to the SWModelDoc
        /// </summary>
        /// <param name="swApp">SolidWorks Application</param>
        /// <param name="model">ModelDoc model to save data string to</param>
        /// <param name="data">string to save</param>
        /// <param name="attributeName">Name of attribute to save to</param>
        private static void SaveDataToModelDoc(SldWorks swApp, ModelDoc2 model,
                                               string data)
        {
            int ConfigurationOptions = (int)swInConfigurationOpts_e.swAllConfiguration;

            SolidWorks.Interop.sldworks.Attribute saveExporterAttribute =
                CreateSWSaveAttribute(swApp, model, UrdfConfigurationSwAttributeName);

            Parameter param = saveExporterAttribute.GetParameter("data");

            param.SetStringValue2(data, ConfigurationOptions, "");
            param = saveExporterAttribute.GetParameter("name");
            param.SetStringValue2("config1", ConfigurationOptions, "");
            param = saveExporterAttribute.GetParameter("date");
            param.SetStringValue2(DateTime.Now.ToString(), ConfigurationOptions, "");
            param = saveExporterAttribute.GetParameter("exporterVersion");
            param.SetDoubleValue2(SerializationVersion, ConfigurationOptions, "");
        }
Ejemplo n.º 13
0
 /// <summary>
 ///  Iterates through features in ModelDoc to find a feature of the correct name
 /// </summary>
 /// <param name="model">ModelDoc of features to iterate through</param>
 /// <param name="featName">The name of the feature to get</param>
 /// <returns>The SolidWorks Feature if found, null otherwise</returns>
 private static Feature GetFeatureAttributeByName(ModelDoc2 model, string featName)
 {
     Object[] objects = model.FeatureManager.GetFeatures(true);
     foreach (Object obj in objects)
     {
         Feature feature = (Feature)obj;
         if (feature.GetTypeName2() == "Attribute")
         {
             SolidWorks.Interop.sldworks.Attribute att =
                 (SolidWorks.Interop.sldworks.Attribute)feature.GetSpecificFeature2();
             if (att.GetName() == featName)
             {
                 return(feature);
             }
         }
     }
     return(null);
 }
Ejemplo n.º 14
0
        // Calls the Exporter loadConfigTree method and then populates the tree with the loaded config
        public void loadConfigTree()
        {
            Object[] objects = ActiveSWModel.FeatureManager.GetFeatures(true);
            string   data    = "";

            foreach (Object obj in objects)
            {
                Feature feat = (Feature)obj;
                string  t    = feat.GetTypeName2();
                if (feat.GetTypeName2() == "Attribute")
                {
                    SolidWorks.Interop.sldworks.Attribute att = (SolidWorks.Interop.sldworks.Attribute)feat.GetSpecificFeature2();
                    if (att.GetName() == "URDF Export Configuration")
                    {
                        Parameter param = att.GetParameter("data");
                        data = param.GetStringValue();
                    }
                }
            }
            LinkNode basenode = null;

            if (!data.Equals(""))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(SerialNode));
                XmlTextReader textReader = new XmlTextReader(new StringReader(data));
                SerialNode    node       = (SerialNode)serializer.Deserialize(textReader);
                basenode = new LinkNode(node);
                Common.loadSWComponents(ActiveSWModel, basenode);
                textReader.Close();
            }

            if (basenode == null)
            {
                basenode = createEmptyNode(null);
            }
            addDocMenu(basenode);

            tree.Nodes.Clear();
            tree.Nodes.Add(basenode);
            tree.ExpandAll();
            tree.SelectedNode = tree.Nodes[0];
        }
Ejemplo n.º 15
0
        public void StoreToSelection(SelectionMgr swSelMgr, ref AttributeDef mdefattr_chbody)//, ref AttributeDef defattr_chconveyor)
        {
            System.Windows.Forms.MessageBox.Show("StoreToSelection()");

            // If user pressed OK, apply settings to all selected parts (i.e. ChBody in C::E):
            for (int isel = 1; isel <= swSelMgr.GetSelectedObjectCount2(-1); isel++)
            {
                if ((swSelectType_e)swSelMgr.GetSelectedObjectType3(isel, -1) == swSelectType_e.swSelCOMPONENTS)
                {
                    Component2 swPart      = (Component2)swSelMgr.GetSelectedObject6(isel, -1);
                    ModelDoc2  swPartModel = (ModelDoc2)swPart.GetModelDoc();

                    // fetch SW attribute with Chrono parameters for ChBody
                    SolidWorks.Interop.sldworks.Attribute myattr = (SolidWorks.Interop.sldworks.Attribute)swPart.FindAttribute(mdefattr_chbody, 0);
                    if (myattr == null)
                    {
                        // if not already added to part, create and attach it
                        myattr = mdefattr_chbody.CreateInstance5(swPartModel, swPart, "Chrono ChBody data", 0, (int)swInConfigurationOpts_e.swThisConfiguration);
                        swPartModel.ForceRebuild3(false); // needed?
                        if (myattr == null)
                        {
                            System.Windows.Forms.MessageBox.Show("myattr null in setting!!");
                        }
                    }

                    ((Parameter)myattr.GetParameter("collision_on")).SetDoubleValue2(
                        Convert.ToDouble(m_collide), (int)swInConfigurationOpts_e.swThisConfiguration, "");

                    ((Parameter)myattr.GetParameter("friction")).SetDoubleValue2(
                        m_friction, (int)swInConfigurationOpts_e.swThisConfiguration, "");

                    ((Parameter)myattr.GetParameter("rolling_friction")).SetDoubleValue2(
                        m_rolling_friction, (int)swInConfigurationOpts_e.swThisConfiguration, "");

                    ((Parameter)myattr.GetParameter("spinning_friction")).SetDoubleValue2(
                        m_spinning_friction, (int)swInConfigurationOpts_e.swThisConfiguration, "");

                    ((Parameter)myattr.GetParameter("restitution")).SetDoubleValue2(
                        m_restitution, (int)swInConfigurationOpts_e.swThisConfiguration, "");

                    ((Parameter)myattr.GetParameter("collision_margin")).SetDoubleValue2(
                        m_collision_margin, (int)swInConfigurationOpts_e.swThisConfiguration, "");

                    ((Parameter)myattr.GetParameter("collision_envelope")).SetDoubleValue2(
                        m_collision_envelope, (int)swInConfigurationOpts_e.swThisConfiguration, "");

                    ((Parameter)myattr.GetParameter("collision_family")).SetDoubleValue2(
                        (double)m_collision_family, (int)swInConfigurationOpts_e.swThisConfiguration, "");

                    /*
                     * // fetch SW attribute with Chrono parameters for ChConveyor
                     * SolidWorks.Interop.sldworks.Attribute myattr_conveyor = (SolidWorks.Interop.sldworks.Attribute)swPart.FindAttribute(defattr_chconveyor, 0);
                     * if (myattr_conveyor == null)
                     * {
                     *  // if not already added to part, create and attach it
                     *  myattr_conveyor = defattr_chconveyor.CreateInstance5(swPartModel, swPart, "Chrono ChConveyor data", 0, (int)swInConfigurationOpts_e.swThisConfiguration);
                     *  if (myattr_conveyor == null)
                     *      System.Windows.Forms.MessageBox.Show("myattr null in setting!!");
                     * }
                     *
                     * ((Parameter)myattr_conveyor.GetParameter("conveyor_speed")).SetDoubleValue2(
                     *            m_conveyor_speed, (int)swInConfigurationOpts_e.swThisConfiguration, "");
                     */
                }
            }
        }
Ejemplo n.º 16
0
        public void UpdateFromSelection(SelectionMgr swSelMgr, ref AttributeDef mdefattr_chbody)//, ref AttributeDef defattr_chconveyor)
        {
            // Fetch current properties from the selected part(s) (i.e. ChBody in C::E)
            for (int isel = 1; isel <= swSelMgr.GetSelectedObjectCount2(-1); isel++)
            {
                if ((swSelectType_e)swSelMgr.GetSelectedObjectType3(isel, -1) == swSelectType_e.swSelCOMPONENTS)
                {
                    Component2 swPart      = (Component2)swSelMgr.GetSelectedObject6(isel, -1);
                    ModelDoc2  swPartModel = (ModelDoc2)swPart.GetModelDoc();

                    // fetch SW attribute with Chrono parameters for ChBody
                    SolidWorks.Interop.sldworks.Attribute myattr = (SolidWorks.Interop.sldworks.Attribute)swPart.FindAttribute(mdefattr_chbody, 0);
                    if (myattr == null)
                    {
                        // if not already added to part, create and attach it
                        myattr = mdefattr_chbody.CreateInstance5(swPartModel, swPart, "Chrono::ChBody_data", 0, (int)swInConfigurationOpts_e.swAllConfiguration);

                        if (myattr.GetEntityState((int)swAssociatedEntityStates_e.swIsEntityInvalid))
                        {
                            System.Windows.Forms.MessageBox.Show("swIsEntityInvalid!");
                        }
                        if (myattr.GetEntityState((int)swAssociatedEntityStates_e.swIsEntitySuppressed))
                        {
                            System.Windows.Forms.MessageBox.Show("swIsEntitySuppressed!");
                        }
                        if (myattr.GetEntityState((int)swAssociatedEntityStates_e.swIsEntityAmbiguous))
                        {
                            System.Windows.Forms.MessageBox.Show("swIsEntityAmbiguous!");
                        }
                        if (myattr.GetEntityState((int)swAssociatedEntityStates_e.swIsEntityDeleted))
                        {
                            System.Windows.Forms.MessageBox.Show("swIsEntityDeleted!");
                        }

                        swPartModel.ForceRebuild3(false); // needed?
                    }

                    Set_collision_on(Convert.ToBoolean(((Parameter)myattr.GetParameter(
                                                            "collision_on")).GetDoubleValue()));
                    Set_friction(((Parameter)myattr.GetParameter(
                                      "friction")).GetDoubleValue());
                    Set_rolling_friction(((Parameter)myattr.GetParameter(
                                              "rolling_friction")).GetDoubleValue());
                    Set_spinning_friction(((Parameter)myattr.GetParameter(
                                               "spinning_friction")).GetDoubleValue());
                    Set_restitution(((Parameter)myattr.GetParameter(
                                         "restitution")).GetDoubleValue());
                    Set_collision_envelope(((Parameter)myattr.GetParameter(
                                                "collision_envelope")).GetDoubleValue());
                    Set_collision_margin(((Parameter)myattr.GetParameter(
                                              "collision_margin")).GetDoubleValue());
                    Set_collision_family((int)((Parameter)myattr.GetParameter(
                                                   "collision_family")).GetDoubleValue());



                    // fetch SW attribute with Chrono parameters for ChConveyor

                    /*
                     * SolidWorks.Interop.sldworks.Attribute myattr_conv = (SolidWorks.Interop.sldworks.Attribute)swPart.FindAttribute(defattr_chconveyor, 0);
                     * if (myattr_conv == null)
                     * {
                     *  // if not already added to part, create and attach it
                     *  //myattr_conv = defattr_chconveyor.CreateInstance5(swPartModel, swPart, "Chrono::ChConveyor_data", 0, (int)swInConfigurationOpts_e.swThisConfiguration);
                     * }
                     */
                    /*
                     * // fetch SW attribute with Chrono parameters for ChConveyor (if any!)
                     * SolidWorks.Interop.sldworks.Attribute myattr_conveyor = (SolidWorks.Interop.sldworks.Attribute)swPart.FindAttribute(defattr_chconveyor, 0);
                     * if (myattr_conveyor != null)
                     * {
                     *  show_conveyor_params = true;
                     *
                     *  Set_conveyor_speed(((Parameter)myattr_conveyor.GetParameter(
                     *                  "conveyor_speed")).GetDoubleValue());
                     * }
                     */
                }
            }
        }
Ejemplo n.º 17
0
        public void UpdateFromSelection(SelectionMgr swSelMgr, ref AttributeDef mdefattr_chbody)//, ref AttributeDef defattr_chconveyor)
        {
            // Fetch current properties from the selected part(s) (i.e. ChBody in C::E)
            for (int isel = 1; isel <= swSelMgr.GetSelectedObjectCount2(-1); isel++)
            {
                if ((swSelectType_e)swSelMgr.GetSelectedObjectType3(isel, -1) == swSelectType_e.swSelCOMPONENTS)
                {
                    //Component2 swPart = (Component2)swSelMgr.GetSelectedObject6(isel, -1);
                    Component2 swPart      = swSelMgr.GetSelectedObjectsComponent3(isel, -1);
                    ModelDoc2  swPartModel = (ModelDoc2)swPart.GetModelDoc2();
                    Component2 swPartcorr  = swPartModel.Extension.GetCorresponding(swPart); // ***TODO*** for instanced parts? does not work...
                    swPartcorr = swPart;                                                     // ***TODO***

                    if (swPartModel.GetType() == (int)swDocumentTypes_e.swDocASSEMBLY)
                    {
                        if (swPart.Solving == (int)swComponentSolvingOption_e.swComponentFlexibleSolving)
                        {
                            System.Windows.Forms.MessageBox.Show("Fexible assemblies not supported as ChBody (set as Rigid?)");
                            return;
                        }
                        if (swPart.Solving == (int)swComponentSolvingOption_e.swComponentRigidSolving)
                        {
                            System.Windows.Forms.MessageBox.Show("Setting props to rigid assembly as ChBody");
                            AssemblyDoc swAssemblyDoc = (AssemblyDoc)swPartModel;
                            swPart.Select(false);
                            swAssemblyDoc.EditAssembly();
                            swAssemblyDoc.EditRebuild();
                            //return;
                        }
                    }

                    // fetch SW attribute with Chrono parameters for ChBody
                    SolidWorks.Interop.sldworks.Attribute myattr = null;
                    if (swPartcorr != null)
                    {
                        myattr = (SolidWorks.Interop.sldworks.Attribute)swPart.FindAttribute(mdefattr_chbody, 0);
                    }
                    if (myattr == null)
                    {
                        // if not already added to part, create and attach it
                        //System.Windows.Forms.MessageBox.Show("Create data");
                        myattr = mdefattr_chbody.CreateInstance5(swPartModel, swPartcorr, "Chrono::ChBody_data", 0, (int)swInConfigurationOpts_e.swAllConfiguration);

                        swPartModel.ForceRebuild3(false); // needed, but does not work...
                        //swPartModel.Rebuild((int)swRebuildOptions_e.swRebuildAll); // needed but does not work...

                        if (myattr.GetEntityState((int)swAssociatedEntityStates_e.swIsEntityInvalid))
                        {
                            System.Windows.Forms.MessageBox.Show("swIsEntityInvalid!");
                        }
                        if (myattr.GetEntityState((int)swAssociatedEntityStates_e.swIsEntitySuppressed))
                        {
                            System.Windows.Forms.MessageBox.Show("swIsEntitySuppressed!");
                        }
                        if (myattr.GetEntityState((int)swAssociatedEntityStates_e.swIsEntityAmbiguous))
                        {
                            System.Windows.Forms.MessageBox.Show("swIsEntityAmbiguous!");
                        }
                        if (myattr.GetEntityState((int)swAssociatedEntityStates_e.swIsEntityDeleted))
                        {
                            System.Windows.Forms.MessageBox.Show("swIsEntityDeleted!");
                        }
                    }

                    Set_collision_on(Convert.ToBoolean(((Parameter)myattr.GetParameter(
                                                            "collision_on")).GetDoubleValue()));
                    Set_friction(((Parameter)myattr.GetParameter(
                                      "friction")).GetDoubleValue());
                    Set_rolling_friction(((Parameter)myattr.GetParameter(
                                              "rolling_friction")).GetDoubleValue());
                    Set_spinning_friction(((Parameter)myattr.GetParameter(
                                               "spinning_friction")).GetDoubleValue());
                    Set_restitution(((Parameter)myattr.GetParameter(
                                         "restitution")).GetDoubleValue());
                    Set_collision_envelope(((Parameter)myattr.GetParameter(
                                                "collision_envelope")).GetDoubleValue());
                    Set_collision_margin(((Parameter)myattr.GetParameter(
                                              "collision_margin")).GetDoubleValue());
                    Set_collision_family((int)((Parameter)myattr.GetParameter(
                                                   "collision_family")).GetDoubleValue());



                    // fetch SW attribute with Chrono parameters for ChConveyor

                    /*
                     * SolidWorks.Interop.sldworks.Attribute myattr_conv = (SolidWorks.Interop.sldworks.Attribute)swPart.FindAttribute(defattr_chconveyor, 0);
                     * if (myattr_conv == null)
                     * {
                     *  // if not already added to part, create and attach it
                     *  //myattr_conv = defattr_chconveyor.CreateInstance5(swPartModel, swPart, "Chrono::ChConveyor_data", 0, (int)swInConfigurationOpts_e.swThisConfiguration);
                     * }
                     */
                    /*
                     * // fetch SW attribute with Chrono parameters for ChConveyor (if any!)
                     * SolidWorks.Interop.sldworks.Attribute myattr_conveyor = (SolidWorks.Interop.sldworks.Attribute)swPart.FindAttribute(defattr_chconveyor, 0);
                     * if (myattr_conveyor != null)
                     * {
                     *  show_conveyor_params = true;
                     *
                     *  Set_conveyor_speed(((Parameter)myattr_conveyor.GetParameter(
                     *                  "conveyor_speed")).GetDoubleValue());
                     * }
                     */
                }
            }
        }