public static void GetFace(ModelDoc2 Doc)
        {
            ModelDocExtension DocEx    = Doc.Extension;
            SelectionMgr      SwSelMrg = Doc.SelectionManager;

            DocEx.SelectByID2("", "FACE", -100 / 1000.0, 60 / 1000.0, 15 / 1000.0, false, -1, null, 0);
            System.Windows.MessageBox.Show("模拟选中面");

            string         selcount = SwSelMrg.GetSelectedObjectCount2(-1).ToString();
            swSelectType_e seltype  = (swSelectType_e)SwSelMrg.GetSelectedObjectType3(1, -1);

            if (seltype == swSelectType_e.swSelFACES)
            {
                Face2 SwFace = SwSelMrg.GetSelectedObject6(1, -1);
                System.Windows.MessageBox.Show("选中数:" + selcount + "\r\n选中类型:" + seltype.ToString() + "\r\n选中面面积:" + SwFace.GetArea().ToString());
            }
        }
        public static void GetEdge(ModelDoc2 Doc)
        {
            ModelDocExtension DocEx    = Doc.Extension;
            SelectionMgr      SwSelMrg = Doc.SelectionManager;

            DocEx.SelectByID2("", "EDGE", 0 / 1000.0, 30 / 1000.0, 75 / 1000.0, false, -1, null, 0);
            System.Windows.MessageBox.Show("模拟选中边线");

            string         selcount = SwSelMrg.GetSelectedObjectCount2(-1).ToString();
            swSelectType_e seltype  = (swSelectType_e)SwSelMrg.GetSelectedObjectType3(1, -1);

            if (seltype == swSelectType_e.swSelEDGES)
            {
                Edge SwEdge = SwSelMrg.GetSelectedObject6(1, -1);
                SwEdge.Display(1, 1, 0, 0, true);//true变色开,false关闭变色
                System.Windows.MessageBox.Show("选中数:" + selcount + "\r\n选中类型:" + seltype.ToString() + "\r\n选中边已变色");
            }
        }
Ejemplo n.º 3
0
        public void CopyLink()
        {
            Clipboard.Clear();
            AddinDocument addinDoc = _swAddin.GetActiveDoc();

            if (addinDoc == null)
            {
                return;
            }
            string    swDoc      = addinDoc.FullFileName;
            ModelDoc2 swModelDoc = SWHelper.GetDocByFileName(swDoc); // нужно учитывать что браться на редактирование может документ не открытый в PLM. тогда здесь будет null и нужно либо открывать документ, либо работать через DMDocument

            if (swModelDoc == null)
            {
                return;
            }

            SelectionMgr mSelectionMgr = swModelDoc.ISelectionManager;
            String       sz            = "";

            var tp = mSelectionMgr.GetSelectedObjectType3(1, -1);

            if (tp == (int)swSelectType_e.swSelDIMENSIONS)
            {
                IDisplayDimension sel = (IDisplayDimension)mSelectionMgr.GetSelectedObject6(1, 0);
                sz = sel.GetDimension2(0).FullName;
                Clipboard.SetText(sz);
            }

            /*  if (tp == (int)swSelectType_e.swSelNOTES)
             * {
             *    INote sel = (INote)mSelectionMgr.GetSelectedObject6(1, 0); mSelectionMgr.IGetSelectedObjectsComponent2
             *    sel
             *
             *    Annotation swAnn = (Annotation)sel.GetAnnotation();
             *    swAnn.
             *    ModelDocExtension mde = (ModelDocExtension)swModel.Extension;
             *    int id = mde.GetObjectId(swAnn);
             *
             *    swFeature.GetNameForSelection(out sz);
             * }*/
            //if (sz.Length != 0) MessageBox.Show(sz);
        }
        public static void GetSelectList(ModelDoc2 Doc)
        {
            ModelDocExtension DocEx    = Doc.Extension;
            SelectionMgr      SwSelMrg = Doc.SelectionManager;

            DocEx.SelectByID2("", "FACE", -100 / 1000.0, 60 / 1000.0, 15 / 1000.0, false, -1, null, 0);
            DocEx.SelectByID2("", "EDGE", 0 / 1000.0, 30 / 1000.0, 75 / 1000.0, true, -1, null, 0);
            System.Windows.MessageBox.Show("模拟选中多个元素完成");

            StringBuilder Sb       = new StringBuilder("选择集合信息:\r\n");
            int           selcount = SwSelMrg.GetSelectedObjectCount2(-1);

            Sb.Append("选择总数:" + selcount.ToString() + "\r\n");
            Sb.Append("-----------------\r\n");
            for (int i = 1; i <= selcount; i++)
            {
                Sb.Append("index参数为" + i.ToString() + "的对象\r\n");
                swSelectType_e seltype = (swSelectType_e)SwSelMrg.GetSelectedObjectType3(i, -1);
                Sb.Append("类型:" + seltype.ToString().Trim() + "\r\n");
                Sb.Append("-----------------\r\n");
            }
            System.Windows.MessageBox.Show(Sb.ToString());
        }
