Language="VBSCRIPT"

Sub CATMain()

' vbscript for creating a relation between the Legislation defined at the IndirectVision Object 
' and the one contained in the TargetPart 



Set productDocument1 = CATIA.ActiveDocument

' how to define the behavior
On Error Resume Next

Dim CurSelection As Selection
set CurSelection = productDocument1.Selection

Dim VBScriptBeh As Behavior
set VBScriptBeh = CurSelection.FindObject("CATIABehaviorVBScript")

if VBScriptBeh Is Nothing then
    MsgBox "Not Started From A Behavior"
else
	VBScriptBeh.Start 

	Set product1 = productDocument1.Product

	Set relations1 = product1.Relations

	Set documents1 = CATIA.Documents

	Set partDocument1 = documents1.Item("Target_Part_1.CATPart")

	Set part1 = partDocument1.Part

	Set parameters1 = part1.Parameters

	Set strParam1 = parameters1.Item("Target_Part\Open_body.2\Target_Definition.1\Norm")

	Set formula1 = relations1.CreateFormula("Formula.3", "", strParam1, "`IndirectVision (Product1)\Legislation`")

	formula1.Rename "Formula.3"
	
	VBScriptBeh.Done

end if
End Sub
