Hide Table of Contents

Create PropertyManager Page Example (C#)

This example shows how to create a PropertyManager page that contains two selection boxes, a combo box,

and a list box. This example also shows how to handle focus events for these controls.

 

NOTE: If the model is an assembly and it contains multiple components and you want to allow the user to

select edges, faces, or vertices, then you must specify swSelCOMPSDONTOVERRIDE as an element of

SelType for the ISldWorks::SetSelectionFilters method. Otherwise, if the user attempts to select an edge,

face, or vertex, then the entire component might get selected and not the edge, face, or vertex.

This example demonstrates how to specify the elements for SelType.

 

//-------------------------------------------------------------------------

// Preconditions:

// 1  Copy Modules - Main to your project.

// 2. Copy Class Modules - clsPropMgr to a class in your project.

// 3. Add the SolidWorks.Interop.swpublished primary interop assembly

//    reference (right-click the name of project, select Add Reference,

//    and select SolidWorks.Interop.swpublished on the .NET tab.)

// 4. Ensure that the namespace and class names in the sample code

//    match that of your C# project.

// 5. Ensure that the assembly document opened by the macro exists.

// 6. Run the macro to open the assembly document and PropertyManager page.

//

// Postconditions:

//   A PropertyManager page called Comps is created. Comps contains a

//   selection box where the user's selections are shown, a drop-down

//   combo box where Value 2 is selected, and a list box where

//   Value 1 is selected.

//

//   Examine the contents of Comps and the Immediate Window as

//   you perform these steps:  

//     1. Click a component in the assembly to add to the first

//        selection box.

//     2. Observe, but do not move, the cursor.

//     3. Press the right-mouse button.

//     4. Click a component in the assembly to add to the second

//        selection box.

//     5. Click Value 4 in the list box at the bottom of Comps.

//     6. Click Value 1 in the list box at the bottom of Comps.

//     7. Click the first selection box.

//     8. Close the PropertyManager page.

//

// NOTE:

//   *  After running this macro, select the

//      Tools > Options > System Options > Stop VSTA debugger

//      on macro exit checkbox.

//   *  Because the assembly document is used elsewhere,

//      do not save any changes when closing the document.

//---------------------------------------------------------------------------

// Modules - Main

using SolidWorks.Interop.sldworks;

using SolidWorks.Interop.swconst;

using System;

namespace CreatePropertyManagerPageExample_CSharp.csproj

{

    partial class SolidWorksMacro

    {

        public ModelDoc2 Part;

        public clsPropMgr pm;

        public void Main()

        {

            int openDocErrors = 0;

            int openDocWarnings = 0;

 

            swApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swStopDebuggingVstaOnExit, false);

            Part = swApp.OpenDoc6("c:\\Program Files\\SolidWorks Corp\\SolidWorks\\samples\\tutorial\\advdrawings\\bladed shaft.sldasm", (int)swDocumentTypes_e.swDocASSEMBLY, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref openDocErrors, ref openDocWarnings);

 

            //Create a new instance of the PropertyManager class

            pm = new clsPropMgr(swApp);

            pm.Show();

        }

        public SldWorks swApp;

    }

}

Back to top

// Class Modules - clsPropMgr

using SolidWorks.Interop.sldworks;

using SolidWorks.Interop.swconst;

using SolidWorks.Interop.swpublished;

using System;

using System.Runtime.InteropServices;

using System.Diagnostics;

namespace CreatePropertyManagerPageExample_CSharp.csproj

{

    [ComVisibleAttribute(true)]

    public class clsPropMgr : PropertyManagerPage2Handler9

    {

        //General objects required for the PropertyManager page

        PropertyManagerPage2 pm_Page;

        PropertyManagerPageGroup pm_Group;

        PropertyManagerPageSelectionbox pm_Selection;

        PropertyManagerPageSelectionbox pm_Selection2;

        PropertyManagerPageCombobox pm_Combo;

        PropertyManagerPageListbox pm_List;

 

        //Each object in the page needs a unique ID

        const int GroupID = 1;

        const int SelectionID = 3;

        const int ComboID = 4;

        const int ListID = 5;

        const int Selection2ID = 6;

        public void Show()

        {

            pm_Page.Show2(0);

        }

        //The following runs when a new instance

        //of the class is created

        public clsPropMgr(SldWorks swApp)

