Add text to Drawing From Root Product

Hello All Users,

The macro I created below prints information text on the technical drawing paper for the active view, taking the part as a reference.

Sub CATMain()
Dim oEdit As Editor
Dim oDrw As DrawingRoot
Dim oActiveSheet As DrawingSheet
Dim oView As DrawingView
Dim oScale As Double

Dim oGenView As DrawingGenView
Dim oProd As VPMReference

Set oEdit = CATIA.ActiveEditor
Set oDrw = oEdit.ActiveObject
Set oActiveSheet = oDrw.ActiveSheet
Set oView = oActiveSheet.Views.ActiveView


Set oGenView = oView.DrawingGenView
Set oProd = oGenView.GetAssociatedRootProduct()

Dim ObjVPMRepInstances As VPMRepInstances

Set ObjVPMRepInstances = oProd.RepInstances

Set ObjVPMRepReference = ObjVPMRepInstances.Item(1).ReferenceInstanceOf

Set ObjPart = ObjVPMRepReference.GetItem("Part")

Set MyRepInstance = oProd.RepInstances.Item(1)

Set MatService = CATIA.GetSessionService("MATPLMService")



Dim NoRef As VPMReference

Dim NoRepInst As PLMEntity

Dim NoOcc As VPMOccurrence

 

Dim MyProductService As PLMProductService

Set MyProductService = oEdit.GetService("PLMProductService")

 

Set myLinkOnRepInst = MyProductService.ComposeLink(NoOcc, MyRepInstance, NoRef)

Dim MyCoreMatRef As Material

Dim MyCoreAppliedMat As AppliedMaterial

 

MatService.GetMaterialCore myLinkOnRepInst, MyCoreMatRef, MyCoreAppliedMat

 

MatName = MyCoreMatRef.Name

 

Dim oTitle As String
oTitle = oProd.GetAttributeValue("V_Name")

Dim oRevision As String
oRevision = oProd.GetAttributeValue("V_version")

Dim oDescription As String
oDesciription = oProd.GetAttributeValue("V_description")

Dim Status
Dim TextLocation(1)
Dim Selection1
Set Selection1 = oEdit.Selection

Dim ObjectSelected
Dim dX As Double
Dim dY As Double
Dim DrawingWindowLocation1(1)
Dim myObjType(0)
myObjType(0) = "DrawingView"

Status = Selection1.IndicateOrSelectElement2D("Select a point", myObjType, False, False, False, ObjectSelected, DrawingWindowLocation1)
Dim Parameter1 As String
Parameter1 = oTitle + Chr(10) + _
"POZ : 1" + Chr(10) + _
"ADET : 1" + Chr(10) + _
"MALZEME : " + MatName + Chr(10) + _
"OLCEK : ()"

Dim MyText As DrawingText
Set MyText = oView.Texts.Add(Parameter1, DrawingWindowLocation1(0), DrawingWindowLocation1(1))
Call oView.InsertViewScale(Len(MyText.Text), MyText)

'Dim Text As DrawingText
'Set Text = oView.Texts.Add("Type : ", 100, 100)

'Insert Attribute Link
'Text.InsertAttributeLink 0, 0, oProd, "VPMReference", "V_Name"

End Sub

 

But the code sequence only works for part. How should I edit the code for the following scenario?

- There is a product and 2 parts underneath it.
- By pressing front view on the technical drawing screen, clicking on just one of the parts in the product and selecting the reference view.
- I want to be able to run the macro only when the view of the relevant part is active on the drawing screen.

I want to provide this link to print information about the part I have selected in text.

Should I add Selection etc? What should I do? Can you help me?