Listing parameters in an assembly, C#

Top  Previous  Next

Here is the code, note the foreach loop.

 

       private void ListParameters_Click(object sender, EventArgs e)

       {

           Inventor.AssemblyDocument AsmDoc = m_Inventor.ActiveDocument as Inventor.AssemblyDocument;

           if (AsmDoc == null)

           {

               MessageBox.Show("This is not an assembly");

               return;

           }

 

           UserParameters UsrParams = AsmDoc.ComponentDefinition.Parameters.UserParameters;

           foreach (UserParameter UserParam in UsrParams)

           {

               string sMsg = string.Format("Found {0} with value {1} ", UserParam.Name.ToString(), UserParam.Value.ToString());

               MessageBox.Show(sMsg);

           }

       }

 

The above works for user parameters, here is the loop for model parameters:

 

           ModelParameters ModParams = AsmDoc.ComponentDefinition.Parameters.ModelParameters;

           foreach (ModelParameter ModParam in ModParams)

           {

               string sMsg = string.Format("Found model param {0} with value {1} ", ModParam.Name.ToString(), ModParam.Value.ToString());

               MessageBox.Show(sMsg);

           }

Text, images and diagrams © 2021 Owen F. Ransen. All rights reserved. (But copy the source code as much as you want!)