        {

            string PageTitle = null;

            string caption = null;

            string tip = null;

            long options = 0;

            int longerrors = 0;

            int controlType = 0;

            int alignment = 0;

            string[] listItems = new string[4];

 

            //Set the variables for the page

            PageTitle = "Comps";

            options = (int)swPropertyManagerButtonTypes_e.swPropertyManager_OkayButton + (int)swPropertyManagerButtonTypes_e.swPropertyManager_CancelButton + (int)swPropertyManagerPageOptions_e.swPropertyManagerOptions_LockedPage + (int)swPropertyManagerPageOptions_e.swPropertyManagerOptions_PushpinButton;

 

            //Create the PropertyManager page

            pm_Page = (PropertyManagerPage2)swApp.CreatePropertyManagerPage(PageTitle, (int)options, this, ref longerrors);

 

            //Make sure that the page was created properly

            if (longerrors == (int)swPropertyManagerPageStatus_e.swPropertyManagerPage_Okay)

            {

                //Begin adding the controls to the page

 

                //Create the group box

                caption = "Comps";

                options = (int)swAddGroupBoxOptions_e.swGroupBoxOptions_Visible + (int)swAddGroupBoxOptions_e.swGroupBoxOptions_Expanded;

                pm_Group = (PropertyManagerPageGroup)pm_Page.AddGroupBox(GroupID, caption, (int)options);

                

//Create two selection boxes

                controlType = (int)swPropertyManagerPageControlType_e.swControlType_Selectionbox;

                caption = "";

                

                alignment = (int)swPropertyManagerPageControlLeftAlign_e.swControlAlign_Indent;

                options = (int)swAddControlOptions_e.swControlOptions_Visible + (int)swAddControlOptions_e.swControlOptions_Enabled;

                tip = "Select an edge, face, vertex, solid body, or a component";

                pm_Selection = (PropertyManagerPageSelectionbox)pm_Group.AddControl(SelectionID, (short)controlType, caption, (short)alignment, (int)options, tip);

                pm_Selection2 = (PropertyManagerPageSelectionbox)pm_Group.AddControl(Selection2ID, (short)controlType, caption, (short)alignment, (int)options, tip);

 

                swSelectType_e[] filters = new swSelectType_e[7];

                filters[0] = swSelectType_e.swSelEDGES;

                filters[1] = swSelectType_e.swSelREFEDGES;

                filters[2] = swSelectType_e.swSelFACES;

                filters[3] = swSelectType_e.swSelVERTICES;

                filters[4] = swSelectType_e.swSelSOLIDBODIES;

                filters[5] = swSelectType_e.swSelCOMPONENTS;

                filters[6] = swSelectType_e.swSelCOMPSDONTOVERRIDE;

 

                object filterObj = null;

                filterObj = filters;

 

                pm_Selection.SingleEntityOnly = false;

                pm_Selection.AllowMultipleSelectOfSameEntity = true;

                pm_Selection.Height = 50;

                pm_Selection.SetSelectionFilters(filterObj);

 

                pm_Selection2.SingleEntityOnly = false;

                pm_Selection2.AllowMultipleSelectOfSameEntity = true;

                pm_Selection2.Height = 50;

                pm_Selection2.SetSelectionFilters(filterObj);

 

                // Create a combo box

                controlType = (int)swPropertyManagerPageControlType_e.swControlType_Combobox;

                caption = "";

                alignment = (int)swPropertyManagerPageControlLeftAlign_e.swControlAlign_Indent;

                options = (int)swAddControlOptions_e.swControlOptions_Visible + (int)swAddControlOptions_e.swControlOptions_Enabled;

                tip = "Select a value from the drop-down";

                pm_Combo = (PropertyManagerPageCombobox)pm_Group.AddControl(ComboID, (short)controlType, caption, (short)alignment, (int)options, tip);

                if ((pm_Combo != null))

                {

                    pm_Combo.Height = 50;

                    listItems[0] = "Value 1";

                    listItems[1] = "Value 2";

                    listItems[2] = "Value 3";

                    listItems[3] = "Value 4";

                    pm_Combo.AddItems(listItems);

                    pm_Combo.CurrentSelection = 0;

                }

 

                // Create a list box

                controlType = (int)swPropertyManagerPageControlType_e.swControlType_Listbox;

                caption = "";

                alignment = (int)swPropertyManagerPageControlLeftAlign_e.swControlAlign_Indent;

                options = (int)swAddControlOptions_e.swControlOptions_Visible + (int)swAddControlOptions_e.swControlOptions_Enabled;

                tip = "Multi-select values from the list box";

                pm_List = (PropertyManagerPageListbox)pm_Group.AddControl(ListID, (short)controlType, caption, (short)alignment, (int)options, tip);

                

                if ((pm_List != null))

                {

                    pm_List.Style = (int)swPropMgrPageListBoxStyle_e.swPropMgrPageListBoxStyle_MultipleItemSelect;

                    pm_List.Height = 50;

                    listItems[0] = "Value 1";

                    listItems[1] = "Value 2";

                    listItems[2] = "Value 3";

                    listItems[3] = "Value 4";

                    pm_List.AddItems(listItems);

                    pm_List.SetSelectedItem(1, true);

                }

            }

            else

            {

                //If the page is not created

                System.Windows.Forms.MessageBox.Show("An error occurred while attempting to create the " + "PropertyManager Page");

            }

        }

 

#region IPropertyManagerPage2Handler9 Members

