Your SlideShare is downloading. ×
0
Basics of Automating Solid Edgewith .NETGreg ChasteenSiemens PLM  #SEU12
Getting StartedAll major Windows programming tools that support Active XAutomation or COM  Visual Basic, C++,.NET, etc.Au...
What is .NET Framework?Google says:A programming infrastructure created by Microsoft forbuilding, deploying, and running a...
COM Interop – Important ClassesSystem.GC Class Controls the system garbage collector, a service that automatically  recla...
Common .NET Framework TerminologyAssembly A collection of one or more files that are versioned and deployed as a  unit. A...
Common .NET Framework TerminologyCOM Interop Component Object Model (COM) is a binary-interface standard for software  co...
Common .NET Framework TerminologyGarbage Collection (GC) The .NET Garbage Collector (GC) is a non-deterministic, compacti...
Confused enough!!!!.NET Framework available versions                                    © Siemens AG 2012. All Rights Rese...
Solid Edge Setup Delivers .NET Frameworkprerequisite         Solid Edge Version         Microsoft .NET Framework          ...
.NET Framework Version CompatibilityMicrosoft says:Most times, applications will ask for a particular version of the frame...
Which Microsoft .NET Framework version?Know your customer… Who will be using your application? What version of Solid Edge...
New Automation ProjectNeed an automation solution to mark dimensions on a solid Edge draft filethat are critical, major an...
Writing .NET Applications for Solid EdgeSeven General Steps To Create A Program    Open a new Project    Add References ...
Create a new project                       © Siemens AG 2012. All Rights Reserved.Page 14                                 ...
Writing .NET Applications for Solid EdgeConfiguring Visual Studio .NET for Solid Edge Programming What’s involved?  Not ...
Adding the Solid Edge References                                   © Siemens AG 2012. All Rights Reserved.Page 16         ...
Adding the Solid Edge References                                   © Siemens AG 2012. All Rights Reserved.Page 17         ...
Result of adding the Solid Edge ReferencesAfter building the solution. Here is what you get….    So where are the Interop ...
New “feature” in VS 2010 VB 2010 has the ability to  embed the InteropsThis is “handy” but is it a goodIdea?Development sa...
Generating Unique InteropsTool delivered with SolidEdgeI generate a bat file for each Solid Edge macro I write and save it...
Generating Unique InteropsDelivered in the Solid Edge SDKtools folder GenEdgeInteropAssemblies.bat First argument   "C:...
Generating Unique InteropsResulting uniquely name Interop DLLs                                       © Siemens AG 2012. Al...
How to reference the unique Interop DLLsRun the Add Reference command and select the necessary interops                   ...
Results          © Siemens AG 2012. All Rights Reserved.Page 24                    Siemens PLM Software
Creating Forms                 © Siemens AG 2012. All Rights Reserved.Page 25                           Siemens PLM Software
Add Code If you automate Solid Edge from an external (out-of-proc) application, you may receive one of the following error...
Add CodeMaking your macro connect to or start Solid Edge                                              © Siemens AG 2012. A...
Add Code           © Siemens AG 2012. All Rights Reserved.Page 28                     Siemens PLM Software
© Siemens AG 2012. All Rights Reserved.Page 29                    Siemens PLM Software
TipsTry, Catch & FinallyVB now supports structured exception handling, which helps you createand maintain programs with ro...
TipsAn executable created with VB .NET 2003 - 2008 because of .NET securityissues can not be run across a network drive be...
TipsIn automation situations where a client is keeping Solid Edge extremelybusy, Solid Edge will not have an opportunity t...
TipsGeneral rule of thumb which reference to use Solid Edge Framework Type Library- All APIs for functionality common acr...
TipsGeneral rule of thumb which reference to use - Continued Solid Edge Install Data Library - lightweight API to determi...
TipsKeep commonly used functions and sub routines in your SE macrotemplate….http://www.codeproject.com/Articles/88957/Writ...
TipsKeep common subroutines and functions in a dll 1 common source…. If need to make a change then ALL your customization...
TipsAdd a reference to your dll housing your common functions andsubroutines                                             ©...
Tips          © Siemens AG 2012. All Rights Reserved.Page 38                    Siemens PLM Software
TipsAdd your functions to your solution                                      © Siemens AG 2012. All Rights Reserved.Page 3...
TipsHow to call your DLL                       © Siemens AG 2012. All Rights Reserved.Page 40                             ...
Tips          © Siemens AG 2012. All Rights Reserved.Page 41                    Siemens PLM Software
TipsOnline templates                   © Siemens AG 2012. All Rights Reserved.Page 42                             Siemens ...
Thank You!Questions?  #SEU12
Upcoming SlideShare
Loading in...5
×

