コード例 #1
0
    //CUSTOMIZATION_ORIGINAL_DIGEST:0374A0D7CACB8B143CF92AFB39BD17D547AE51CC
    //CUSTOMIZATION_BEGIN

    // Config SAGA

    /// <summary>
    /// Возвращает атрибут другого объекта для определения атрибута с типом "ссылка на другой атрибут"
    /// </summary>
    /// <param name="obj">Объект, чей атрибут вычисляем</param>
    /// <param name="attr">Определение атрибута-ссылки</param>
    /// <returns>Найденный атрибут другого объекта</returns>
    /// <remarks>Этот метод может вызываться несколько раз в ходе редактирования карточки объекта.
    /// Для корректной работы необходимо, чтобы прежде чем вернуть атрибут, объект-владелец атрибута
    /// должен быть проверен на наличие в списке obj.BoundObjects и взят оттуда, если там уже есть такой.
    /// Код ядра проделывает эту операцию автоматически по завершении работы этой функции</remarks>
    public override EntityAttribute ResolveAttribute(InfoObject obj, AttributeDef attr)
    {
        NamedValue      nval     = Service.GetNamedValue(@"SAGA_confg\FactBlock_Types\tfb_Header");
        EntityAttribute result   = null;
        var             FactAddr = obj.GetInfoObject("FactAddr");

        if (FactAddr != null)
        {
            InfoObject realFactAddr = null;
            if (FactAddr.Template.NameKey == "FactBlock")
            {
                // одиночный блок фактических данных
                if (FactAddr.GetValue <NamedValue>("BlockType") == nval)
                {
                    realFactAddr = FactAddr;
                }
            }
            else
            {
                // ссылка на блок метаданных типа "Коллекция"
                realFactAddr = FactAddr.Children.Where(o => o.GetValue <NamedValue>("BlockType") == nval).FirstOrDefault();
            }
            if (realFactAddr != null)
            {
                result = realFactAddr.GetAttribute("TextData");
            }
        }
        return(result);
    }
コード例 #2
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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
 public AttributeInstance(AttributeDef attribute, Flow scope)
 {
     this.Id       = SunStone.Util.SequentialGuid.NewGuid();
     ValueText     = attribute.InitialValue;
     AttributeId   = attribute.Id;
     AttributeName = attribute.Name;
     Scope         = scope;
 }
コード例 #5
0
    public bool ConnectToSW(object ThisSW, int Cookie)
    {
        //System.Windows.Forms.MessageBox.Show("Add-in: ConnectToSW");
        try
        {
            mSWApplication = (SldWorks)ThisSW;
            mSWCookie = Cookie;
            bool result = mSWApplication.SetAddinCallbackInfo(0, this, Cookie);

            // Attributes register
            

            defattr_chbody = (AttributeDef)mSWApplication.DefineAttribute("chrono::ChBody");
            defattr_chbody.AddParameter("friction",             (int)swParamType_e.swParamTypeDouble, 0.6, 0);
            defattr_chbody.AddParameter("rolling_friction",     (int)swParamType_e.swParamTypeDouble, 0, 0);
            defattr_chbody.AddParameter("spinning_friction",    (int)swParamType_e.swParamTypeDouble, 0, 0);
            defattr_chbody.AddParameter("restitution",          (int)swParamType_e.swParamTypeDouble, 0, 0);
            defattr_chbody.AddParameter("collision_on",         (int)swParamType_e.swParamTypeDouble, 1, 0);
            defattr_chbody.AddParameter("collision_margin",     (int)swParamType_e.swParamTypeDouble, 0.01, 0);
            defattr_chbody.AddParameter("collision_envelope",   (int)swParamType_e.swParamTypeDouble, 0.03, 0);
            defattr_chbody.AddParameter("collision_family",     (int)swParamType_e.swParamTypeDouble, 0, 0);
            defattr_chbody.Register();
            /*
            defattr_chconveyor = (AttributeDef)moSWApplication.DefineAttribute("chrono::ChConveyor");
            defattr_chconveyor.AddParameter("conveyor_speed",   (int)swParamType_e.swParamTypeDouble, 1.0, 0);
            defattr_chconveyor.Register();
            */

            // Register the taskpane
            this.UISetup();

            // Event register: here is an example of how to do...
            SldWorks moSWApplication = (SldWorks)mSWApplication;
            moSWApplication.ActiveDocChangeNotify += new DSldWorksEvents_ActiveDocChangeNotifyEventHandler(test_event_ActiveDocChangeNotify);
            moSWApplication.ActiveModelDocChangeNotify += new DSldWorksEvents_ActiveModelDocChangeNotifyEventHandler(test_event_ActiveModelDocChangeNotify);
        }
        catch (Exception ex)
        {
            System.Windows.Forms.MessageBox.Show("ConnectToSW failed! " + ex.Message);
        }

        return true;
 
    }