        void IPropertyManagerPage2Handler9.AfterActivation()

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler9.AfterClose()

        {

            throw new Exception("The method or operation is not implemented.");

        }

        int IPropertyManagerPage2Handler9.OnActiveXControlCreated(int Id, bool Status)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler9.OnButtonPress(int Id)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler9.OnCheckboxCheck(int Id, bool Checked)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler9.OnClose(int Reason)

        {

            if (Reason == (int)swPropertyManagerPageCloseReasons_e.swPropertyManagerPageClose_Cancel)

            {

                //Do something when the cancel button is clicked

            }

            else if (Reason == (int)swPropertyManagerPageCloseReasons_e.swPropertyManagerPageClose_Okay)

            {

                //Do something else when the OK button is clicked

            }

        }

        void IPropertyManagerPage2Handler9.OnComboboxEditChanged(int Id, string Text)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler9.OnComboboxSelectionChanged(int Id, int Item)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler9.OnGainedFocus(int Id)

        {

            short[] varArray = null;

            Debug.Print("Control box " + Id + " has gained focus");

            varArray = (short[])pm_List.GetSelectedItems();

            pm_Combo.CurrentSelection = varArray[0];

        }

        void IPropertyManagerPage2Handler9.OnGroupCheck(int Id, bool Checked)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler9.OnGroupExpand(int Id, bool Expanded)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        bool IPropertyManagerPage2Handler9.OnHelp()

        {

            throw new Exception("The method or operation is not implemented.");

        }

        bool IPropertyManagerPage2Handler9.OnKeystroke(int Wparam, int Message, int Lparam, int Id)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler9.OnListboxSelectionChanged(int Id, int Item)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler9.OnLostFocus(int Id)

        {

            Debug.Print("Control box " + Id + " has lost focus");

        }

        bool IPropertyManagerPage2Handler9.OnNextPage()

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler9.OnNumberboxChanged(int Id, double Value)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler9.OnOptionCheck(int Id)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler9.OnPopupMenuItem(int Id)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler9.OnPopupMenuItemUpdate(int Id, ref int retval)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        bool IPropertyManagerPage2Handler9.OnPreview()

        {

            throw new Exception("The method or operation is not implemented.");

        }

        bool IPropertyManagerPage2Handler9.OnPreviousPage()

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler9.OnRedo()

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler9.OnSelectionboxCalloutCreated(int Id)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler9.OnSelectionboxCalloutDestroyed(int Id)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler9.OnSelectionboxFocusChanged(int Id)

        {

            Debug.Print("The focus has moved to selection box " + Id);

        }

        void IPropertyManagerPage2Handler9.OnSelectionboxListChanged(int Id, int Count)

        {

            // Move focus to next selection box if right-mouse button pressed

            pm_Page.SetCursor((int)swPropertyManagerPageCursors_e.swPropertyManagerPageCursors_Advance);

            Debug.Print("The list in selection box " + Id + " has changed");

        }

        void IPropertyManagerPage2Handler9.OnSliderPositionChanged(int Id, double Value)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler9.OnSliderTrackingCompleted(int Id, double Value)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        bool IPropertyManagerPage2Handler9.OnSubmitSelection(int Id, object Selection, int SelType, ref string ItemText)

        {

// This method must return true for selections to occur

            return true;

        }

        bool IPropertyManagerPage2Handler9.OnTabClicked(int Id)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler9.OnTextboxChanged(int Id, string Text)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler9.OnUndo()

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler9.OnWhatsNew()

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler9.OnListboxRMBUp(int Id, int PosX, int PosY)
        {
            throw new Exception("The method or operation is not implemented.");
        }

   public int IPropertyManagerPage2Handler9.OnWindowFromHandleControlCreated(int Id, bool Status)
   {
        throw new Exception("The method or operation is not implemented.");
   }

   void IPropertyManagerPage2Handler9.OnNumberBoxTrackingCompleted(int Id, double Value)
   {
        throw new Exception("The method or operation is not implemented.");
   }

        #endregion

    }

}

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:   Create PropertyManager Page 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) 2012 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.