RSS

SolidWorks Dev: Programmatically get the active PropertyManagerPage2 instance (III)

19 Nov

Given the hacked knowledge as described in the series (I) and (II), now it is trivial to devise an approach to programmatically get the active PMP page. The desired way of using the code is like this:

IntPtr handle=SWPropertyPageFinder.GetPMPHandle(SolidWorksAddin.SwApp));
string Caption=SWPropertyPageFinder.GetActivePMPCaption(SolidWorksAddin.SwApp));

And the class is designed like this:

Hack_SW_PropertyPage5

The detailed implemetation involves using two service classes:Hack_SW_PropertyPage6

Hack_SW_PropertyPage7

These two classes encapsulates the unmanaged api calls using such functions as

  • EnumChildWindows
  • GetWindowText
  • GetClassName

And using these two classes, one can enumerate all the child windows with specific caption or classes, and all the matched child window handles are archived into MatchedHandles field.

  1. By first enumerate all the child windows of SolidWorks Mainframe window, we can get all the windows whose title is "Dve sheet";
  2. Given a list of Windows handles derived from step 1, for each window handle, we check if the window has a child window whose caption is "Properties"
    • If yes, this is the default PMP page generated by SolidWorks;
    • Otherwise, this window should have a child window, whose type is "Button", and in addition, this button is the 1st child of the window under inspection.
    • The button, if exists, has the same caption as the PMP page’s title.

A basic test shows its efficacy:

Hack_SW_PropertyPage8Hack_SW_PropertyPage9

 Hack_SW_PropertyPage11Hack_SW_PropertyPage10 

Any comments are welcome.

Advertisements
 
2 Comments

Posted by on November 19, 2008 in CAD, Dotnet/C#

 

2 responses to “SolidWorks Dev: Programmatically get the active PropertyManagerPage2 instance (III)

  1. Mike Warner

    March 4, 2011 at 1:45 am

    Re:
    Programmatically get the active PropertyManagerPage2

    I have been struggling for some time now to do this and it seemed that your article would show me the solution.

    Unfortunately none your png files that, I assume, show the code are for some reason not displaying.

    I am wondering if you might me kind enough to send me some code.

    Regards,
    Mike Warner
    Port Credit, Ontario, Canada

     
  2. xinyustudio

    March 4, 2011 at 10:15 am

    Thanks. The images are updated.

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: