Date post: | 25-Dec-2014 |
Category: |
Technology |
Upload: | siemens-plm-software |
View: | 3,458 times |
Download: | 4 times |
#SEU12
My First Add-In Jason Newell
The Charles Machine Works, Inc
Ditch Witch
Applications Architect
© Siemens AG 2012. All Rights Reserved.
Siemens PLM Software Page 2
Background
The Charles Machine Works, Inc. (Ditch Witch)
• 1997 – Hired into IT support for Engineering department
• 1999 – Took over administration of multi-million dollar Unix based PDM
system
• * The beginning of my programming journey started here
• 2000 – Started learning how to automate Solid Edge
• 2002 – Moved to full-time programming position
• 2005 – Implemented SAP
• Present – Little bit of everything with a focus on Microsoft technologies
JasonNewell.NET
• 2005 – Created website and forums
• Consulting work for customers world-wide
© Siemens AG 2012. All Rights Reserved.
Siemens PLM Software Page 3
Overview
We will be thoroughly covering the basics of Solid Edge Add-Ins. Nothing fancy
but you will understand how Solid Edge Add-Ins work when you leave and know
what the bare minimum code it requires to write one.
There is so much that needs to be understood before attempting to write an add-
in. So many situations and scenarios. So many programming languages to
choose from.
What programming language is used in this presentation ?
Survey says: Visual Basic .NET
© Siemens AG 2012. All Rights Reserved.
Siemens PLM Software Page 4
Solid Edge Add-In - Definition
What in the an Add-In?
Standard Definition
“Solid Edge defines an add-in as a dynamically linked library (DLL) containing a
COM-based object that implements the ISolidEdgeAddIn interface.” - addin.doc
Extended Definition
Besides the technical definitions, the add-in architecture allows you to execute
code in process “in-proc” with Solid Edge rather than out of process “out-of-proc”
like macros.
© Siemens AG 2012. All Rights Reserved.
Siemens PLM Software Page 5
Solid Edge Add-In Pros \ Cons
Pros
• Add-In gets loaded when Solid Edge is started (typically or can be later).
Point is no user interaction is required to start the add-in.
• You can achieve a higher level of integration with Solid Edge compared to say
a macro.
Cons
• Generally speaking, if you crash, you’re taking Solid Edge down with you.
Challenges
• The current add-in architecture was designed with native COM friendly
languages in mind. Writing add-ins in .NET is challenge because of this fact.
• Getting a .NET cat to bark like a COM dog (no pun intended) is damn hard!
© Siemens AG 2012. All Rights Reserved.
Siemens PLM Software Page 6
Managed vs Native
Code written in .NET compiles to Microsoft Intermediate Language (MSIL) and is
referred to as “Managed” code. The code is Just-in-time (JIT) compiled at
runtime whereas “Native” code is compiled directly to machine code.
Solid Edge is a native application so any interaction with .NET must go through
an interoperability (Interop) layer. This interoperability layer is the one of the
biggest pain points in .NET add-in development compared to native add-in
development.
© Siemens AG 2012. All Rights Reserved.
Siemens PLM Software Page 7
.NET Framework Versions and Dependencies
Source: http://msdn.microsoft.com/en-us/library/bb822049.aspx
© Siemens AG 2012. All Rights Reserved.
Siemens PLM Software Page 8
Basic Architecture of .NET
Shared Components
CLR v2
.NET Framework
2.0
.NET Framework
3.0
.NET Framework
3.5
CLR v4
.NET Framework
4.0
.NET Framework
4.5
© Siemens AG 2012. All Rights Reserved.
Siemens PLM Software Page 9
Process Overview
Edge.exe – Native Process
Native.dll Native
Addin.dll mscoree.dll – (Default “vanilla“ shim)
CLR v2
(Default app domain)
MyAddin_20 MyAddin_30 MyAddin_35
CLR v4 (Default app domain)
MyAddin_40 MyAddin_45
© Siemens AG 2012. All Rights Reserved.
Siemens PLM Software Page 10
Application Domains & Runtime Callable Wrappers
COM Object
Ref Count = 2
AppDomain 1
RCW
Ref Count = 1 Addin1
Addin2
AppDomain 2
RCW
Ref Count = 1 Addin3
Addin4
© Siemens AG 2012. All Rights Reserved.
Siemens PLM Software Page 11
Visual Studio Bugs!
Visual Studio 2010 has a bug that will cause the Type Library Importer
(tlbimp.exe) to generate interop assemblies in the wrong format. I only noticed
the bug when having Solid Edge x64 installed. This will cause regasm.exe to
fail. To correct this, you have to manually edit your . vbproj and add the following
line.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PlatformTarget>AnyCPU</PlatformTarget>
….
</PropertyGroup>
</Project>
© Siemens AG 2012. All Rights Reserved.
Siemens PLM Software Page 12
Live Demos!
#SEU12
Thank You! Questions?