{"id":7399,"date":"2014-07-14T10:41:23","date_gmt":"2014-07-14T17:41:23","guid":{"rendered":"https:\/\/blogs.plm.automation.siemens.com\/t5\/Solid-Edge-Blog\/Automation-Part-Configurator\/ba-p\/37112"},"modified":"2026-03-26T07:30:19","modified_gmt":"2026-03-26T11:30:19","slug":"automation-part-configurator","status":"publish","type":"post","link":"https:\/\/blogs.sw.siemens.com\/solidedge\/automation-part-configurator\/","title":{"rendered":"Automation: Part Configurator"},"content":{"rendered":"<p><P>This article takes technique learnt in&nbsp;<a href=\"https:\/\/blogs.plm.automation.siemens.com\/t5\/Solid-Edge-Blog\/Automation-Parametric-Parts\/ba-p\/36482\" target=\"_blank\" rel=\"noopener noreferrer\">the previous post<\/A> a step ahead and shows how to configure a Solid Edge model so its variants can be generated programmatically.<\/P><\/p>\n<p><P>The earlier article in the Automation series discussed how to control a parametric part from VB.Net. In this post you learn how to create variations of a part by changing the value of the suppression variables.<\/P><\/p>\n<p><P>Begin with creating a Window Form Application as explained in the <a href=\"https:\/\/blogs.plm.automation.siemens.com\/t5\/Solid-Edge-Blog\/Automation-Parametric-Parts\/ba-p\/36482\" target=\"_blank\" rel=\"noopener noreferrer\">previous article<\/A>. Add a ListBox <span class=\"lia-inline-image-display-wrapper lia-image-align-inline\" style=\"width: 58px;\"><img decoding=\"async\" src=\"http:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/8\/2019\/09\/02-28.png\" alt=\"02.png\" title=\"02.png\" \/><\/span> and a Button to the Form.<\/P><\/p>\n<p><P>Set properties for the Form, ListBox and the Button as below:<\/P><\/p>\n<p><P><SPAN style=\"text-decoration: underline;\"><STRONG>1. Form:<\/STRONG><\/SPAN><\/P><br \/>\n<P><EM>Text: <\/EM>Part Configurator<\/P><br \/>\n<P><EM>TopMost: <\/EM>True<\/P><br \/>\n<P><EM>StartPosition:<\/EM> CenterScreen<\/P><br \/>\n<P><EM>MaximizeBox:<\/EM> False<\/P><br \/>\n<P><EM>MinimizeBox:<\/EM> False<\/P><\/p>\n<p><P><SPAN style=\"text-decoration: underline;\"><STRONG>2. Button:<\/STRONG><\/SPAN><\/P><br \/>\n<P><EM>Text: <\/EM>Configure Part<\/P><br \/>\n<P><EM>Name:<\/EM> btnConfigure<\/P><\/p>\n<p><P><SPAN style=\"text-decoration: underline;\"><STRONG>3. ListBox:<\/STRONG><\/SPAN><\/P><br \/>\n<P><EM>Name: <\/EM>lstShaft<\/P><\/p>\n<p><P>With the ListBox still selected, click the ellipsis button&nbsp;<span class=\"lia-inline-image-display-wrapper lia-image-align-inline\" style=\"width: 15px;\"><img decoding=\"async\" src=\"http:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/8\/2019\/09\/03-31.png\" alt=\"03.png\" title=\"03.png\" \/><\/span> in front of the <STRONG>Items<\/STRONG> property as shown below:<\/P><\/p>\n<p><P><span class=\"lia-inline-image-display-wrapper lia-image-align-inline\" style=\"width: 578px;\"><img decoding=\"async\" src=\"http:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/8\/2019\/09\/01-25.png\" alt=\"01.png\" title=\"01.png\" \/><\/span><\/P><\/p>\n<p><P>A new dialog pops up titled &#8216;String Collection Editor&#8217;. This holds the items to be displayed in the ListBox for the user to pick.<\/P><\/p>\n<p><P>As shown above type one name on each line. These are the variations of the Shaft that the program will generate.<\/P><\/p>\n<p><P>Click OK when done and Press F5 or from the Debug menu, select Start Debugging <span class=\"lia-inline-image-display-wrapper lia-image-align-inline\" style=\"width: 11px;\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/8\/2019\/09\/05-27.png\" width=\"11\" height=\"20\" alt=\"05.png\" title=\"05.png\" \/><\/span> to preview your Part Configurator dialog.<\/P><\/p>\n<p><P>This would be the right time to add Solid Edge references if not so far as explained in this&nbsp;<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\">first article<\/A> in the Automation series.<\/P><\/p>\n<p><P><span class=\"lia-inline-image-display-wrapper lia-image-align-left\" style=\"width: 253px;\"><img decoding=\"async\" src=\"http:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/8\/2019\/09\/04-28.png\" alt=\"04.png\" title=\"04.png\" \/><\/span><\/P><br \/>\n<P>Press Ctrl+Shift+S to <EM>Save All<\/EM> files in the project.<\/P><\/p>\n<p><P>Switch to Solid Edge and create a Shaft with three features &#8211; a Taper, a Hole and a Keyway as shown below:<\/P><\/p>\n<p><P>Right click each feature in the PathFinder viz. Keyway, Taper and Hole. Each time select <EM>Add Suppression Variable<\/EM> from the context menu that appears.<\/P><\/p>\n<p><P><span class=\"lia-inline-image-display-wrapper lia-image-align-right\" style=\"width: 238px;\"><img decoding=\"async\" src=\"http:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/8\/2019\/09\/05-28.png\" alt=\"05.png\" title=\"05.png\" \/><\/span><\/P><br \/>\n<P>This adds new variables to the Variable Table one for each of the features. The value of this variable can be set to 0 to un-suppress or 1 to suppress the feature.<\/P><\/p>\n<p><P>In the Part environment, right click anywhere in the graphics area except on the model and select Variables&#8230; from the context menu to bring up the Variable Table.<\/P><\/p>\n<p><P>Note the new variables with names FeatureName_Suppress. Try changing the value of the variables from 0 to 1 and observe how the corresponding feature gets suppressed.<\/P><\/p>\n<p><P><span class=\"lia-inline-image-display-wrapper lia-image-align-left\" style=\"width: 218px;\"><img decoding=\"async\" src=\"http:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/8\/2019\/09\/06-22.png\" alt=\"06.png\" title=\"06.png\" \/><\/span><\/P><br \/>\n<P>With all three features getting suppressed the shaft appears to be a simple variant without any features as shown in image.<\/P><\/p>\n<p><P>Through the VB.Net code, we will change the value of these suppression variables to create a variation of the shaft as per user selection from the ListBox.<\/P><\/p>\n<p><P>Switch to Visual Studio using Ctrl+Tab or Win+Tab.<\/P><\/p>\n<p><P>&nbsp;Double-click anywhere on the Form except on any of the controls. This will open the code window with the cursor placed inside the Sub for Form_Load. Code placed here is executed when the program starts i.e. when the Form loads.<\/P><\/p>\n<p><P>Press Ctrl+Home to go to the top of the code window and add the following lines:<\/P><\/p>\n<p><PRE>Imports System.Runtime.InteropServices<br \/>\nImports SolidEdgeFramework<br \/>\nImports SolidEdgePart<BR \/><BR \/>Public Class Form1<\/PRE><br \/>\n<P>The meaning, importance and use of these lines has already been explained in the previous articles.<\/P><\/p>\n<p><P>Also add variables for Solid Edge and variables collection as explained in the <a href=\"https:\/\/blogs.plm.automation.siemens.com\/t5\/Solid-Edge-Blog\/Automation-Parametric-Parts\/ba-p\/36482\" target=\"_blank\" rel=\"noopener noreferrer\">previous article<\/A>:<\/P><\/p>\n<p><PRE>Public Class Form1<\/p>\n<p>  Dim oApp As SolidEdgeFramework.Application<br \/>\n  Dim oVars As SolidEdgeFramework.Variables<\/PRE><\/p>\n<p><P>Place the cursor back into the Form_Load Sub and add lines as below:<\/P><\/p>\n<p><PRE>Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load<br \/>\n  oApp = Marshal.GetActiveObject(&#8220;SolidEdge.Application&#8221;)<BR \/>&nbsp; oVars = oApp.ActiveDocument.Variables<BR \/>  <BR \/>  <STRONG>lstShaft.SelectedIndex = 0<\/STRONG><br \/>\nEnd Sub<\/PRE><br \/>\n<P>The first two lines for the oApp = Marshal&#8230; and oVars = oApp&#8230; are already explained in the <a href=\"https:\/\/blogs.plm.automation.siemens.com\/t5\/Solid-Edge-Blog\/Automation-Parametric-Parts\/ba-p\/36482\" target=\"_blank\" rel=\"noopener noreferrer\">previous post<\/A>.<\/P><\/p>\n<p><P>lstShaft is the name of the ListBox on the Form. A ListBox has items in it displayed when the program runs.<\/P><\/p>\n<p><P>Each item has an index number assigned internally. The first item in the ListBox has an index number of 0 while the second item that appears in the ListBox has an index of 1 and so on.<\/P><\/p>\n<p><P><span class=\"lia-inline-image-display-wrapper lia-image-align-right\" style=\"width: 293px;\"><img decoding=\"async\" src=\"http:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/8\/2019\/09\/07-20.png\" alt=\"07.png\" title=\"07.png\" \/><\/span><\/P><br \/>\n<P>The SelectedIndex property of the ListBox named lstShaft means the index number of the item currently selected.<\/P><\/p>\n<p><P>By setting the value of this property to 0 we specify that the first item in the ListBox be selected. Press F5 again to check this upon which the Form appears as shown in image.<\/P><\/p>\n<p><P>The zeroth item i.e the first item in the list is selected automatically.<\/P><\/p>\n<p><P>If the user selects a variant from the list by clicking it, the SelectedIndex property changes.<\/P><\/p>\n<p><P>The new SelectedIndex value can be checked via the Button on the Form and accordingly the shaft can be configured to render the selected variant in Solid Edge.<\/P><\/p>\n<p><P>Double-click the button <EM>Configure Part<\/EM> and type the following:<\/P><\/p>\n<p><P><STRONG>If lstShaft.SelectedIndex = 1 Then<\/STRONG> and press &lt;ENTER&gt;. The <STRONG>End If<\/STRONG> line will be added automatically.<\/P><\/p>\n<p><P>Complete the code as below:<\/P><\/p>\n<p><PRE>If lstShaft.SelectedIndex = 1 Then<br \/>\n  oVars.Edit(&#8220;Taper_Suppress&#8221;, 0)<br \/>\nEnd If<\/p>\n<p>If lstShaft.SelectedIndex = 2 Then<br \/>\n  oVars.Edit(&#8220;Keyway_Suppress&#8221;, 0)<br \/>\nEnd If<\/p>\n<p>oApp.ActiveDocument.Recompute()<\/PRE><\/p>\n<p><P>The second item with text <EM>Tapered Shaft<\/EM> has the index of 1. If this is selected by user, the SelectedIndex value is 1. If this is so, change the corresponding value of its suppression variable Taper_Suppress to 0 so as to un-suppress it in Solid Edge.<\/P><\/p>\n<p><P>This will create a tapered shaft when the button is clicked.<\/P><\/p>\n<p><P>Similarly, if the SelectedIndex is 2, it means the user has picked the item Shaft with Keyway and to create this variant, the Keyway needs to be un-suppressed by setting its Suppress variable to 0.<\/P><\/p>\n<p><P>This will create a Shaft with a keyway when the button is clicked.<\/P><\/p>\n<p><P>Complete the code as below:<\/P><\/p>\n<p><PRE>        If lstShaft.SelectedIndex = 1 Then<br \/>\n            oVars.Edit(&#8220;Taper_Suppress&#8221;, 0)<br \/>\n        End If<\/p>\n<p>        If lstShaft.SelectedIndex = 2 Then<br \/>\n            oVars.Edit(&#8220;Keyway_Suppress&#8221;, 0)<br \/>\n        End If<\/p>\n<p>        If lstShaft.SelectedIndex = 3 Then<br \/>\n            oVars.Edit(&#8220;Hole_Suppress&#8221;, 0)<br \/>\n        End If<\/p>\n<p>        If lstShaft.SelectedIndex = 4 Then<br \/>\n            oVars.Edit(&#8220;Taper_Suppress&#8221;, 0)<br \/>\n            oVars.Edit(&#8220;Keyway_Suppress&#8221;, 0)<br \/>\n        End If<\/p>\n<p>        If lstShaft.SelectedIndex = 5 Then<br \/>\n            oVars.Edit(&#8220;Taper_Suppress&#8221;, 0)<br \/>\n            oVars.Edit(&#8220;Hole_Suppress&#8221;, 0)<br \/>\n        End If<\/p>\n<p>        If lstShaft.SelectedIndex = 6 Then<br \/>\n            oVars.Edit(&#8220;Taper_Suppress&#8221;, 0)<br \/>\n            oVars.Edit(&#8220;Keyway_Suppress&#8221;, 0)<br \/>\n            oVars.Edit(&#8220;Hole_Suppress&#8221;, 0)<br \/>\n        End If<BR \/><BR \/>        oApp.ActiveDocument.Recompute()<\/PRE><\/p>\n<p><P>Note that, to create a variation where two or more features need to be un-suppressed, call the oVars.Edit method twice or those many times &#8211; simple as that.<\/P><\/p>\n<p><P>It is customary to copy-paste repeating code.<\/P><\/p>\n<p><P><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\/tip-1.png\" alt=\"tip.png\" title=\"tip.png\" \/><\/span><\/P><br \/>\n<P><STRONG>Tip:<\/STRONG> In Visual Studio, you need not select an entire line to copy it. Just place the cursor on the line to copy and press Ctrl+C, the line gets copied.<\/P><\/p>\n<p><P>Test your program by pressing F5 and selecting various items from the ListBox followed by pressing the Configure Part button.<\/P><\/p>\n<p><P>Solid Edge should update by unsuppressing feature(s) as per the selection.<\/P><\/p>\n<p><P>By now you must have noticed that after creating a variant &#8211; Tapered Shaft with Hole and Keyway &#8211; followed by creating any other variant, say &#8211; a Shaft with a Hole &#8211; it does not update the shaft model.<\/P><\/p>\n<p><P><EM>In the next installment, learn:<\/EM><\/P><br \/>\n<P>1. How to handle this situation.<\/P><br \/>\n<P>2. About the <STRONG>Select Case<\/STRONG> statement which makes the program run faster and more efficiently.<\/P><\/p>\n<p><P>The completed code files are not provided purposely with this post, I would insist you try out the steps and build your own version of the program.<\/P><\/p>\n<p><P>Should you face any problems with coding, the Solid Edge Dev Forum is a&nbsp;<a href=\"https:\/\/blogs.plm.automation.siemens.com\/t5\/Solid-Edge-Developer-Forum\/bd-p\/SEDeveloperForum\" target=\"_blank\" rel=\"noopener noreferrer\">click<\/A> away.<\/P><br \/>\n<P>Or simply post a <a href=\"https:\/\/blogs.plm.automation.siemens.com\/t5\/forums\/postpage\/board-id\/SEDeveloperForum\" target=\"_blank\" rel=\"noopener noreferrer\">new message<\/A>.<\/P><\/p>\n<p><P>-Tushar Suradkar<\/P><br \/>\n<P><a href=\"http:\/\/surfandcode.blogspot.in\/2014\/01\/index-of-all-tutorials-on-this-solid.html\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">http:\/\/surfandcode.blogspot.in<\/A><\/P><br \/>\n<P><a href=\"http:\/\/www.cadvertex.com\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">www.cadvertex.com<\/A><\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article takes technique learnt in&nbsp;the previous post a step ahead and shows how to configure a Solid Edge model so its variants can be generated programmatically. <\/p>\n<p> The earlier arti&#8230;<\/p>\n","protected":false},"author":42979,"featured_media":7427,"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-7399","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\/tip-1.png","_links":{"self":[{"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/posts\/7399","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=7399"}],"version-history":[{"count":10,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/posts\/7399\/revisions"}],"predecessor-version":[{"id":7428,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/posts\/7399\/revisions\/7428"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/media\/7427"}],"wp:attachment":[{"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/media?parent=7399"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/categories?post=7399"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/tags?post=7399"},{"taxonomy":"industry","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/industry?post=7399"},{"taxonomy":"product","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/product?post=7399"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/coauthors?post=7399"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}