Hide Table of Contents

Start, Update, and Stop Progress Indicator Example (C#)

This example shows how to create, start, update, and stop a progress indicator on the system task bar.

//----------------------------------------------------------------------------
// Preconditions:
// 1. Create a C# macro in SOLIDWORKS called ManipulatePB_CSharp.
// 2. Right-click the macro project name in the Project Explorer and click
//    Add > Windows Form
.
// 3. Click Add.
// 4. Modify Form1.cs [Design] to look like this:

   

// 5. Copy Forms - Form1 into Form1.cs.
// 6. Modify control_name in the control_name_Click subroutine names to
//    match your form.
// 7. Copy
SolidWorksMacro into SolidWorksMacro.cs.
//
// Postconditions: 
// 1. Shows a dialog box.
// 2. Click Start.
//    * A progress indicator appears on the SOLIDWORKS icon on the
//      system taskbar.
//    * The progress indicator increments to 100% completion.
// 3. Click Update repeatedly to increment the progress indicator in steps of
//    10.
// 4. Inspect the Immediate window to see the return code after each update.
// 5. Type a new title and click Update Title.
//    * The progress indicator title changes in the SOLIDWORKS status bar.
// 6. Click Stop to remove the progress indicator from SOLIDWORKS.
// 7. Click Exit to close the dialog box.
// ---------------------------------------------------------------------------

Forms - Form1

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using Microsoft.VisualBasic;
 
namespace ManipulateUserPB_CSharp.csproj
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        UserProgressBar pb;
        int Position;
        int lRet;
        bool retVal;
        bool boolstatus;
        public SldWorks swApp;
 
        public void cmdExit_Click(System.Object sender, System.EventArgs e)
        {
            this.Close();
        }


        public void cmdPBTitle_Click(System.Object sender, System.EventArgs e)
        {
            retVal = pb.UpdateTitle(textBox1.Text);
        }


        public void cmdStartPB_Click(System.Object sender, System.EventArgs e)
        {
            boolstatus = pb.Start(0, 160, "Status");
            while (!(Position == 160)) {
                Position = Position + 10;
                lRet = pb.UpdateProgress(Position);
            }
            Position = 0;
        }


        public void cmdStopPB_Click(System.Object sender, System.EventArgs e)
        {
            pb.End();
        }


        public void Form1_Initialize(System.Object sender, System.EventArgs e)
        {
            swApp = (SldWorks)System.Runtime.InteropServices.Marshal.GetActiveObject("SldWorks.Application");
            retVal = swApp.GetUserProgressBar(out pb);
        }


        public void cmdUpdatePB_Click(System.Object sender, System.EventArgs e)
        {
            Position = Position + 10;
            if ((Position == 160))
                Position = 0;
            lRet = pb.UpdateProgress(Position);
            if (lRet != 2) {
                Debug.Print(" Result " + lRet);
            } else {
                MessageBox.Show(" User pressed Esc to cancel "" API");
                pb.End();
            }
        }


        private void TextBox1_TextChanged(System.Object sender, System.EventArgs e)
        {
        }

    }
}

Back to top

SolidWorksMacro

using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
 
namespace ManipulateUserPB_CSharp.csproj
{
    public partial class SolidWorksMacro
    {
 
        System.Windows.Forms.Form aForm;
        public void Main()
        {
            aForm = new Form1();
            aForm.ShowDialog();
        }
 
        /// <summary>
        ///  The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
        public SldWorks swApp;
    }
}

Back to top

 

 



Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Start, Update, and Stop Progress Indicator Example (C#)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:




x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2015 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.