Monday, 29 December 2014

Making of Solid Edge Text Search Part 2

...continued from Part 1

Declare Form level variables as below:

30

Of these the lFoundObjects is a Dictionary that stores Text, Balloon and Callout objects that are found during the Search operation.

A Dictionary is similar to a list but stores two values in one item called a Key-Value pair. In this program this is used to store an Object along with its sheet.

The object can be a Text, Balloon or a Callout. 

06

The sCaption is a simple string used for captions on various message boxes.

iMaxFound is the total number of objects found for a given text search and iCurrent is used in the Find Next button to keep a tab on the currently searched text from the Dictionary.

Following this, is the Form's Load event,

31

The Marshal class comes from System.Runtime.Interopservices namespace and its GetActiveObject method helps the macro to connect to the running instance of Solid Edge specified as a string "SolidEdge.Application".

This string is the ProgID or Program ID of Solid Edge which is stored in the Registry and can be searched, upon which you will also find lying nearby the installed path of (Edge.exe) i.e. Solid Edge from where it is accessed or invoked.

The Load event code begins with On Error Resume Next so the program proceeds even when there I an error and we can catch the error in the following line.

Since this program is supposed to run from within Solid Edge from a button on the ribbon, there should be no problem accessing the running instance of Solid Edge.

However, this program works in the Draft environment only, hence checking the active document type is necessary. This is done using the oDoc.Type property and a proper message is shown to the user.

The Search button: In this button's click event, a message is displayed in the label just below the txtFind Textbox if it is empty.

Further the Dictionary lFoundObjects is initiated using the New keyword so that found objects can be added to it along with their respective sheets.

32

Sheets in Solid Edge are categorized into two: Working Section and Background Section.

oWSheets and oBSheets respectively store these two sheets as shown in the last two lines of code snippet above.

28

Further if the check boxes for Working and Background sheets are checked, the two sheet sections are searched for Objects viz. Text, Balloons and Callouts.

33

The FindText function takes the SectionSheets as an argument and uses a For loop to  search through each of the sheets - Working and/or Background - and tries to match the text part of the Objects

34

When the texts match, the Text object is added to the Dictionary along with its sheet:

35

36 Note how the case is matched by default and when the chkMatchCase check box is not checked, both the text are made uppercase using ToUpper and matched in which case the case dos not matter, just the characters should match.

Searching Balloon: Similarly the Balloon is searched which has four texts as below:

37

After all objects viz. Text, Balloons and Callouts are searched and collected into the Dictionary lFoundObjects, the count is checked and if it is greater than 0, the status in the label shows the count and the object and its sheet are stored in oObject and oSheet respectively.

The found object and its sheet are then provided as arguments to the ZoomToObject function which actually zooms in closer to the object.

38

The ZoomToObject function finds the range i.e. the extents of the textbox or Balloon which are defined by the lower-left corner and upper-right corner of the imaginary box that the text occupies on the sheet.

10

 

To determine the extents i.e. the Range, the Range method is used on the oTextBox object:

11

where XMin and YMin are the coordinates of the lower-left corner of the Range and XMax and YMax are coordinates of the upper-right corner of the range, dclared as below:

12

These are the values in terms of sheet sizes. However the zoom action is in terms of the screen size and coordinates. Hence these sheet coordinates need to be transformed in to screen coordinates as below:

13

where, the Draft sheet is the model while the screen is the window.

These transformed coordinates are then used to zoom in to the oTextFound textbox object on the Draft sheet:

14

Continued to Part 3...


Index of all Solid Edge Tips, Tutorials and Videos...