Ejemplo n.º 5
0
                public static ExternalFileReferences Get(SldWorks swApp)
                {
                    try
                    {
                        var               obj                = new ExternalFileReferences();
                        ModelDoc2         swModel            = default(ModelDoc2);
                        ModelDocExtension swModDocExt        = default(ModelDocExtension);
                        SelectionMgr      swSelMgr           = default(SelectionMgr);
                        Feature           swFeat             = default(Feature);
                        Component2        swComp             = default(Component2);
                        object            vModelPathName     = null;
                        object            vComponentPathName = null;
                        object            vFeature           = null;
                        object            vDataType          = null;
                        object            vStatus            = null;
                        object            vRefEntity         = null;
                        object            vFeatComp          = null;
                        int               nConfigOpt         = 0;
                        string            sConfigName        = null;
                        int               nRefCount          = 0;
                        int               nSelType           = 0;
                        int               i = 0;

                        swModel  = (ModelDoc2)swApp.ActiveDoc;
                        swSelMgr = (SelectionMgr)swModel.SelectionManager;

                        swModDocExt = (ModelDocExtension)swModel.Extension;
                        nSelType    = swSelMgr.GetSelectedObjectType3(1, -1);

                        switch (nSelType)
                        {
                        // Selected component in an assembly document
                        case (int)swSelectType_e.swSelCOMPONENTS:
                            swComp    = (Component2)swSelMgr.GetSelectedObjectsComponent3(1, -1);
                            nRefCount = swComp.ListExternalFileReferencesCount();
                            swComp.ListExternalFileReferences2(out vModelPathName, out vComponentPathName, out vFeature, out vDataType, out vStatus, out vRefEntity, out vFeatComp, out nConfigOpt, out sConfigName);

                            swModel = (ModelDoc2)swComp.GetModelDoc2();

                            break;

                        // Selected feature in a part or assembly document
                        case (int)swSelectType_e.swSelBODYFEATURES:
                        case (int)swSelectType_e.swSelSKETCHES:
                            swFeat    = (Feature)swSelMgr.GetSelectedObject6(1, -1);
                            nRefCount = swFeat.ListExternalFileReferencesCount();
                            swFeat.ListExternalFileReferences2(out vModelPathName, out vComponentPathName, out vFeature, out vDataType, out vStatus, out vRefEntity, out vFeatComp, out nConfigOpt, out sConfigName);

                            break;

                        // Part document only
                        default:
                            nRefCount = swModDocExt.ListExternalFileReferencesCount();
                            swModDocExt.ListExternalFileReferences(out vModelPathName, out vComponentPathName, out vFeature, out vDataType, out vStatus, out vRefEntity, out vFeatComp, out nConfigOpt, out sConfigName);

                            break;
                        }

                        //Debug.Print("Model name = " + swModel.GetPathName());

                        if (nRefCount >= 1)
                        {
                            object[] ModelPathName     = new object[nRefCount - 1];
                            object[] ComponentPathName = new object[nRefCount - 1];
                            object[] Feature           = new object[nRefCount - 1];
                            object[] DataType          = new object[nRefCount - 1];
                            int[]    Status            = new int[nRefCount - 1];
                            object[] RefEntity         = new object[nRefCount - 1];
                            object[] FeatComp          = new object[nRefCount - 1];

                            ModelPathName     = (object[])vModelPathName;
                            ComponentPathName = (object[])vComponentPathName;
                            Feature           = (object[])vFeature;
                            DataType          = (object[])vDataType;
                            Status            = (int[])vStatus;
                            RefEntity         = (object[])vRefEntity;
                            FeatComp          = (object[])vFeatComp;

                            for (i = 0; i <= nRefCount - 1; i++)
                            {
                                obj.ModelPathName     = ModelPathName[i].ToString();
                                obj.ComponentPathName = ComponentPathName[i].ToString();
                                obj.Feature           = Feature[i].ToString();
                                obj.DataType          = DataType[i].ToString();
                                obj.Status            = Status[i].ToString();
                                obj.ReferenceEntity   = RefEntity[i].ToString();
                                obj.FeatureComponent  = FeatComp[i].ToString();
                                obj.ConfigOption      = nConfigOpt.ToString();
                                obj.ConfigName        = sConfigName?.ToString();
                            }
                        }
                        return(obj);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.StackTrace);
                        return(null);
                    }
                }
Ejemplo n.º 6
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.º 7
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.º 8
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());
                     * }
                     */
                }
            }
        }
Ejemplo n.º 9
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());
                    }
                    */
                }
        }
