Sunday 5 January 2014

Cust 11: Document & Environ Type: C++ with MFC Part 2

This is part 2 of the two part tutorial where you learn:

  • How to determine the type of a document currently open in Solid Edge using C++ with MFC i.e. pure C++.
  • Difference between Solid Edge Document and Environment types.
  • How to determine Solid Edge Document and Environment types.


… continued from Part 1

Complete the switch statement as below:

if(this->oApp->Documents->Count > 0)
  switch (this->oApp->ActiveDocumentType)
    case (SolidEdgeFramework::DocumentTypeConstants::igPartDocument):
    txtDocType.SetWindowTextA("Part Document");

    case (SolidEdgeFramework::DocumentTypeConstants::igDraftDocument):
    txtDocType.SetWindowTextA("Draft Document");

    case SolidEdgeFramework::DocumentTypeConstants::igAssemblyDocument:
    txtDocType.SetWindowTextA = "Assembly Document";

    case SolidEdgeFramework::DocumentTypeConstants::igSheetMetalDocument:
    txtDocType.SetWindowTextA("Sheetmetal Document");

    case SolidEdgeFramework::DocumentTypeConstants::igWeldmentDocument:
    txtDocType.SetWindowTextA("Weldment Document");

    case SolidEdgeFramework::DocumentTypeConstants::igWeldmentAssemblyDocument:
    txtDocType.SetWindowTextA(“Weldment Assembly Document");

    case SolidEdgeFramework::DocumentTypeConstants::igUnknownDocument:
    txtDocType.SetWindowTextA("Unknown Document Type");
  }// switch

  _bstr_t Environ(this->oApp->ActiveEnvironment);
  string environ((char*)Environ);

  } // if
  txtDocType.SetWindowTextA("No Document Open");

Each time check the document type property against the document type constants and accordingly display the document type in the first Static Text control.

To set the first Static Text control to display the document type, switch to the tab for the design view of the dialog and right click on the Static Text. Select Add Variable… from the context menu.


In the dialog that appears, specify the variable name as txtDocType or lblDocType.

Leave other settings unchanged and click Finish.

Similarly add a variable for the second Static Text control which will display the Environment type.

This variable represents the Static Text control in the code and its SetWindowTextA function is used to set or change the text displayed during program execution.

So when the active document type is detected as a Part document, set the text displayed in the Static Text control as:

    txtDocType.SetWindowTextA("Part Document");

In the second Static Text control, the text to be displayed is the environment type using the ActiveEnvironment property which is of type _bstr_t which is cast to a char* and using the .c_str method is converted to a LPCTSTR so that it can be displayed in the Static Text control.

  _bstr_t Environ(this->oApp->ActiveEnvironment);
  string environ((char*)Environ);

The subtle difference between document type and environment type can be understood by running the program.

First start Solid Edge and close all open documents. Run the program and click the Document & Env Type button. The program readily connects to Solid Edge as soon as the form loads.

The first Static Text control displays No Document Open from the else part of the if statement.

The second Static Text control does not change.


Next, without closing the program, open a Part document and click the button again.

Now the document type is displayed as Part Document and the environment type is displayed, as Part:


Keep the MFC program running and in Solid Edge, start sketching on a plane and switch back to the program to click the button. Now the second Static Text control displays the environment type as LayoutInPart.


Open or create a Drawing document in Solid Edge with the program still running in the background. Click the button:


Place a view in the drawing and right click on the view. Select Draw in View from the context menu.


Click the button in the program and note the change in the environment type.


Similarly check the document and environment types in an assembly document.

clip_image002 Drop a comment below if you need the Visual studio code files and also if you liked the depth of discussion here, similar in-depth techniques are discussed in cMayoCAD where you create your own, brand new, fully functional CAD system with scripting capabilities using a geometric modeling kernel.

Download the detailed course contents for cMayoCAD here.



No comments:

Post a Comment