コード例 #6
0
        public bool ConnectToSW(object ThisSW, int Cookie)
        {
            //System.Windows.Forms.MessageBox.Show("Add-in: ConnectToSW");
            try
            {
            mSWApplication = (SldWorks)ThisSW;
            mSWCookie = Cookie;
            bool result = mSWApplication.SetAddinCallbackInfo(0, this, Cookie);

            // Attributes register

            defattr_chbody = (AttributeDef)mSWApplication.DefineAttribute("chrono::ChBody");
            defattr_chbody.AddParameter("friction",             (int)swParamType_e.swParamTypeDouble, 0.6, 0);
            defattr_chbody.AddParameter("rolling_friction",     (int)swParamType_e.swParamTypeDouble, 0, 0);
            defattr_chbody.AddParameter("spinning_friction",    (int)swParamType_e.swParamTypeDouble, 0, 0);
            defattr_chbody.AddParameter("restitution",          (int)swParamType_e.swParamTypeDouble, 0, 0);
            defattr_chbody.AddParameter("collision_on",         (int)swParamType_e.swParamTypeDouble, 1, 0);
            defattr_chbody.AddParameter("collision_margin",     (int)swParamType_e.swParamTypeDouble, 0.01, 0);
            defattr_chbody.AddParameter("collision_envelope",   (int)swParamType_e.swParamTypeDouble, 0.03, 0);
            defattr_chbody.AddParameter("collision_family",     (int)swParamType_e.swParamTypeDouble, 0, 0);
            defattr_chbody.Register();
            /*
            defattr_chconveyor = (AttributeDef)moSWApplication.DefineAttribute("chrono::ChConveyor");
            defattr_chconveyor.AddParameter("conveyor_speed",   (int)swParamType_e.swParamTypeDouble, 1.0, 0);
            defattr_chconveyor.Register();
            */

            // Register the taskpane
            this.UISetup();

            // Event register: here is an example of how to do...
            SldWorks moSWApplication = (SldWorks)mSWApplication;
            moSWApplication.ActiveDocChangeNotify += new DSldWorksEvents_ActiveDocChangeNotifyEventHandler(test_event_ActiveDocChangeNotify);
            moSWApplication.ActiveModelDocChangeNotify += new DSldWorksEvents_ActiveModelDocChangeNotifyEventHandler(test_event_ActiveModelDocChangeNotify);
            }
            catch (Exception ex)
            {
            System.Windows.Forms.MessageBox.Show("ConnectToSW failed! " + ex.Message);
            }

            return true;
        }
コード例 #7
0
        public void ParsesDefaults()
        {
            var defaultsDef = "def +flag1 -flag2 someVal:val;";
            var expected    = new AttributeDef[]
            {
                new AttributeDef("flag1", true),
                new AttributeDef("flag2", false),
                new AttributeDef("someVal", "val")
            };

            var parsed = RecordsParser.Defaults.Parse(defaultsDef).ToArray();

            Assert.AreEqual(expected.Length, parsed.Length);
            for (int i = 0; i < expected.Length; i++)
            {
                Assert.AreEqual(expected[i].Name, parsed[i].Name);
                Assert.AreEqual(expected[i].Type, parsed[i].Type);
                Assert.AreEqual(expected[i].Value, parsed[i].Value);
            }
        }
