Reply
Solved! Go to solution

How to use SetBaseStyle

[ Edited ]

Hello everybody,

i want to set the basestyles for some files, but SetBaseStyle causes a ComException. When calling SetBaseStyle i get a System.Runtime.InteropServices.COMException with

HRESULT: 0x80040224. Here is some more information for the error:

 

System.Runtime.InteropServices.COMException wurde nicht behandelt.
  ErrorCode=-2147220956
  HResult=-2147220956
  Message=Ausnahme von HRESULT: 0x80040224
  Source=""
  StackTrace:
       bei System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
       bei SolidEdgeAssembly.AssemblyDocument.SetBaseStyle(AssemblyBaseStylesConstants BaseStyleType, FaceStyle BaseStyle)
       bei ModellStyler.CModellStyler.UpdateFaceStyles() in T:\CKu\Code\Quellcode\CKM\Solid Edge VB Projekte\ModellStyler\CModellStyler.vb:Zeile 181.
       bei ModellStyler.CModellStyler.Update() in T:\CKu\Code\Quellcode\CKM\Solid Edge VB Projekte\ModellStyler\CModellStyler.vb:Zeile 127.
       bei ModellStyler.frmModellStyles.btnStart_Click(Object sender, EventArgs e) in T:\CKu\Code\Quellcode\CKM\Solid Edge VB Projekte\ModellStyler\frmModellStyles.vb:Zeile 196.
       bei System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       bei System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       bei System.Windows.Forms.Control.WndProc(Message& m)
       bei System.Windows.Forms.ButtonBase.WndProc(Message& m)
       bei System.Windows.Forms.Button.WndProc(Message& m)
       bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       bei System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       bei System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
       bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
       bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       bei ModellStyler.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:Zeile 82.
       bei System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       bei System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
       bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
       bei System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       bei System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

 

I attached a short version of my class. In the code is a comment (not working, here is my problem) for the part which is making trouble.

Can anybody tell me how to use SetBaseStyle for example to set the style for threaded cylinders of a part?

 

Greetings from Germany

Christian

Greetings from Germany
Christian Kunkel
https://c-k-m.info
7 REPLIES

Re: How to use SetBaseStyle

Hello everybody,

 

i made a test and if i use the direct reference to solid edge type librarys it works as expected.

If i use the great Interop.SolidEdge (107.2.0.0) i get the error.

 

Jason, can you fix it?

Greetings from Germany
Christian Kunkel
https://c-k-m.info

Re: How to use SetBaseStyle

That is odd. I'll take a look tonight and see if I can tell what's going on.

Jason Newell
Applications Architect
www.jasonnewell.net

Re: How to use SetBaseStyle

Thank you Jason,

perhaps it has to do with the missing culture information for Interop.SolidEdge?

 

Greetings from Germany

 

Christian

Greetings from Germany
Christian Kunkel
https://c-k-m.info

Re: How to use SetBaseStyle

Hallo Jason,

 

any news?

Greetings from Germany
Christian Kunkel
https://c-k-m.info
Solution
Solution
Accepted by topic author ckunkel72
‎08-26-2015 04:32 AM

Re: How to use SetBaseStyle

I have verified that the IL for the Visual Studio generated interop assembly matches the interop assembly in the NuGet package. That eliminates the NuGet package as the possible culprit. As to why you're only seeing an exception when using the NuGet package, I'm not sure.

 

Upon investigation into your code, I believe I've found the flaw. In your UpdateFaceStyles() method, you define an variable named sourceStyles and set it equal to the source document FaceStyles property. You later access a particular FaceStyle in sourceStyles and use it to call SetBaseStyle() in the destination document.

 

'set styles (not working, here is my problem)
If _stylerSettings.FaceStyleSet Then
	style = CType(sourceStyles.Item(_stylerSettings.KonstruktionsFaceStyle), FaceStyle)
	par.SetBaseStyle(SolidEdgePart.PartBaseStylesConstants.seConstructionBaseStyle, style)
	style = CType(sourceStyles.Item(_stylerSettings.GewindeFaceStyle), FaceStyle)
	par.SetBaseStyle(SolidEdgePart.PartBaseStylesConstants.seThreadedCylindersBaseStyle, style)
End If

That will never work because you are trying to use a COM object from the source document and apply it to the destination object. That is flawed logic and you need to rewrite it so that you're referencing a FaceStyle from the destination document after you've imported the styles via ImportStyles().

 

As a simple test to check that SetBaseStyle() is working as expected, I wrote the following C# code and it worked as expected. You should use this example to verify on your end.

 

asm.GetBaseStyle(SolidEdgeAssembly.AssemblyBaseStylesConstants.seAssemblyConstructionStyle, out style);

asm.SetBaseStyle(SolidEdgeAssembly.AssemblyBaseStylesConstants.seAssemblyConstructionStyle, style);

 

 

Jason Newell
Applications Architect
www.jasonnewell.net

Re: How to use SetBaseStyle

Hallo Jason,

 

now it works as expected! Thank you very much!

Sorry for the trouble and work. You do a great job.

 

Greetings from Germany

Christian

Greetings from Germany
Christian Kunkel
https://c-k-m.info

Re: How to use SetBaseStyle

Don't apologize. We're all learning as we go. It's easy to miss the little things when working on big projects. Extra set of eyes never hurts. Thanks for the compliment.

Jason Newell
Applications Architect
www.jasonnewell.net