In this tutorial you learn:
- How to invoke or determine the type of Solid Edge document using Managed C++ i.e. C++/CLI
- What is the difference between document type and environment type and how to determine it.
Note:
Start Visual Studio and add a Windows Forms Application project under Visual C++/CLR.
Visual Studio 2010 with .Net framework 4 should work well with Solid Edge 20.
Specify a suitable name for the project and a location and click OK.
Select Solid Edge Framework Type Library from the list. Back to the Property Pages dialog, Solid Edge Framework gets added under References. |
In the form’s load event add the following code: oApp = (SolidEdgeFramework::Application^)Marshal::GetActiveObject("SolidEdge.Application"); The GetActiveObject method of the Marshal class helps to connect to a running instance of Solid Edge, which in turn is made available by virtue of the using namespace System::Collections::Generic; statement added earlier. Here, SolidEdge.Application is the Program ID for Solid Edge which does not change from version to version. To check this, start the Registry Editor by pressing Windows+R button to invoke the Run utility. Type regedit and press ENTER. In the registry editor application which looks like the Windows Explorer, select Edit > Find or press F3 and type SolidEdge.Application. After a while it searches for SolidEdge.Application and displays the search as below: If you click the LocalServer32 just above ProgID folder in the left panel, it displays the installed path for Solid Edge. |
Build the project and check if everything is fine.
Back to Visual Studio, double click the Check Document Type button and add the following line of code for the button:
if(oApp->Documents->Count > 0)
{
switch (oApp->ActiveDocumentType)
To determine the type of the currently active document, first check if there is at least one document open using the if statement as above.
Set up a switch construct to check the document type using the ActiveDocumentType property of the Solid Edge Application object.
The ActiveDocumentType is a SolidEdgeFramework.DocumentTypeConstants enum
Complete the switch statement as below:
if(oApp->Documents->Count > 0)
{
switch (oApp->ActiveDocumentType)
{
case SolidEdgeFramework::DocumentTypeConstants::igPartDocument:
Label1->Text = "Part Document";
break;
case SolidEdgeFramework::DocumentTypeConstants::igDraftDocument:
Label1->Text = "Draft Document";
break;
case SolidEdgeFramework::DocumentTypeConstants::igAssemblyDocument:
Label1->Text = "Assembly Document";
break;
case SolidEdgeFramework::DocumentTypeConstants::igSheetMetalDocument:
Label1->Text = "Sheetmetal Document";
break;
case SolidEdgeFramework::DocumentTypeConstants::igWeldmentDocument:
Label1->Text = "Weldment Document";
break;
case SolidEdgeFramework::DocumentTypeConstants::igWeldmentAssemblyDocument:
Label1->Text = "Weldment Assembly Document";
break;
case SolidEdgeFramework::DocumentTypeConstants::igUnknownDocument:
Label1->Text = "Unknown Document Type";
break;
}// switch
Label2->Text = oApp.ActiveEnvironment.ToString();
} // if
else
Label1->Text = "No Document Open";
}
Each time check the document type property against the document type constants and accordingly display the document type in the first label.
The second label displays the ActiveEnvironment property directly by converting to string.
The subtle difference between document type and environment type can be understood by running the program.
First start Solid Edge and close any open documents. Run the program and click the Check Document Type button. The program readily connects to Solid Edge as soon as the form loads.
The first label displays No Document Open from the else part of the if statement.
The second label is blank.
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 program running and in Solid Edge, start sketching on a plane and switch back to the program to click the button. Now the second label 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 labels in an assembly document.
Post a comment below if you need the Visual studio code files and be aware of 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