コード例 #8
0
        public void ParsesPrototype()
        {
            var defaultsDef = "proto myProto +flag1 -flag2 someVal:val;";
            var expected    = new AttributeDef[]
            {
                new AttributeDef("flag1", true),
                new AttributeDef("flag2", false),
                new AttributeDef("someVal", "val")
            };

            var parsed = RecordsParser.Prototype.Parse(defaultsDef);
            var attrs  = parsed.Attributes.ToArray();

            Assert.AreEqual("myProto", parsed.Name);
            Assert.AreEqual(expected.Length, attrs.Length);
            for (int i = 0; i < expected.Length; i++)
            {
                Assert.AreEqual(expected[i].Name, attrs[i].Name);
                Assert.AreEqual(expected[i].Type, attrs[i].Type);
                Assert.AreEqual(expected[i].Value, attrs[i].Value);
            }
        }
コード例 #9
0
        public AssemblyExportForm(ISldWorks iSwApp, LinkNode node)
        {
            InitializeComponent();
            swApp            = iSwApp;
            BaseNode         = node;
            ActiveSWModel    = swApp.ActiveDoc;
            Exporter         = new URDFExporter(iSwApp);
            AutoUpdatingForm = false;


            jointBoxes = new Control[] {
                textBox_joint_name, comboBox_axis, comboBox_joint_type,
                textBox_axis_x, textBox_axis_y, textBox_axis_z,
                textBox_joint_x, textBox_joint_y, textBox_joint_z, textBox_joint_pitch, textBox_joint_roll, textBox_joint_yaw,
                textBox_limit_lower, textBox_limit_upper, textBox_limit_effort, textBox_limit_velocity,
                textBox_damping, textBox_friction,
                textBox_calibration_falling, textBox_calibration_rising,
                textBox_soft_lower, textBox_soft_upper, textBox_k_position, textBox_k_velocity
            };
            linkBoxes = new Control[] {
                textBox_inertial_origin_x, textBox_inertial_origin_y, textBox_inertial_origin_z, textBox_inertial_origin_roll, textBox_inertial_origin_pitch, textBox_inertial_origin_yaw,
                textBox_visual_origin_x, textBox_visual_origin_y, textBox_visual_origin_z, textBox_visual_origin_roll, textBox_visual_origin_pitch, textBox_visual_origin_yaw,
                textBox_collision_origin_x, textBox_collision_origin_y, textBox_collision_origin_z, textBox_collision_origin_roll, textBox_collision_origin_pitch, textBox_collision_origin_yaw,
                textBox_ixx, textBox_ixy, textBox_ixz, textBox_iyy, textBox_iyz, textBox_izz,
                textBox_mass,
                domainUpDown_red, domainUpDown_green, domainUpDown_blue, domainUpDown_alpha,
                comboBox_materials,
                textBox_texture
            };

            saveConfigurationAttributeDef = iSwApp.DefineAttribute("URDF Export Configuration");
            int Options = 0;

            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();
        }
コード例 #10
0
ファイル: AssemblyExportForm.cs プロジェクト: chlai/sw2urdf
        public AssemblyExportForm(ISldWorks iSwApp, LinkNode node)
        {
            InitializeComponent();
            swApp = iSwApp;
            BaseNode = node;
            ActiveSWModel = swApp.ActiveDoc;
            Exporter = new URDFExporter(iSwApp);
            AutoUpdatingForm = false;


            jointBoxes = new Control[] {
                textBox_joint_name, comboBox_axis, comboBox_joint_type,
                textBox_axis_x, textBox_axis_y, textBox_axis_z,
                textBox_joint_x, textBox_joint_y, textBox_joint_z, textBox_joint_pitch, textBox_joint_roll, textBox_joint_yaw,
                textBox_limit_lower, textBox_limit_upper, textBox_limit_effort, textBox_limit_velocity,
                textBox_damping, textBox_friction,
                textBox_calibration_falling, textBox_calibration_rising,
                textBox_soft_lower, textBox_soft_upper, textBox_k_position, textBox_k_velocity
            };
            linkBoxes = new Control[] {
                textBox_inertial_origin_x, textBox_inertial_origin_y, textBox_inertial_origin_z, textBox_inertial_origin_roll, textBox_inertial_origin_pitch, textBox_inertial_origin_yaw,
                textBox_visual_origin_x, textBox_visual_origin_y, textBox_visual_origin_z, textBox_visual_origin_roll, textBox_visual_origin_pitch, textBox_visual_origin_yaw,
                textBox_collision_origin_x, textBox_collision_origin_y, textBox_collision_origin_z, textBox_collision_origin_roll, textBox_collision_origin_pitch, textBox_collision_origin_yaw,
                textBox_ixx, textBox_ixy, textBox_ixz, textBox_iyy, textBox_iyz, textBox_izz,
                textBox_mass, 
                domainUpDown_red, domainUpDown_green, domainUpDown_blue, domainUpDown_alpha,
                comboBox_materials,
                textBox_texture
            };

            saveConfigurationAttributeDef = iSwApp.DefineAttribute("URDF Export Configuration");
            int Options = 0;

            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();
        }
