Hide Table of Contents

Activate PropertyManager Page Tab Example (C#)

The following code example demonstrates how SolidWorks add-ins can use IPropertyManagerPageTab.Activate to programmatically select a tab on a SolidWorks PropertyManager page.

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

// Preconditions:

// 1. Open an active assembly document containing multiple components.  

// 2. Create a clsPropMgr class module in the macro that contains the class

//    module code from this file.

// 3. Add a reference to SolidWorks <version> exposed type libraries

//    for add-in use.

//

// Postconditions:

// 1. A PropertyManager page called Materials and Dimensions

//    is created with two tabs labeled, Materials and Dimensions.

// 2. The Materials tab is programmatically selected through

//    IPropertyManagerPageTab.Activate.

// 3. The Materials tab has a selection box where user selections are shown.

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

using SolidWorks.Interop.sldworks;

using SolidWorks.Interop.swconst;

using System;

namespace ActivatePropertyManagerPageTab.csproj

{

    partial class SolidWorksMacro

   {

    

    public SldWorks swApp;

    

    public ModelDoc2 Part;

    

    public SelectionMgr SelMgr;

    

    public clsPropMgr pm;

    

    

    

    public void Main()

    {

        

        Part = (ModelDoc2)swApp.ActiveDoc;

        

        SelMgr = (SelectionMgr)Part.SelectionManager;

        

        

        //Create a new instance of the PropertyManager class

        

        

        pm = new clsPropMgr(swApp);

        

        pm.Show();

        

        

    }

    

    

    }

}

 

// ====================================================================

// Add the following class to the project

//=====================================================================

 

using System;

using System.Collections.Generic;

using System.Text;

using System.Runtime.InteropServices;

using SWPublished;

using SolidWorks.Interop.sldworks;

using SolidWorks.Interop.swconst;

namespace ActivatePropertyManagerPageTab.csproj

{

    [ComVisibleAttribute(true)]

public class clsPropMgr : PropertyManagerPage2Handler6//

{

    PropertyManagerPage2 pm_Page;

    bool ClickedCancel;

    

    

    

    public void Show()

    {

        

        pm_Page.Show();

        

    }

    

    public clsPropMgr(SolidWorks.Interop.sldworks.SldWorks swApp)

    {

        

        //General objects required for the PropertyManager page

        

        

        PropertyManagerPageTab pm_Page_Tab = default(PropertyManagerPageTab);

        

        PropertyManagerPageTab pm_Page_Tab_2 = default(PropertyManagerPageTab);

        

        PropertyManagerPageGroup pm_Group = default(PropertyManagerPageGroup);

        

        PropertyManagerPageSelectionbox pm_Selection = default(PropertyManagerPageSelectionbox);

        

        PropertyManagerPageLabel pm_Label = default(PropertyManagerPageLabel);

        

        PropertyManagerPageCombobox pm_Combo = default(PropertyManagerPageCombobox);

        

        //Each object in the page needs a unique ID

        

        const int GroupID = 1;

        

        const int LabelID = 2;

        

        const int SelectionID = 3;

        

        const int ComboID = 4;

        

        const int Tab1ID = 1;

        

        const int Tab2ID = 2;

        

        

        

        string density = null;

        

        string material = null;

        

        

        string PageTitle = null;

        

        string caption = null;

        

        string tip = null;

        

        int options = 0;

        

        int longerrors = 0;

        

        short controlType = 0;

        

        short alignment = 0;

        

        //Set the variables for the page

        

        PageTitle = "Materials and Dimensions";

        

        options = (int)swPropertyManagerPageOptions_e.swPropertyManagerOptions_OkayButton + (int)swPropertyManagerPageOptions_e.swPropertyManagerOptions_CancelButton + (int)swPropertyManagerPageOptions_e.swPropertyManagerOptions_LockedPage + (int)swPropertyManagerPageOptions_e.swPropertyManagerOptions_PushpinButton;

        

        

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

        

        // Create page tabs

        

        pm_Page_Tab = (PropertyManagerPageTab)pm_Page.AddTab(Tab1ID, "Materials", "", 0);

        pm_Page_Tab_2 = (PropertyManagerPageTab)pm_Page.AddTab(Tab2ID, "Dimensions", "", 0);

        

        // Activate the first tab

        

        pm_Page_Tab.Activate();

        

        

        //Begin adding the controls to the page tab

        

        

        //Create the group box

        

        caption = "Materials";

        

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

        

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

        

        

        

        //Create selection box

        

        controlType = (short)swPropertyManagerPageControlType_e.swControlType_Selectionbox;

        

        caption = "";

        // No caption for selection boxes

        

        alignment = (short)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, controlType, caption, alignment, options, tip);

        

        long[] filters = new long[7];

        

        filters[0] = (long)swSelectType_e.swSelEDGES;

        

        filters[1] = (long)swSelectType_e.swSelREFEDGES;

        

        filters[2] = (long)swSelectType_e.swSelFACES;

        

        filters[3] = (long)swSelectType_e.swSelVERTICES;

        

        filters[4] = (long)swSelectType_e.swSelSOLIDBODIES;

        

        filters[5] = (long)swSelectType_e.swSelCOMPONENTS;

        

        filters[6] = (long)swSelectType_e.swSelCOMPSDONTOVERRIDE;

        

        

        

        pm_Selection.SingleEntityOnly = false;

        

        pm_Selection.AllowMultipleSelectOfSameEntity = true;

        

        pm_Selection.Height = 50;

        

        pm_Selection.SetSelectionFilters(filters);

        

        

        

        //Substitute the path and filename of the bitmap

        

        //pm_Selection.SetPictureLabelByName "c:\bitmaps\part.bmp", "c:\bitmaps\part.bmp"

        

        //Else 'If the page is not created

        

        //MsgBox("An error while attempting to create the " _

        // & "PropertyManager Page", vbCritical)

        

        //End If

        

        

        

    }

    private void PropertyManagerPage2Handler6_AfterActivation()

    {

        

    }

    

    private void PropertyManagerPage2Handler6_AfterClose()

    {

        

    }

    

    

    

    

    

    private void PropertyManagerPage2Handler6_OnClose(int Reason)

    {

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

            

            //Cancel button was clicked

            

            ClickedCancel = true;

        }

        

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

            

            //OK button was clicked

            

            ClickedCancel = false;

            

        }

        

        

        //Store the density and material name values based

        

        //on the combo-box selection

        

    }

    

    

    

    

    private bool PropertyManagerPage2Handler6_OnHelp()

    {

        return false;

    }

    

    

    

    private bool PropertyManagerPage2Handler6_OnNextPage()

    {

        return false;

    }

    

    

    

    private bool PropertyManagerPage2Handler6_OnPreview()

    {

        return false;

    }

    

    private bool PropertyManagerPage2Handler6_OnPreviousPage()

    {

        return false;

    }

    

    private void PropertyManagerPage2Handler6_OnRedo()

    {

        

    }

    

    

    

    private void PropertyManagerPage2Handler6_OnUndo()

    {

      

    }

    

    private void PropertyManagerPage2Handler6_OnWhatsNew()

    {

      

    }

    

    public void AfterActivation()

    {

    

    }

    

    public void AfterClose()

    {

    

    }

    

    public int OnActiveXControlCreated(int Id, bool Status)

    {

        return 0;

    }

    

    public void OnButtonPress(int Id)

    {

       

    }

    

    public void OnCheckboxCheck(int Id, bool Checked)

    {

       

    }

    

    public void OnClose(int Reason)

    {

      

    }

    

    public void OnComboboxEditChanged(int Id, string Text)

    {

       

    }

    

    public void OnComboboxSelectionChanged(int Id, int Item)

    {

     

    }

    

    public void OnGroupCheck(int Id, bool Checked)

    {

      

    }

    

    public void OnGroupExpand(int Id, bool Expanded)

    {

        

    }

    

    public bool OnHelp()

    {

        return false;

    }

    

    public bool OnKeystroke(int Wparam, int Message, int Lparam, int Id)

    {

        return false;

    }

    

    public void OnListboxSelectionChanged(int Id, int Item)

    {

       

    }

    

    public bool OnNextPage()

    {

        return false;

    }

    

    public void OnNumberboxChanged(int Id, double Value)

    {

        

    }

    

    public void OnOptionCheck(int Id)

    {

        

    }

    

    public void OnPopupMenuItem(int Id)

    {

        

    }

    

    public void OnPopupMenuItemUpdate(int Id, ref int retval)

    {

        

    }

    

    public bool OnPreview()

    {

        return false;

    }

    

    public bool OnPreviousPage()

    {

        return false;

    }

    

    public void OnRedo()

    {

        

    }

    

    public void OnSelectionboxCalloutCreated(int Id)

    {

        

    }

    

    public void OnSelectionboxCalloutDestroyed(int Id)

    {

        

    }

    

    public void OnSelectionboxFocusChanged(int Id)

    {

        

    }

    

    public void OnSelectionboxListChanged(int Id, int Count)

    {

        

    }

    

    public void OnSliderPositionChanged(int Id, double Value)

    {

        

    }

    

    public void OnSliderTrackingCompleted(int Id, double Value)

    {

        

    }

    

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

    {

        return false;

    }

    

    public bool OnTabClicked(int Id)

    {

        return false;

    }

    

    public void OnTextboxChanged(int Id, string Text)

    {

        

    }

    

    public void OnUndo()

    {

        

    }

    

    public void OnWhatsNew()

    {

        

    }

}

}

 



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:   Activate PropertyManager Page Tab 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) 2014 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.