Solid Edge API: Automating Solid Edge Basics with .net

12,390

Published on

Solid Edge API: Automating Solid Edge Basics with .net

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
12,390
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
194
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "Solid Edge API: Automating Solid Edge Basics with .net"

  1. 1. Basics of Automating Solid Edgewith .NETGreg ChasteenSiemens PLM #SEU12
  2. 2. Getting StartedAll major Windows programming tools that support Active XAutomation or COM  Visual Basic, C++,.NET, etc.Automation typlibs delivered with Solid Edge  Physically located in program folder  Just Add Reference to the typlib requiredJust pick your favorite programming language and away you go.This presentation will mainly use Visual Basic delivered with VisualStudio 2010. © Siemens AG 2012. All Rights Reserved.Page 2 Siemens PLM Software
  3. 3. What is .NET Framework?Google says:A programming infrastructure created by Microsoft forbuilding, deploying, and running applications and services that use .NETtechnologies, such as desktop applications and Web services.The .NET Framework contains three major parts: the Common Language Runtime The Common Language Runtime (CLR) is the execution engine of the .NET Framework. All .NET programs execute under the supervision of the CLR, guaranteeing certain properties and behaviors in the areas of memory management, security, and exception handling. the Framework Class Library The .NET Framework includes a set of standard class libraries. The class library is organized in a hierarchy of namespaces. Most of the built-in APIs are part of either System.* or Microsoft.* namespaces. These class libraries implement a large number of common functions, such as file reading and writing, graphic rendering, database interaction, and XML document manipulation, among others. ASP.NET. © Siemens AG 2012. All Rights Reserved. Page 3 Siemens PLM Software
  4. 4. COM Interop – Important ClassesSystem.GC Class Controls the system garbage collector, a service that automatically reclaims unused memory GC.Collect() method forces garbage collectionSystem.Runtime.InteropServices Namespace that provides a wide variety of members that support COM Interop and platform invoke servicesSystem.Runtime.InteropServices.Marshall Class Provides a collection of methods for allocating unmanaged memory, copying unmanaged memory blocks, and converting managed to unmanaged types, as well as other miscellaneous methods used when interacting with unmanaged code. Marshal.ReleaseComObject() method Decrements the reference count of the supplied runtime callable wrapper © Siemens AG 2012. All Rights Reserved.Page 4 Siemens PLM Software
  5. 5. Common .NET Framework TerminologyAssembly A collection of one or more files that are versioned and deployed as a unit. An assembly is the primary building block of a .NET Framework application.Global Assembly Cache (GAC) A machine-wide code cache that stores assemblies specifically installed to be shared by many applications on the computer. Applications deployed in the global assembly cache must have a strong name.Primary Interop Assembly• An assembly containing definitions of COM types that is distributed and digitally signed by the author of the COM component. © Siemens AG 2012. All Rights Reserved.Page 5 Siemens PLM Software
  6. 6. Common .NET Framework TerminologyCOM Interop Component Object Model (COM) is a binary-interface standard for software componentry introduced by Microsoft in 1993. It is used to enable interprocess communication and dynamic object creation in a large range of programming languages. The term COM is often used in the Microsoft software development industry as an umbrella term that encompasses the OLE, OLE Automation, ActiveX, COM+ and DCOM technologies.Why is COM Interop important? It is the only means by which a .NET application can communicate with a COM application and vice-versa Solid Edge is COM based application. Therefore, API’s are Majority of applications that you will interact with are currently COM based COM is going to be around for long, long time so better get used to it! © Siemens AG 2012. All Rights Reserved.Page 6 Siemens PLM Software
  7. 7. Common .NET Framework TerminologyGarbage Collection (GC) The .NET Garbage Collector (GC) is a non-deterministic, compacting, mark- and-sweep garbage collector. The GC runs only when a certain amount of memory has been used or there is enough pressure for memory on the system. Since it is not guaranteed when the conditions to reclaim memory are reached, the GC runs are non-deterministic.So exactly what does this mean to the average Solid Edge wannbeprogrammer like ME! This was a much bigger issue for ST2 and previous Solid Edge versions and .NET programs. Later SE versions especially ST4 and ST5 do a much better job determining when to FORCE this Garbage Collection. The result is ALL the responsibility for memory management is NOT on me the .NET application programmer as before in previous Solid Edge versions! That said it is still a good idea as a programmer to appropriate Garbage Collection when necessary. This provides simply and extra “layer” or protection against crashes and memory corruption as a result of running your program. © Siemens AG 2012. All Rights Reserved. Page 7 Siemens PLM Software
  8. 8. Confused enough!!!!.NET Framework available versions © Siemens AG 2012. All Rights Reserved.Page 8 Siemens PLM Software
  9. 9. Solid Edge Setup Delivers .NET Frameworkprerequisite Solid Edge Version Microsoft .NET Framework V20 2.0 ST 2.0 ST2 3.5 ST3 3.5 ST4 3.5, 4.0 ST5 3.5, 4.0 © Siemens AG 2012. All Rights Reserved.Page 9 Siemens PLM Software
  10. 10. .NET Framework Version CompatibilityMicrosoft says:Most times, applications will ask for a particular version of the frameworkto be installed. Wed recommend avoiding installing that particularversion, and trying instead to install the most up-to-date version of.NET, assuming your Windows OS supports it. Most .NET packages havebackwards compatibility, so an app asking for the 2.0 framework canusually get by with whats packaged into the latest version: .NETFramework 4.Another common problem involves older versions of .NETand, perhaps, their misbehavior on your system. Head into yourAdd/Remove Programs section in Control Panel (or "Uninstall Programs"in newer Windows setups) and search for any installations related to ".NETFramework," or something very similar. Try removing them fromhere, through the standard uninstall procedure, then try installing yournewer .NET framework again. If that still fails, its time to turn to the .NET © Siemens AG 2012. All Rights Reserved.Framework Cleanup Tool, which was made by Microsoft itself to tidy up Page 10 Siemens PLM Software
  11. 11. Which Microsoft .NET Framework version?Know your customer… Who will be using your application? What version of Solid Edge will they be using? What type of machines?What Visual Studio version are you using? VS 2010 -> 4.0 .NET Framework VS 2008 -> 3.5 .NET Framework © Siemens AG 2012. All Rights Reserved.Page 11 Siemens PLM Software
  12. 12. New Automation ProjectNeed an automation solution to mark dimensions on a solid Edge draft filethat are critical, major and minor with diamond, square and roundrespectively. The idea is to automate this to help increase productivity. REQUIREMENTS  Macro that runs only in the draft environment  User selects the desired dimensions depending on which type of dimension. Select all critical dimensions then run the macro to mark the selected dimensions. Repeat process for major and minor dimensions.  Critical dimensions marked with  Major dimensions marked with  Minor dimensions marked with © Siemens AG 2012. All Rights Reserved.Page 12 Siemens PLM Software
  13. 13. Writing .NET Applications for Solid EdgeSeven General Steps To Create A Program  Open a new Project  Add References  Create Forms  Place Controls on Forms  Set Properties for Forms and Controls  Write code  Test and Debug code  Create executable and deploy © Siemens AG 2012. All Rights Reserved.Page 13 Siemens PLM Software
  14. 14. Create a new project © Siemens AG 2012. All Rights Reserved.Page 14 Siemens PLM Software
  15. 15. Writing .NET Applications for Solid EdgeConfiguring Visual Studio .NET for Solid Edge Programming What’s involved?  Not much actually  We still have to reference Solid Edge .dll’s, just in a different way What happens when we reference a Solid Edge .dll from Visual Studio (VB).NET?  Visual Studio .NET uses the Type Library Importer (Tlbimp.exe), to create a new .NET .dll that you can use in your project  This new .NET .dll contains the Runtime Callable Wrappers (RCW) that we will use when writing .NET code  Depending on Solid Edge COM API changes, this .NET interop dll may or may not work from version to version  The .NET version of the Solid Edge .dll must be deployed with your application © Siemens AG 2012. All Rights Reserved.Page 15 Siemens PLM Software
  16. 16. Adding the Solid Edge References © Siemens AG 2012. All Rights Reserved.Page 16 Siemens PLM Software
  17. 17. Adding the Solid Edge References © Siemens AG 2012. All Rights Reserved.Page 17 Siemens PLM Software
  18. 18. Result of adding the Solid Edge ReferencesAfter building the solution. Here is what you get…. So where are the Interop DLLs previously discussed? © Siemens AG 2012. All Rights Reserved.Page 18 Siemens PLM Software
  19. 19. New “feature” in VS 2010 VB 2010 has the ability to embed the InteropsThis is “handy” but is it a goodIdea?Development says still a good ideato generate unique interops andreference those and to not embed! © Siemens AG 2012. All Rights Reserved. Page 19 Siemens PLM Software
  20. 20. Generating Unique InteropsTool delivered with SolidEdgeI generate a bat file for each Solid Edge macro I write and save it to thesolution folder. © Siemens AG 2012. All Rights Reserved.Page 20 Siemens PLM Software
  21. 21. Generating Unique InteropsDelivered in the Solid Edge SDKtools folder GenEdgeInteropAssemblies.bat First argument  "C:Program FilesSolid Edge ST5Program“ - where you have SE loaded Second argument  "C:_WorkEventsDev Day SE University 2012Automating SE basics with .NETSampleSampleInterops“ - the location were the generated interop DLLs will be placed Third argument  Sample - This should be a unique label. I typically match the macro name © Siemens AG 2012. All Rights Reserved.Page 21 Siemens PLM Software
  22. 22. Generating Unique InteropsResulting uniquely name Interop DLLs © Siemens AG 2012. All Rights Reserved.Page 22 Siemens PLM Software
  23. 23. How to reference the unique Interop DLLsRun the Add Reference command and select the necessary interops © Siemens AG 2012. All Rights Reserved.Page 23 Siemens PLM Software
  24. 24. Results © Siemens AG 2012. All Rights Reserved.Page 24 Siemens PLM Software
  25. 25. Creating Forms © Siemens AG 2012. All Rights Reserved.Page 25 Siemens PLM Software
  26. 26. Add Code If you automate Solid Edge from an external (out-of-proc) application, you may receive one of the following errors: Application is busy (RPC_E_CALL_REJECTED 0x80010001) Call was rejected by callee (RPC_E_SERVERCALL_RETRYLATER 0x8001010A)These errors occur due to threading contention issues between automation clientsand Solid Edge. They can be handled by implementing the OleMessageFilter errorhandlers in your automation application. © Siemens AG 2012. All Rights Reserved. Page 26 Siemens PLM Software
  27. 27. Add CodeMaking your macro connect to or start Solid Edge © Siemens AG 2012. All Rights Reserved.Page 27 Siemens PLM Software
  28. 28. Add Code © Siemens AG 2012. All Rights Reserved.Page 28 Siemens PLM Software
  29. 29. © Siemens AG 2012. All Rights Reserved.Page 29 Siemens PLM Software
  30. 30. TipsTry, Catch & FinallyVB now supports structured exception handling, which helps you createand maintain programs with robust, comprehensive error handlers © Siemens AG 2012. All Rights Reserved.Page 30 Siemens PLM Software
  31. 31. TipsAn executable created with VB .NET 2003 - 2008 because of .NET securityissues can not be run across a network drive because of trust. • Must tell each client the macro is trusted!• With VB .NET 2010 this has been lifted provided you are Framework 4.0 based You can again store all your SE macros on a mapped network drive to simplify deployment of fixes or enhancements to your macros to all your customers! © Siemens AG 2012. All Rights Reserved.Page 31 Siemens PLM Software
  32. 32. TipsIn automation situations where a client is keeping Solid Edge extremelybusy, Solid Edge will not have an opportunity to perform backgroundtasks. Depending on the automation scenario, this could mean that certainobjects may not be in an expected state.One of the most important tasks that DoIdle() performs is to ensure that aSolidEdgeDocument gets fully released after SolidEdgeDocument.Close iscalled. This is significant because even though SolidEdgeDocument.Closeis called, the calling client is still holding a reference to the COM object viaIUnknown.AddRef(). It is recommended that DoIdle() be called after anydocument is closed if the client that closed the document is going to domore processing before returning control to Solid Edge. © Siemens AG 2012. All Rights Reserved.Page 32 Siemens PLM Software
  33. 33. TipsGeneral rule of thumb which reference to use Solid Edge Framework Type Library- All APIs for functionality common across all environments at the document level Solid Edge FrameworkSupport Type Library- All APIs for functionality common across all environments for 2D elements (lines, dimensons, boundaries,etc) Solid Edge Geometry Type Library - All APIs for functionality regarding both 2D and 3D elements ( body,face,curve,etc.) Solid Edge Part Type Library – All APIs for functionality specific to the Part and Sheetmetal environments Solid Edge Assembly Type Library - All APIs for functionality specific to the Assembly environment Solid Edge Draft Type Library - All APIs for functionality specific to the DRAFT environment Solid Edge Constants Type Library - All constants example igRight, igUnitDistance, etc Solid Edge Revision Manager Object Library - All APIs for functionality specific to insight connect/revision manager © Siemens AG 2012. All Rights Reserved.Page 33 Siemens PLM Software
  34. 34. TipsGeneral rule of thumb which reference to use - Continued Solid Edge Install Data Library - lightweight API to determine Solid Edge information such as path version, etc. Solid Edge File Properties Object Library – Lightweight API to get read/write access to a Solid Edge document’s file properties Solid Edge Part Viewer Control – This is an OCX control that can be used to view SE document Solid Edge Web Parts 1.0 Type Library – This is an API to get access to certain Sharepoint related functionality © Siemens AG 2012. All Rights Reserved.Page 34 Siemens PLM Software
  35. 35. TipsKeep commonly used functions and sub routines in your SE macrotemplate….http://www.codeproject.com/Articles/88957/Write-Templates-for-Visual-Studio-2010 This is very useful… As I write little apps, I come across things I find myself having to code over and over again. As I encounter these, I’ll update my VB 2010 .NET template as shown in the above link!!! © Siemens AG 2012. All Rights Reserved.Page 35 Siemens PLM Software
  36. 36. TipsKeep common subroutines and functions in a dll 1 common source…. If need to make a change then ALL your customization that references this DLL can automatically recognize any changes/enhancements.Add the code to a class library project, build it and then reference it so allFunctions and subroutines can be called from your other customization projects © Siemens AG 2012. All Rights Reserved.Page 36 Siemens PLM Software
  37. 37. TipsAdd a reference to your dll housing your common functions andsubroutines © Siemens AG 2012. All Rights Reserved.Page 37 Siemens PLM Software
  38. 38. Tips © Siemens AG 2012. All Rights Reserved.Page 38 Siemens PLM Software
  39. 39. TipsAdd your functions to your solution © Siemens AG 2012. All Rights Reserved.Page 39 Siemens PLM Software
  40. 40. TipsHow to call your DLL © Siemens AG 2012. All Rights Reserved.Page 40 Siemens PLM Software
  41. 41. Tips © Siemens AG 2012. All Rights Reserved.Page 41 Siemens PLM Software
  42. 42. TipsOnline templates © Siemens AG 2012. All Rights Reserved.Page 42 Siemens PLM Software
  43. 43. Thank You!Questions? #SEU12
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×