コード例 #11
0
        public void HelloWorld3()
        {
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.Load("Definitions\\HelloWorld3.xml");

            using (var unitWork = UnitOfWork.Start())
            {
                ProcessDefinitionCreationContext creationContext = new ProcessDefinitionCreationContext();
                ProcessDefinition processDefinition = creationContext.CreateProcessDefinition(xmlDocument);
                creationContext.ResolveReferences();

                AttributeDef evaluation = null, text = null;
                foreach (AttributeDef attribute in processDefinition.Attributes)
                {
                    if (attribute.Name == "evaluation result")
                    {
                        evaluation = attribute;
                    }
                    else if (attribute.Name == "the text attrib")
                    {
                        text = attribute;
                    }
                }

                Assert.IsNotNull(evaluation);
                Assert.IsNotNull(evaluation.SerializerDelegation);
                Assert.AreEqual("EvaluationSerializer", evaluation.SerializerDelegation.ClassName);

                Assert.IsNotNull(text);
                Assert.IsNotNull(text.SerializerDelegation);
                Assert.AreEqual("TextSerializer", text.SerializerDelegation.ClassName);
                Assert.AreEqual(":-)", text.InitialValue);

                var processBlockRepository = new EFRepository <ProcessBlock>();
                processBlockRepository.Add(processDefinition);
                unitWork.Flush();
            }
        }
コード例 #12
0
        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;
        }
コード例 #13
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, "");
                     */
                }
            }
        }
コード例 #14
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());
                     * }
                     */
                }
            }
        }
コード例 #15
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());
                     * }
                     */
                }
            }
        }
