Software Developer's Kit - ChemDraw

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

Description

Member of ChemDraw Control.Rect.

Modifies this rectangle, according to the result of the intersection with another rectangle.

Syntax

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

Parameters

newVal
newVal is a ChemDrawControl rectangle

Return Type

Rect

Remarks

This method yields a new rectangle which is the intersection of the rectangle with a second rectangle (newVal as Rect). If the rectangles do not intersect, then the original rectangle is set to coincide with the second one. 

Rect1.Intersection Rect2  : yields a new rectangle as a result of the intersection of Rect1 with Rect2

Rect1 is the object on which Intersection 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 
 Private Sub ctlChemDraw_SelectionChanged(ByVal selection As _
        ChemDrawControl10Ctl.IChemDrawSelection)
    'Verifies what has been selected 
     If  Selection.Objects.Count < 1 Then
         Exit Sub 'exits if there is nothing selected 
     End If

    'Intersection 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 cmdIntersection_Click()    
    'Example of Rect.Intersection
     Set Rect1 = vObject1.Bounds 
     Set Rect2 = vObject2.Bounds 
     Rect1.Intersection Rect2 
    'Rect1 becomes the intersection of Rect1 & Rect2, if intersection is not empty   
    'Rect1 becomes Rect2, if intersection is empty

 End Sub 

See Also