{"id":5692,"date":"2014-06-11T00:58:48","date_gmt":"2014-06-11T07:58:48","guid":{"rendered":"https:\/\/blogs.plm.automation.siemens.com\/t5\/Solid-Edge-Blog\/First-Steps-to-Automation-Part-2\/ba-p\/32496"},"modified":"2026-03-26T07:30:34","modified_gmt":"2026-03-26T11:30:34","slug":"first-steps-to-automation-part-2","status":"publish","type":"post","link":"https:\/\/blogs.sw.siemens.com\/solidedge\/first-steps-to-automation-part-2\/","title":{"rendered":"First Steps to Automation &#8211; Part 2"},"content":{"rendered":"<p><P><a href=\"https:\/\/blogs.plm.automation.siemens.com\/t5\/Solid-Edge-Blog\/Take-the-First-Steps-to-Automation\/ba-p\/32478\" target=\"_blank\" rel=\"noopener noreferrer\">&#8230;continued from Part 1<\/A><\/P><br \/>\n<P><BR \/>Keep typing more lines as shown below:<\/P><\/p>\n<p><P><span class=\"lia-inline-image-display-wrapper lia-image-align-inline\" style=\"width: 358px;\"><img decoding=\"async\" src=\"http:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/8\/2019\/09\/08-6.png\" alt=\"08.png\" title=\"08.png\" \/><\/span><\/P><br \/>\n<P><BR \/>As evident, <FONT face=\"courier new,courier\">oDoc<\/FONT> stores the Draft Document whose type definition comes from the DraftDocument type library referenced earlier.<\/P><\/p>\n<p><P>Similarly, oSel is a variable that stores the object of type SelectSet. Though we are using the selection set in the draft document alone, selection set exist in other environment like Part and Assembly too. Hence it comes from the SolidEdgeFramework type library which hosts definitions for objects common to various Solid Edge environments.<\/P><\/p>\n<p><P>The <FONT face=\"courier new,courier\">SolidEdgeFramework.<\/FONT> prefixed to the <FONT face=\"courier new,courier\">SelectSet<\/FONT> means the later is fully defined and leaves no ambiguity to VB.Net. The prefix is also called a qualifier.<BR \/><BR \/><span class=\"lia-inline-image-display-wrapper lia-image-align-left\" style=\"width: 48px;\"><img decoding=\"async\" src=\"http:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/8\/2019\/09\/09-6.png\" alt=\"09.png\" title=\"09.png\" \/><\/span><STRONG>Note: <\/STRONG>As you type, some lists and tooltips will appear automatically. This is the <EM>Intellisense<\/EM> feature of Visual Studio. Ignore them for the time being and continue typing. Your code should now appear as below:<\/P><\/p>\n<p><P><span class=\"lia-inline-image-display-wrapper lia-image-align-inline\" style=\"width: 356px;\"><img decoding=\"async\" src=\"http:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/8\/2019\/09\/10-14.png\" alt=\"10.png\" title=\"10.png\" \/><\/span><\/P><br \/>\n<P><BR \/>Notice there are no scary formulas or number crunching so far.<\/P><br \/>\n<P>Solid Edge automation using programming is fun !! <img decoding=\"async\" id=\"cathappy\" class=\"emoticon emoticon-cathappy\" src=\"https:\/\/siemensplm.i.lithium.com\/i\/smilies\/16x16_cat-happy.png\" alt=\"Cat Happy\" title=\"Cat Happy\" \/><\/P><br \/>\n<P><STRONG>Note:<\/STRONG> Solid Edge automation using Excel is fun too &#8211; refer <a href=\"https:\/\/blogs.plm.automation.siemens.com\/t5\/Solid-Edge-Blog\/Using-Lookup-Tables-in-Solid-Edge\/ba-p\/32380\" target=\"_blank\" rel=\"noopener noreferrer\">this article<\/A> and <a href=\"https:\/\/blogs.plm.automation.siemens.com\/t5\/Solid-Edge-Blog\/Solid-Edge-Design-Optimization-using-Excel-Solver\/ba-p\/25540\" target=\"_blank\" rel=\"noopener noreferrer\">this one<\/A>.<\/P><br \/>\n<P><BR \/>Now it&#8217;s time to access objects and store their values in the variables.<BR \/>Add more lines after the line <FONT face=\"courier new,courier\" color=\"#0000FF\">Dim<\/FONT> <FONT face=\"courier new,courier\">iCount<\/FONT> <FONT face=\"courier new,courier\" color=\"#0000FF\">As Integer<\/FONT> and before the <FONT face=\"courier new,courier\" color=\"#0000FF\">End Sub<\/FONT> line:<\/P><\/p>\n<p><P><span class=\"lia-inline-image-display-wrapper lia-image-align-inline\" style=\"width: 388px;\"><img decoding=\"async\" src=\"http:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/8\/2019\/09\/11-7.png\" alt=\"11.png\" title=\"11.png\" \/><\/span><\/P><br \/>\n<P><BR \/><STRONG>\u2022<\/STRONG> <FONT face=\"courier new,courier\">oApp<\/FONT> stores the Solid Edge object.<BR \/><STRONG>\u2022<\/STRONG> <FONT face=\"courier new,courier\" color=\"#008080\">Marshal <\/FONT>comes from the namespace added at the very top of the code window that begins with <FONT face=\"courier new,courier\" color=\"#0000FF\">Imports<\/FONT>&#8230;<BR \/><STRONG>\u2022<\/STRONG> <FONT face=\"courier new,courier\" color=\"#008080\">Marshal <\/FONT>has a method called <FONT face=\"courier new,courier\">GetActiveObject<\/FONT> which uses the ProgID or Program ID of Solid Edge which is <FONT face=\"courier new,courier\" color=\"#993300\">&#8220;SolidEdge.Application&#8221;<\/FONT> and stored in the registry.<\/P><\/p>\n<p><P>At your own risk, you can search for <FONT face=\"courier new,courier\">SolidEdge.Application<\/FONT> in the Windows registry. To open the Windows Registry, press Win+R and type regedit. Associated with the Prog ID is the full path and name of the Solid Edge program i.e. Edge.exe found in the LocalServer32 node just above the Prog ID in the registry.<\/P><\/p>\n<p><P>Similar to <FONT face=\"courier new,courier\">GetActiveObject<\/FONT> is <STRONG><FONT face=\"courier new,courier\">CreateObject<\/FONT> <\/STRONG>which also takes the ProgID <FONT face=\"courier new,courier\">SolidEdge.Application<\/FONT> and launches or starts Solid Edge through VB.Net. You can use <FONT face=\"courier new,courier\">CreateObject<\/FONT> in a macro meant to be used from a desktop shortcut and not from a button inside Solid Edge.<\/P><\/p>\n<p><P>When using <FONT face=\"courier new,courier\">CreateObject<\/FONT>, additionally the <FONT face=\"courier new,courier\">Visible<\/FONT> property of Solid Edge needs to be set to <FONT face=\"courier new,courier\" color=\"#0000FF\">True <\/FONT>as below:<\/P><\/p>\n<p><P><span class=\"lia-inline-image-display-wrapper lia-image-align-inline\" style=\"width: 318px;\"><img decoding=\"async\" src=\"http:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/8\/2019\/09\/12-9.png\" alt=\"12.png\" title=\"12.png\" \/><\/span><\/P><\/p>\n<p><P><STRONG>Notes:<\/STRONG><\/P><br \/>\n<P><STRONG>\u2022<\/STRONG> CreateObject does not require <FONT face=\"courier new,courier\" color=\"#008080\">Marshal <\/FONT>or the <FONT face=\"courier new,courier\" color=\"#0000FF\">Imports <\/FONT>statement at the top of the program.<\/P><br \/>\n<P><STRONG>\u2022<\/STRONG> Don&#8217;t use <FONT face=\"courier new,courier\">CreateObject<\/FONT> in the SelCount macro.<\/P><br \/>\n<P><BR \/>Solid Edge must be running to use the SelCount macro. To check this,<\/P><br \/>\n<P><STRONG>\u2022<\/STRONG> Start the Windows Task Manager by right clicking the task bar and selecting this option.<BR \/><STRONG>\u2022<\/STRONG> Take the processes tab and Edge.exe should be listed with a description Solid Edge.<\/P><\/p>\n<p><P>Back to the code,<BR \/><STRONG>\u2022<\/STRONG> On the next line, <FONT face=\"courier new,courier\">oDoc<\/FONT> stores the <FONT face=\"courier new,courier\">ActiveDocument<\/FONT> property of <FONT face=\"courier new,courier\">oApp<\/FONT> which is none other than Solid Edge itself.<BR \/><STRONG>\u2022<\/STRONG> <FONT face=\"courier new,courier\">oApp<\/FONT> knows which is the currently active document and assigns it to <FONT face=\"courier new,courier\">oDoc<\/FONT>.<BR \/>Chances are no document is open in Solid Edge so the <FONT face=\"courier new,courier\">ActiveDocument<\/FONT> property would be blank and the program might run into an error condition.<BR \/>This will not happen if you run this macro from a button on the ribbon bar in the draft environment, so a draft document will always be available.<BR \/><BR \/><STRONG>\u2022<\/STRONG> <FONT face=\"courier new,courier\">oSel<\/FONT> stores the <FONT face=\"courier new,courier\">SelectSet<\/FONT> which is the set of selected objects in the active draft document via <FONT face=\"courier new,courier\">oDoc.SelectSet<\/FONT><BR \/><BR \/><STRONG>\u2022<\/STRONG> Finally, <FONT face=\"courier new,courier\">iCount<\/FONT> stores the number or count of selected objects.<\/P><br \/>\n<P><BR \/>Your code should now appear like this:<BR \/><BR \/><span class=\"lia-inline-image-display-wrapper lia-image-align-inline\" style=\"width: 444px;\"><img decoding=\"async\" src=\"http:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/8\/2019\/09\/13-9.png\" alt=\"13.png\" title=\"13.png\" \/><\/span><BR \/><BR \/>The last step is to actually display the count in the Status bar or PromptBar of Solid Edge.<BR \/>For this, manipulate the <FONT face=\"courier new,courier\">StatusBar<\/FONT> property of <FONT face=\"courier new,courier\">oApp<\/FONT> i.e. Solid Edge as below:<\/P><br \/>\n<P><BR \/><FONT face=\"courier new,courier\">oApp.StatusBar = iCount.ToString() + <FONT color=\"#993300\">&#8221; object(s) selected.&#8221;<\/FONT><\/FONT><BR \/><BR \/>The + sign adds up two strings:<BR \/>1. The number <FONT face=\"courier new,courier\">iCount<\/FONT> converted to string by suffixing to it the <FONT face=\"courier new,courier\">ToString()<\/FONT> function, and<BR \/>2. The string<FONT face=\"courier new,courier\" color=\"#993300\"> &#8220;object(s) selected.&#8221;<\/FONT>.<\/P><\/p>\n<p><P>The completed program should appear as below:<\/P><\/p>\n<p><P><span class=\"lia-inline-image-display-wrapper lia-image-align-inline\" style=\"width: 516px;\"><img decoding=\"async\" src=\"http:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/8\/2019\/09\/15-7.png\" alt=\"15.png\" title=\"15.png\" \/><\/span><\/P><\/p>\n<p><P>This displays a nice message in the status bar, for e.g.<\/P><\/p>\n<p><P><span class=\"lia-inline-image-display-wrapper lia-image-align-inline\" style=\"width: 452px;\"><img decoding=\"async\" src=\"http:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/8\/2019\/09\/14-9.png\" alt=\"14.png\" title=\"14.png\" \/><\/span><\/P><\/p>\n<p><P>Its time to convert the code into an executable macro. This process is called Build.<\/P><br \/>\n<P><BR \/>In Visual Studio 2010 Express if you don&#8217;t see the Build Menu.<BR \/>1. Click on Tools menu.<BR \/>2. Click on Settings.<BR \/>3. Click on Expert Settings.<BR \/>4. Click on Tools Menu, Select Options. In the dialog box, check the Show All Settings option in the bottom left.<BR \/>5. In the above dialog, now choose Projects and Solutions. Expand General. Check the option Show advanced build configurations. Click Okay.<BR \/><BR \/>From the menus, select Build &gt; Build Solution.<BR \/>Read the status bar in Visual Studio which should read &#8216;Build started&#8230;&#8217; then &#8216;Build succeeded&#8217;.<BR \/><BR \/>Go back again to Window Explorer and check the Debug folder. You should now see SelCount.exe<\/P><\/p>\n<p><P><span class=\"lia-inline-image-display-wrapper lia-image-align-left\" style=\"width: 192px;\"><img decoding=\"async\" src=\"http:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/8\/2019\/09\/16-7.png\" alt=\"16.png\" title=\"16.png\" \/><\/span>This is our macro, ready for use in Solid Edge. The exe file does not have an icon. You can use the SelCount.png file attached with this blog post and copy it to the debug folder as shown in the image besides.<\/P><br \/>\n<P><BR \/>alternatively you can use MS Paint to create a 32&#215;32 PNG, BMP or ICO file and name it same as that of the macro i.e. SelCount.<\/P><br \/>\n<P><BR \/>To assign the macro to a button on the ribbon bar in the Draft environment, follow these steps:<\/P><br \/>\n<P>1. Right-click on an existing button on the ribbon to display the context menu.<\/P><br \/>\n<P>2. Select Customize the <U>R<\/U>ibbon from the menu.<\/P><br \/>\n<P>3. In the Customize dialog, the Ribbon tab should be active.<\/P><br \/>\n<P>4. On the TreeView on the right side, expand the Home or Sketching nodes &#8211; both have the Select group.<\/P><br \/>\n<P>5. Expand the Select node and also select it.<\/P><br \/>\n<P>6. At the top on the left side, pull down the list called Choose co<U>m<\/U>mands from:<\/P><\/p>\n<p><P><span class=\"lia-inline-image-display-wrapper lia-image-align-inline\" style=\"width: 500px;\"><img decoding=\"async\" src=\"http:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/8\/2019\/09\/17-6.png\" alt=\"17.png\" title=\"17.png\" \/><\/span><\/P><\/p>\n<p><P>7. At the bottom side of the dialog, click <U>B<\/U>rowse&#8230;<\/P><br \/>\n<P>8. Pick the SelCount.exe<\/P><br \/>\n<P>9. Pick the Selcount.exe again in the left-side list in the Customize dialog.<\/P><br \/>\n<P>10. Click <U>A<\/U>dd &gt;&gt;<\/P><\/p>\n<p><P><span class=\"lia-inline-image-display-wrapper lia-image-align-inline\" style=\"width: 599px;\"><img decoding=\"async\" src=\"http:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/8\/2019\/09\/18-5.png\" alt=\"18.png\" title=\"18.png\" \/><\/span><\/P><\/p>\n<p><P>11. If you have also copied the SelCount.PNG to the same folder as the EXE, the icon will be picked up automatically and displayed.<\/P><br \/>\n<P><STRONG>Note:<\/STRONG> If you want your own icon, make a 32 x 32 PNG file using MS Paint. ICO and BMP files should also work.<\/P><br \/>\n<P>12. Right-click the SelCount.exe and select Rename or simply press F2 to rename it.<\/P><br \/>\n<P>13. Select the SelCount node in the tree and click Move Down several times to move it to the end of the list which also moves it appropriately in the ribbon group.<\/P><br \/>\n<P>14. Right-click on the SelCount node in the tree and select Small\/Large button and Text\/No text as desired.<\/P><br \/>\n<P>15. To assign a keyboard shortcut, take the Keyboard tab and follow the steps in the image below.<\/P><\/p>\n<p><P><span class=\"lia-inline-image-display-wrapper lia-image-align-inline\" style=\"width: 418px;\"><img decoding=\"async\" src=\"http:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/8\/2019\/09\/19-5.png\" alt=\"19.png\" title=\"19.png\" \/><\/span><\/P><\/p>\n<p><P>16. Close the Customize dialog. Hover the mouse cursor over the SelCount macro in the Sketching tab on the ribbon.<\/P><\/p>\n<p><P><span class=\"lia-inline-image-display-wrapper lia-image-align-left\" style=\"width: 333px;\"><img decoding=\"async\" src=\"http:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/8\/2019\/09\/20-7.png\" alt=\"20.png\" title=\"20.png\" \/><\/span><\/P><br \/>\n<P>17. Check everything appears fine and the macro works properly.<\/P><\/p>\n<p><P>Even with no object selected, the PromptBar should display<\/P><br \/>\n<P><FONT face=\"verdana,geneva\" size=\"2\">&#8216;0 object(s) selected&#8217;.<\/FONT><\/P><\/p>\n<p><P>See the attachments with this post below for the SelCount.PNG file.<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8230;continued from Part 1<br \/>\n   Keep typing more lines as shown below: <\/p>\n<p>   As evident, oDoc stores the Draft Document whose type definition comes from the DraftDocument type library refe&#8230;<\/p>\n","protected":false},"author":42979,"featured_media":5732,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spanish_translation":"","french_translation":"","german_translation":"","italian_translation":"","polish_translation":"","japanese_translation":"","chinese_translation":"","footnotes":""},"categories":[1,96],"tags":[33],"industry":[],"product":[],"coauthors":[],"class_list":["post-5692","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-news","category-tips-tricks","tag-developer"],"featured_image_url":"https:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/8\/2019\/09\/20-7.png","_links":{"self":[{"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/posts\/5692","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/users\/42979"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/comments?post=5692"}],"version-history":[{"count":14,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/posts\/5692\/revisions"}],"predecessor-version":[{"id":5733,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/posts\/5692\/revisions\/5733"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/media\/5732"}],"wp:attachment":[{"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/media?parent=5692"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/categories?post=5692"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/tags?post=5692"},{"taxonomy":"industry","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/industry?post=5692"},{"taxonomy":"product","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/product?post=5692"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/coauthors?post=5692"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}