Software Developer's Kit - ChemDraw

Send comments on this topic
Union Method
See Also 
newVal
newVal is a ChemDrawControl rectangle

Description

Member of ChemDraw Control.Rect.

Modifies this rectangle according to the result of its union with another rectangle.

Syntax

Visual Basic
Public Sub Union( _
   ByVal newVal As Rect _
) 

Parameters

newVal
newVal is a ChemDrawControl rectangle

Return Type

Rect

Remarks

This method yields a new rectangle which is the union of the rectangle with a second rectangle (newVal as Rect). The union rectangle is the smallest rectangle which encloses both the original rectangle and the second rectangle (newVal as Rect). 

Rect1.Union Rect2  : yields a new rectangle as a result of the union of Rect1 with Rect2

Rect1 is the object on which Union is a method. 
Rect2 is the argument to the method.

Example

'Declares the variables
 Dim myObject As ChemDrawControl10Ctl.Object
 Dim vObject1  As ChemDrawControl10Ctl.Object 
 Dim vObject2  As ChemDrawControl10Ctl.Object 
 Dim Rect1 As ChemDrawControl10Ctl.Rect  
 Dim Rect2 As ChemDrawControl10Ctl.Rect
'Checks that there is an object loaded in the variable
 If  Selection.Objects.Count < 1 Then 
     Exit Sub
 End If

'Union works with two rectangles - such as those that bound ChemDraw objects
 Dim i As Integer
 i = 0 
 For Each myObject In Selection.Objects
     If myObject.Selected = True Then
        Set
vObject = myObject
        If  i = 0 Then
            
Set vObject1 = ChemDrawControl10Ctl.ActiveDocument.Selection.Objects.Item(1)
        End If
        If 
i = 1 Then
            
Set vObject2 = ChemDrawControl10Ctl.ActiveDocument.Selection.Objects.Item(2)
        End If
       
i = i + 1
    End If
 Next
 End Sub

 Private Sub cmdUnion_Click()
    'Example of Rect.Union
    'Shows the coordinates of both rectangles Rect1 and Rect2
     Label1.Caption = "Rect1 coordinates:" + Chr$(13) + _
                       Format(elrect1.TopLeft.X, "0.0") + "  " + _
                       Format(elrect1.TopLeft.Y, "0.0") + Chr$(13) + _
                       Format(elrect1.BottomRight.X, "0.0") + "  " + _
                       Format(elrect1.BottomRight.Y, "0.0") + Chr$(13)
     Label2.Caption = "Rect2 coordinates:" + Chr$(13) + _
                       Format(elrect2.TopLeft.X, "0.0") + "  " + _
                       Format(elrect2.TopLeft.Y, "0.0") + Chr$(13) + _
                       Format(elrect2.BottomRight.X, "0.0") + "  " + _
                       Format(elrect2.BottomRight.Y, "0.0") + Chr$(13)
    'Applies the union method: Rect1 is equaled to the union 
     Set Rect1 = vObject1.Bounds 
     Set Rect2 = vObject2.Bounds 
     Rect1.Union Rect2
 End Sub

See Also