Check inteference using C#

 

Hello all,

I've been trying for a few days now to make AssemblyDocument.CheckInteference to work without success... I get the error

System.Runtime.InteropServices.COMException occurred Message="Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))"

This is caused most probably because of the type of array sent.void VerificaInterferenta(SolidEdgeAssembly.Occurrence feronerie) { try { int NumElementsSet1 = 1; Array Set1 = new Occurrence[1] { feronerie }; SolidEdgeAssembly.InterferenceStatusConstants Status; object ComparisonMethod; object NumElementsSet2 = 0; object Set2 = null; object AddInterferenceAsOccurrence = null; object ReportFilename = ""; object ReportType = ""; object NumInterferences; object InterferingPartsSet1 = null; object InterferingPartsOtherSet = null; object ConfirmedInterference = null; object InterferenceOccurrence; object IgnoreThreadInterferences = SolidEdgeConstants.InterferenceOptionsConstants.seIntfOptIgnoreThreadVsNonThreaded; ComparisonMethod = SolidEdgeConstants.InterferenceComparisonConstants.seInterferenceComparisonSet1vsAllOther; assemblyDocument.CheckInterference(NumElementsSet1, ref Set1, out Status, ComparisonMethod, NumElementsSet2, Set2, AddInterferenceAsOccurrence, ReportFilename, ReportType, out NumInterferences, ref InterferingPartsSet1, ref InterferingPartsOtherSet, ref ConfirmedInterference, out InterferenceOccurrence, IgnoreThreadInterferences); } catch (System.Exception e) { MessageBox.Show(e.ToString()); } }

Any help appreciated.

Thanks a lot,

Edi

 

Posted by: Eduard Oprea
Post date: 11/30/2007 10:12:53 PM

3 REPLIES

RE: Check inteference using C#

 

Hi Edi and welcome,

I've tried it before but I never could get it to work without using .NET Reflection.  Here is the code that I had.using System;using System.Collections.Generic;using System.Reflection;using System.Runtime.InteropServices;using System.Text;namespace CheckInterference{ class Program { static void Main(string[] args) { SolidEdgeFramework.Application application = null; SolidEdgeAssembly.AssemblyDocument assembly = null; SolidEdgeAssembly.Occurrences occurrences = null; application = Marshal.GetActiveObject("SolidEdge.Application") as SolidEdgeFramework.Application; assembly = application.ActiveDocument as SolidEdgeAssembly.AssemblyDocument; occurrences = assembly.Occurrences; Array set1 = Array.CreateInstance(typeof(SolidEdgeAssembly.Occurrence), assembly.Occurrences.Count); SolidEdgeAssembly.InterferenceStatusConstants status = (SolidEdgeAssembly.InterferenceStatusConstants)0; object numInterferences = 0; object interferenceOccurrence = null; for (int i = 1; i = occurrences.Count; i++) { set1.SetValue(occurrences.Item(i), i - 1); } object[] methodArgs = { set1.Length, set1, status, SolidEdgeConstants.InterferenceComparisonConstants.seInterferenceComparisonSet1vsItself, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value }; ParameterModifier p = new ParameterModifier(15); p[1] = true; p[2] = true; ParameterModifier[] mods = { p }; int hr = 0; try { hr = Marshal.GetLastWin32Error(); assembly.GetType().InvokeMember("CheckInterference", BindingFlags.InvokeMethod, null, assembly, methodArgs, mods, null, null); status = (SolidEdgeAssembly.InterferenceStatusConstants)methodArgs[2]; } catch (System.Exception e) { hr = Marshal.GetLastWin32Error(); Console.WriteLine(e.Message); } } }}

 

Posted by: Jason Newell
Post date: 12/1/2007 8:52:15 AM

RE: Check inteference using C#

 

Thanks a lot, Jason. It's working.

Do you think it might be worth to raise an IR? The documentation (provided in the SDK folder) is confusing...

Edi

PS: I really appreciate your work!

 

Posted by: Eduard Oprea
Post date: 12/2/2007 12:01:15 AM

RE: Check inteference using C#

Edi,

 

Glad the code worked for you.

 

I think we should all send in an IR and tell them that their SDK sucks.

 

Posted by: Jason Newell
Post date: 12/2/2007 5:07:09 PM