コード例 #16
0
        public AssemblyExportForm(SldWorks SwApp, LinkNode node, ExportHelper exporter)
        {
            Application.ThreadException +=
                new ThreadExceptionEventHandler(ExceptionHandler);
            AppDomain.CurrentDomain.UnhandledException +=
                new UnhandledExceptionEventHandler(UnhandledException);
            InitializeComponent();
            swApp            = SwApp;
            BaseNode         = node;
            ActiveSWModel    = swApp.ActiveDoc;
            Exporter         = exporter;
            AutoUpdatingForm = false;

            jointBoxes = new Control[] {
                textBoxJointName, comboBoxAxis, comboBoxJointType,
                textBoxAxisX, textBoxAxisY, textBoxAxisZ,
                textBoxJointX, textBoxJointY, textBoxJointZ,
                textBoxJointPitch, textBoxJointRoll, textBoxJointYaw,
                textBoxLimitLower, textBoxLimitUpper, textBoxLimitEffort, textBoxLimitVelocity,
                textBoxDamping, textBoxFriction,
                textBoxCalibrationFalling, textBoxCalibrationRising,
                textBoxSoftLower, textBoxSoftUpper, textBoxKPosition, textBoxKVelocity
            };
            linkBoxes = new Control[] {
                textBoxInertialOriginX, textBoxInertialOriginY, textBoxInertialOriginZ,
                textBoxInertialOriginRoll, textBoxInertialOriginPitch, textBoxInertialOriginYaw,
                textBoxVisualOriginX, textBoxVisualOriginY, textBoxVisualOriginZ,
                textBoxVisualOriginRoll, textBoxVisualOriginPitch, textBoxVisualOriginYaw,
                textBoxIxx, textBoxIxy, textBoxIxz, textBoxIyy, textBoxIyz, textBoxIzz,
                textBoxMass,
                domainUpDownRed, domainUpDownGreen, domainUpDownBlue, domainUpDownAlpha,
                comboBoxMaterials,
                textBoxTexture
            };

            List <TextBox> numericTextBoxes = new List <TextBox>()
            {
                textBoxAxisX, textBoxAxisY, textBoxAxisZ,
                textBoxJointX, textBoxJointY, textBoxJointZ,
                textBoxJointPitch, textBoxJointRoll, textBoxJointYaw,
                textBoxLimitLower, textBoxLimitUpper, textBoxLimitEffort, textBoxLimitVelocity,
                textBoxDamping, textBoxFriction,
                textBoxCalibrationFalling, textBoxCalibrationRising,
                textBoxSoftLower, textBoxSoftUpper, textBoxKPosition, textBoxKVelocity,
                textBoxInertialOriginX, textBoxInertialOriginY, textBoxInertialOriginZ,
                textBoxInertialOriginRoll, textBoxInertialOriginPitch, textBoxInertialOriginYaw,
                textBoxVisualOriginX, textBoxVisualOriginY, textBoxVisualOriginZ,
                textBoxVisualOriginRoll, textBoxVisualOriginPitch, textBoxVisualOriginYaw,
                textBoxIxx, textBoxIxy, textBoxIxz, textBoxIyy, textBoxIyz, textBoxIzz,
                textBoxMass,
                textBoxMimicMultiplier, textBoxMimicOffset,
            };

            foreach (TextBox textBox in numericTextBoxes)
            {
                textBox.KeyPress += NumericalTextBoxKeyPress;
            }

            saveConfigurationAttributeDef = SwApp.DefineAttribute(Serialization.URDF_CONFIGURATION_SW_ATTRIBUTE_NAME);
            int Options = 0;

            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();
        }
コード例 #17
0
        //, ref AttributeDef defattr_chconveyor)
        public void UpdateFromSelection(SelectionMgr swSelMgr, ref AttributeDef mdefattr_chbody)
        {
            // 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());
                    }
                    */
                }
        }
コード例 #18
0
        //, ref AttributeDef defattr_chconveyor)
        public void StoreToSelection(SelectionMgr swSelMgr, ref AttributeDef mdefattr_chbody)
        {
            //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);
                    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***

                    // fetch SW attribute with Chrono parameters for ChBody
                    SolidWorks.Interop.sldworks.Attribute myattr = (SolidWorks.Interop.sldworks.Attribute)swPartcorr.FindAttribute(mdefattr_chbody, 0);
                    if (myattr == null)
                    {
                        // if not already added to part, create and attach it
                        System.Windows.Forms.MessageBox.Show("Create data [should not happen here]");
                        myattr = mdefattr_chbody.CreateInstance5(swPartModel, swPartcorr, "Chrono::ChBody data", 0, (int)swInConfigurationOpts_e.swThisConfiguration);
                        swPartModel.ForceRebuild3(false); // needed?
                        if (myattr == null) System.Windows.Forms.MessageBox.Show("Error: 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, "");
                    */
                }
        }
コード例 #19
0
        //, ref AttributeDef defattr_chconveyor)
        public void UpdateFromSelection(SelectionMgr swSelMgr, ref AttributeDef mdefattr_chbody)
        {
            // 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());
                    }
                    */
                }
        }