Ejemplo n.º 10
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, "");
                    */
                }
        }
        public void Main()
        {
            //ADD THESE LINES OF CODE
            double holeRadius;
            double holeDepth;
            //Create an instance of the user form

            frmCutExtrude myForm = new frmCutExtrude();

            //Set the title for the form
            myForm.Text = "Size of Cut-Extrude in Millimeters";
            //Display the user form and retrieve radius and
            //depth values typed by the user; divide those values
            //by 1000 to change millimeters to meters
            myForm.ShowDialog();
            holeRadius = myForm.radius / 1000;
            holeDepth  = myForm.depth / 1000;
            //Dispose of the user form and remove it from
            //memory because it's no longer needed
            myForm.Dispose();


            ModelDoc2 swDoc = null;

            //bool boolstatus = false;
            //var COSMOSWORKSObj = null;
            swDoc = ((ModelDoc2)(swApp.ActiveDoc));
            //COSMOSWORKSObj COSMOSWORKSObj = null;
            //CWAddinCallBackObj CWAddinCallBackObj = null;
            //CWAddinCallBackObj = swApp.GetAddInObject("CosmosWorks.CosmosWorks");
            //COSMOSWORKSObj = CWAddinCallBackObj.COSMOSWORKS;
            ModelView myModelView = null;

            myModelView            = ((ModelView)(swDoc.ActiveView));
            myModelView.FrameState = ((int)(swWindowState_e.swWindowMaximized));
            //boolstatus = swDoc.Extension.SelectByRay(0.00053592862681739462, 0.2199999999999136, -0.0045118054006820785, -0.18724816575405859, -0.66456615869841951, -0.723387824845406, 0.0010862903128070283, 2, false, 0, 0);
            //ADD THESE LINES OF CODE
            //Get coordinates of selection point
            SelectionMgr swSelectionMgr = null;

            swSelectionMgr = (SelectionMgr)swDoc.SelectionManager;
            double[] SelectCoordinates;
            SelectCoordinates = (double[])swSelectionMgr.GetSelectionPoint2(1, -1);
            //If face is selected, then open a sketch;
            //otherwise, stop execution
            object SelectedObject = null;

            SelectedObject = (object)swSelectionMgr.GetSelectedObject6(1, 0);
            int objtype;

            objtype = (int)swSelectionMgr.GetSelectedObjectType3(1, -1);
            if (objtype == (int)swSelectType_e.swSelFACES)
            {
                swDoc.SketchManager.InsertSketch(true);
            }

            //swDoc.ClearSelection2(true);
            SketchSegment skSegment = null;

            skSegment = ((SketchSegment)(swDoc.SketchManager.CreateCircle(0, 0, 0, 0.010505, -0.007509, 0)));
            Feature myFeature = null;

            myFeature = ((Feature)(swDoc.FeatureManager.FeatureCut4(true, false, false, 0, 0, 0.02, 0.01, true, false, false, false, 0.26179938779914946, 0.017453292519943334, false, false, false, false, false, true, true, true, true, false, 0, 0, false, false)));
            swDoc.ISelectionManager.EnableContourSelection = false;
            //StudyManagerObj = null;
            //ActiveDocObj = null;
            //CWAddinCallBackObj = null;
            //COSMOSWORKSObj = null;


            //ADD THESE LINES OF CODE
            //Get IMathPoint to use when transforming
            //from model space to sketch space
            MathUtility swMathUtility = null;
            MathPoint   swMathPoint   = null;
            Sketch      swSketch      = null;
            double      dx;
            double      dy;
            double      dz;

            swMathUtility = (MathUtility)swApp.GetMathUtility();
            swMathPoint   = (MathPoint)swMathUtility.CreatePoint(SelectCoordinates);
            //Get reference to sketch
            swSketch = (Sketch)swDoc.SketchManager.ActiveSketch;
            //Translate sketch point into sketch space
            MathTransform swMathTransform = null;

            swMathTransform = (MathTransform)swSketch.ModelToSketchTransform;
            swMathPoint     = (MathPoint)swMathPoint.MultiplyTransform(swMathTransform);
            //Retrieve coordinates of the sketch point
            double[] darray;
            darray = (double[])swMathPoint.ArrayData;
            dx     = darray[0];
            dy     = darray[1];
            dz     = darray[2];
            //Use swDoc.SketchManager.CreateCircleByRadius instead of
            //swDoc.SketchManager.CreateCircle because
            //swDoc.SketchManager.CreateCircleByRadius sketches a
            //circle centered on a sketch point and lets you
            //specify a radius
            double        radius          = 0.015;
            SketchSegment swSketchSegment = null;

            swSketchSegment = (SketchSegment)swDoc.SketchManager.CreateCircleByRadius(dx, dy, dz, radius);
            //Create the cut extrude feature
            Feature swFeature = null;

            swFeature = (Feature)swDoc.FeatureManager.FeatureCut3(true, false, false, 0, 0, 0.025, 0.01, true, false, false, false, 0, 0, false, false, false, false, false, true, true, false, false, false, (int)swStartConditions_e.swStartSketchPlane, 0, false);
        }
Ejemplo n.º 12
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());
                    }
                    */
                }
        }