public void TestSelectComponentsLink(string modelName) { ModelDoc2 doc = OpenSWDocument(modelName); AssemblyDoc assyDoc = (AssemblyDoc)doc; LinkNode baseNode = ConfigurationSerialization.LoadBaseNodeFromModel(doc, out bool abortProcess); Assert.False(abortProcess); Link baseLink = baseNode.RebuildLink(); List <Component2> componentsToSelect = new List <Component2>(); AddLinkComponents(baseLink, componentsToSelect); HashSet <string> componentsToSelectNames = new HashSet <string>(componentsToSelect.Select(component => component.Name2)); CommonSwOperations.SelectComponents(doc, baseLink, true); SelectionMgr selManager = doc.SelectionManager; int numSelected = selManager.GetSelectedObjectCount2(-1); Assert.Equal(componentsToSelect.Count, numSelected); for (int i = 0; i < selManager.GetSelectedObjectCount2(-1); i++) { Component2 comp = selManager.GetSelectedObjectsComponent4(i, -1); Assert.Contains(comp.Name2, componentsToSelectNames); } SwApp.CloseAllDocuments(true); }
public void TestSelectComponentsList(string modelName) { ModelDoc2 doc = OpenSWDocument(modelName); AssemblyDoc assyDoc = (AssemblyDoc)doc; LinkNode baseNode = Serialization.LoadBaseNodeFromModel(SwApp, doc, out bool abortProcess); Assert.False(abortProcess); Link baseLink = baseNode.GetLink(); List <Component2> componentsToSelect = baseLink.SWComponents; HashSet <string> componentsToSelectNames = new HashSet <string>(componentsToSelect.Select(component => component.Name2)); Common.SelectComponents(doc, componentsToSelect, true); SelectionMgr selManager = doc.SelectionManager; // -1 is the Mark, set to negative one if it's not being used. int numSelected = selManager.GetSelectedObjectCount2(-1); Assert.Equal(componentsToSelect.Count, numSelected); for (int i = 0; i < selManager.GetSelectedObjectCount2(-1); i++) { // -1 is the Mark, set to negative one if it's not being used. Component2 comp = selManager.GetSelectedObjectsComponent4(i, -1); Assert.Contains(comp.Name2, componentsToSelectNames); } SwApp.CloseAllDocuments(true); }
public void DrawingNoInput() { IModelDoc2 modDoc = (IModelDoc2)iSwApp.ActiveDoc; //获取当前打开文件类型:1-part,2-assembly int modleType = modDoc.GetType(); //将本体命名 GetAndSetDrawingNo(modDoc);//待完善 //装配体则对下层命名 if (modleType == 2) { AssemblyDoc asmDoc = (AssemblyDoc)modDoc; SelectionMgr selectionMgr = modDoc.SelectionManager; IModelDoc2 partDoc; Component2 component; //asmDoc.getsel int looptime = selectionMgr.GetSelectedObjectCount2(-1); while (looptime >= 1) { //todo:校核是否是零件类,现在是直接抛出 try { looptime--; component = selectionMgr.GetSelectedObject6(looptime + 1, -1); partDoc = (IModelDoc2)component.GetModelDoc2(); GetAndSetDrawingNo(partDoc); } catch { } } } }
/// <summary> /// Run this function after this.Document is populated. It fills two ref vars with swDocumentTypes_e. /// </summary> /// <param name="d">The document type.</param> /// <param name="od">The top-level document type.</param> private void GetTypes(ref swDocumentTypes_e d, ref swDocumentTypes_e od) { swDocumentTypes_e docT = (swDocumentTypes_e)Document.GetType(); ModelDoc2 overDoc = (ModelDoc2)_swApp.ActiveDoc; swDocumentTypes_e overDocT = (swDocumentTypes_e)overDoc.GetType(); if ((docT != swDocumentTypes_e.swDocDRAWING && swSelMgr != null) && swSelMgr.GetSelectedObjectCount2(-1) > 0) { Component2 comp = (Component2)swSelMgr.GetSelectedObjectsComponent4(1, -1); if (comp != null) { ModelDoc2 cmd = (ModelDoc2)comp.GetModelDoc2(); docT = (swDocumentTypes_e)cmd.GetType(); prop.GetPropertyData(comp); comp = null; } else { prop.GetPropertyData(Document); } } else { swSelMgr = null; prop.GetPropertyData(Document); } d = docT; od = overDocT; }
//Finds the selected components and returns them, used when pulling the items from the selection box because it would be too hard // for SolidWorks to allow you to access the selectionbox components directly. public static void getSelectedComponents(ModelDoc2 model, List <Component2> Components, int Mark = -1) { SelectionMgr selectionManager = model.SelectionManager; Components.Clear(); for (int i = 0; i < selectionManager.GetSelectedObjectCount2(Mark); i++) { object obj = selectionManager.GetSelectedObject6(i + 1, Mark); Component2 comp = (Component2)obj; if (comp != null) { Components.Add(comp); } } }
public void SaveAs() { IModelDoc2 modDoc = (IModelDoc2)iSwApp.ActiveDoc; ModelDocExtension mDocExten; IModelDoc2 swModel; AssemblyDoc asmDoc = (AssemblyDoc)modDoc; SelectionMgr selectionMgr = modDoc.SelectionManager; Component2 component; string path; string recentPath; int errors = 0; int warnings = 0; recentPath = iSwApp.GetRecentFiles()[0].Substring(0, modDoc.GetPathName().LastIndexOf("\\")); int looptime = selectionMgr.GetSelectedObjectCount2(-1); while (looptime >= 1) { try { looptime--; component = selectionMgr.GetSelectedObject6(looptime + 1, -1); swModel = (IModelDoc2)component.GetModelDoc2(); mDocExten = swModel.Extension; //todo:校核是否是零件类,现在是直接抛出 //另存为对话框 SaveFileDialog sfd = new SaveFileDialog(); sfd.Title = "另存为"; sfd.InitialDirectory = recentPath;//更改为最近使用 sfd.Filter = "零件| *.sldprt"; sfd.ShowDialog(); path = sfd.FileName; if (path == "") { return; } //另存为新零件 mDocExten.SaveAs(path, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Copy, null, ref errors, ref warnings); //替换现有零件 asmDoc.ReplaceComponents(path, "", false, true); } catch { } } }
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选中边已变色"); } }
public void PartDye() { IModelDoc2 modDoc = (IModelDoc2)iSwApp.ActiveDoc; //获取当前打开文件类型:1-part,2-assembly int modleType = modDoc.GetType(); dynamic materialPropertyValues; PartDoc partDoc; Component2 component; if (modleType == 1) { partDoc = (PartDoc)modDoc; materialPropertyValues = partDoc.MaterialPropertyValues; partDoc.MaterialPropertyValues = RandomColorValues(materialPropertyValues); } else if (modleType == 2) { AssemblyDoc asmDoc = (AssemblyDoc)modDoc; SelectionMgr selectionMgr = modDoc.SelectionManager; //asmDoc.getsel int looptime = selectionMgr.GetSelectedObjectCount2(-1); while (looptime >= 1) { try { looptime--; component = selectionMgr.GetSelectedObject6(looptime + 1, -1); partDoc = (PartDoc)component.GetModelDoc2(); //todo:校核是否是零件类,现在是直接抛出 materialPropertyValues = partDoc.MaterialPropertyValues; partDoc.MaterialPropertyValues = RandomColorValues(materialPropertyValues); } catch { } } } modDoc.GraphicsRedraw2(); }
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()); }
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, ""); */ } } }
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()); * } */ } } }
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()); * } */ } } }
//, 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()); } */ } }
//, 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, ""); */ } }
//, 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()); } */ } }