コード例 #20
0
        static public void QueryDwg()
        {
            //prompt for input json and output folder
            var doc  = Application.DocumentManager.MdiActiveDocument;
            var ed   = doc.Editor;
            var res1 = ed.GetFileNameForOpen("Specify parameter file");

            if (res1.Status != Autodesk.AutoCAD.EditorInput.PromptStatus.OK)
            {
                return;
            }

            /*var res2 = ed.GetString("Specify output sub-folder name");
             * if (res2.Status != Autodesk.AutoCAD.EditorInput.PromptStatus.OK)
             *  return;*/
            try {
                //get parameter from input json
                var parameters = JsonConvert.DeserializeObject <Parameters>(File.ReadAllText(res1.StringResult));
                //Directory.CreateDirectory(res2.StringResult);
                //extract layer names and block names from drawing as requested and place the results in the
                //output folder
                var db = doc.Database;
                //build XML output
                JsonOutput output = new JsonOutput
                {
                    Blocks     = new List <Block>(),
                    Dependents = new List <Dependent>(),
                    Layers     = new List <Layer>()
                };
                if (parameters.ExtractLayerNames)
                {
                    using (var helper = new GeneralHelper()) {
                        var list = helper.GetLayers().ToList();
                        if (list.Count > 0)
                        {
                            list.ForEach(layer => {
                                var jsonlayer         = new Layer();
                                jsonlayer.Name        = layer.Name;
                                jsonlayer.Description = layer.Description;
                                output.Layers.Add(jsonlayer);
                            });
                        }
                    }
                }
                if (parameters.ExtractBlockNames)
                {
                    using (var helper = new GeneralHelper()) {
                        var list = helper.GetBlocks().ToList();
                        if (list.Count > 0)
                        {
                            list.ForEach(block => {
                                var jsonblock        = new Block();
                                jsonblock.Name       = block.Name;
                                jsonblock.Comments   = block.Comments;
                                jsonblock.Attributes = new List <AttributeDef>();
                                if (block.HasAttributeDefinitions)
                                {
                                    //ed.WriteMessage("\n[INFO] Block name: " + block.Name);
                                    foreach (ObjectId id in block.GetBlockReferenceIds(true, false))
                                    {
                                        if (!(id == ObjectId.Null))
                                        {
                                            //ed.WriteMessage("\n[INFO]   Block Ref Id: " + id);
                                            BlockReference blockRef    = (BlockReference)id.GetObject(OpenMode.ForRead);
                                            AttributeCollection attCol = blockRef.AttributeCollection;
                                            if (attCol.Count > 0)
                                            {
                                                foreach (ObjectId attId in attCol)
                                                {
                                                    if (!(attId == ObjectId.Null))
                                                    {
                                                        AttributeReference attRef = (AttributeReference)attId.GetObject(OpenMode.ForRead);
                                                        if (!(String.IsNullOrEmpty(attRef.Tag) && String.IsNullOrEmpty(attRef.TextString)))
                                                        {
                                                            //ed.WriteMessage("\n[INFO]       Tag: " + attRef.Tag + " | Text: " + attRef.TextString);
                                                            var jsonAttDef  = new AttributeDef();
                                                            jsonAttDef.Tag  = attRef.Tag;
                                                            jsonAttDef.Text = attRef.TextString;
                                                            jsonblock.Attributes.Add(jsonAttDef);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                output.Blocks.Add(jsonblock);
                            });
                        }
                    }
                }
                if (parameters.ExtractDependents)
                {
                    TransmittalFile      tf;
                    TransmittalOperation to = new TransmittalOperation();
                    TransmittalInfo      ti = to.getTransmittalInfoInterface();
                    ti.includeDataLinkFile         = 1;
                    ti.includeDGNUnderlay          = 1;
                    ti.includeDWFUnderlay          = 1;
                    ti.includeFontFile             = 1;
                    ti.includeImageFile            = 1;
                    ti.includeInventorProjectFile  = 1;
                    ti.includeInventorReferences   = 1;
                    ti.includeMaterialTextureFile  = 1;
                    ti.includeNestedOverlayXrefDwg = 1;
                    ti.includePDFUnderlay          = 1;
                    ti.includePhotometricWebFile   = 1;
                    ti.includePlotFile             = 1;
                    ti.includeUnloadedXrefDwg      = 1;
                    ti.includeXrefDwg = 1;
                    if (to.addDrawingFile(doc.Name, out tf) == AddFileReturnVal.eFileAdded)
                    {
                        TransmittalFilesGraph tfg    = to.getTransmittalGraphInterface();
                        TransmittalFile       rootTF = tfg.getRoot();
                        DisplayDependent(rootTF, output);
                    }
                }
                File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "results.json"), JsonConvert.SerializeObject(output));
            } catch (System.Exception e) {
                ed.WriteMessage("Error: {0}", e);
            }
        }