CAT VBA Macro for inserting text

Phanindra R

CAT VBA Macro for inserting text


I am learning VB Programmin recently, I am trying to write a macro in CATVBA Which has to accomplish the following objective.

It should insert a line of text for example:"This is a CATIA Drawing" into my currently opened drawing file.

Since i am new to CATVBA Programming i do not know the exact approach i have to follow,Hence please guide me on the approach,

I would greatly appreciate any help or any suggestions which would help me to achieve this objective .




Fernando Petre

RE: CAT VBA Macro for inserting text
(in response to Phanindra R)


Here you have some examples how to handle text and lines in a drawing view - here is background view

' made as example for

Sub CATMain()

Dim CATIA As Object
Set CATIA = GetObject(, "CATIA.Application" )

Dim MyDrawingDoc As DrawingDocument
Set MyDrawingDoc = CATIA.ActiveDocument

Dim MyDrawingSheets As DrawingSheets
Set MyDrawingSheets = MyDrawingDoc.Sheets

Dim MyDrawingSheet As DrawingSheet
Set MyDrawingSheet = MyDrawingSheets.ActiveSheet

Dim MyDrawingViews As DrawingViews
Set MyDrawingViews = MyDrawingSheet.Views

Dim drwviews As DrawingViews  'make background view active
Set drwviews = MyDrawingSheet.Views
drwviews.Item("Background View" ).Activate

'Set myText.... As DrawingText - adding texts
Set myText = MyDrawingViews.ActiveView.Texts.Add ("Dibujado", 22, 38) 'coordinates x=22, y=38 of left bottom corner of the text location
Set myText1 = MyDrawingViews.ActiveView.Texts.Add ("Corregido", 22, 31)
Set myText2 = MyDrawingViews.ActiveView.Texts.Add ("Fecha", 57, 46)
Set myText3 = MyDrawingViews.ActiveView.Texts.Add ("DD-mm-08", 57, 38)
Set myText4 = MyDrawingViews.ActiveView.Texts.Add ("DD-mm-08", 57, 31)
Set myText5 = MyDrawingViews.ActiveView.Texts.Add ("Nombre", 87, 46)
Set myText6 = MyDrawingViews.ActiveView.Texts.Add ("Jefatura", 87, 38)
Set myText7 = MyDrawingViews.ActiveView.Texts.Add ("Delineante", 87, 31)
Set myText8 = MyDrawingViews.ActiveView.Texts.Add ("Empresa S.A.", 159, 40)
Set myText9 = MyDrawingViews.ActiveView.Texts.Add ("C/laredo 8, 2B", 159, 32)

Set myText13 = MyDrawingViews.ActiveView.Texts.Add ("Escalas:", 22, 23)
Set myText14 = MyDrawingViews.ActiveView.Texts.Add ("1/X", 22, 17)
Set myText15 = MyDrawingViews.ActiveView.Texts.Add ("1/X", 22, 11)
Set myText16 = MyDrawingViews.ActiveView.Texts.Add ("Firma", 128, 38)

Dim iFortSize1 As Double 'font text size
iFontSize1 = 3.500
myText1.SetFontSize 0, 0, 3.500  'iFontSize

'next lines with a different size for fonts - 2.5
Set myText10 = MyDrawingViews.ActiveView.Texts.Add ("Sustituye a: xxx-08", 155, 22)
Set myText11 = MyDrawingViews.ActiveView.Texts.Add ("Sustituido por: xxx-08", 155, 12)

Dim iFortSize10 As Double
iFontSize10 = 2.500
myText10.SetFontSize 0, 0, 2.500  'iFontSize

Dim iFortSize11 As Double
iFontSize11 = 2.500
myText11.SetFontSize 0, 0, 2.500  'iFontSize

'next lines with a different size for fonts - 5
Set myText12 = MyDrawingViews.ActiveView.Texts.Add ("plano No xxx-08", 70, 18)

Dim iFortSize12 As Double
iFontSize12 = 5.00
myText12.SetFontSize 0, 0, 5.00  'iFontSize


Dim DrwDocument   As DrawingDocument
Dim DrwSheets     As DrawingSheets
Dim DrwSheet      As DrawingSheet
Dim DrwView       As DrawingView
Dim DrwTexts      As DrawingTexts
Dim Text          As DrawingText
Dim Fact          As Factory2D
Dim Point         As Point2D
Dim Line          As Line2D
Dim Cicle         As Circle2D
Dim Selection     As Selection
Dim GeomElems     As GeometricElements

  Set DrwDocument = CATIA.ActiveDocument
  Set DrwSheets   = DrwDocument.Sheets
  Set Selection   = DrwDocument.Selection
  Set DrwSheet    = DrwSheets.ActiveSheet
  Set DrwView     = DrwSheet.Views.ActiveView
  Set DrwTexts    = DrwView.Texts
  Set Fact        = DrwView.Factory2D
  Set GeomElems   = DrwView.GeometricElements

'draw frame bottom line
    Set Line1 = Fact.CreateLine(20, 5, 205, 5) 'these are the coordinates of the starting point x=20, y=5 of the line and end point of the line x=205, y=5
    Line1.Name = "Line1"
    CATIA.ActiveDocument.Selection.VisProperties.SetRealWidth 3,1
'draw frame upper line
    Set Line2 = Fact.CreateLine(20, 292, 205, 292)
    Line2.Name = "Line2"
    CATIA.ActiveDocument.Selection.VisProperties.SetRealWidth 3,1
'draw a thin line
    Set Line3 = Fact.CreateLine(20, 40, 120, 40)
    Line3.Name = "Line3"
    CATIA.ActiveDocument.Selection.Add Line3
    Set visProperties1 = CATIA.ActiveDocument.Selection.VisProperties
    visProperties1.SetRealLineType 1,0.2
    Set visProperties1 = CATIA.ActiveDocument.Selection.VisProperties
    visProperties1.SetRealWidth 1,0.2

' You can continue to draw the rest of the lines and try other settings...

End Sub

Phanindra R

RE: CAT VBA Macro for inserting text
(in response to Phanindra R)


Thanks a lot for your help,The appraoch you have provided helped me a lot

I need another help ,I have posted details regarding the same can you please provide a solution for that ,I would greatly appreciate your help in this context

I have two questions here they are

1) I want to know how to insert two lines of text for example:-

    "This is a cata drawing"

     "This has been generated in CATIA V5"

    I want to insert the above two lines using CATVBA such that on a drawing file they should  be one below the other (in a single text box) upon executing the macro.

2)I want to know how to insert text in a Drawing which has been striken through

   for ex: "This is a CATIA Drawing"

I want to insert this using "CATVBA" such that on a drawing file they should look like as though they have been stricken off

Please guide me about the approach that I have to follow to achieve these two objectives.



Fernando Petre

RE: CAT VBA Macro for inserting text
(in response to Phanindra R)

Try to post your questions about programming in the proper section of the forum (Develop and Deploy).

For your first question you can try

Dim newText as String
newText = "This is a cata drawing" & Chr(13) & "This has been generated in CATIA V5"

For the second question I didn't have the opportunity to check in the documentation but I'm sure you can find an answer in vba help docs.

Calvin Cheng

RE: CAT VBA Macro for inserting text
(in response to Phanindra R)
Check the CATIA Document B19doc\English\online\CAAScdBase\CAAScdAutomationHome.htm

Here is the example how to make a strikethru line.

Property StrikeThru( ) As long

Returns or sets the drawing text font strikethrough property.
True if the drawing text font is striked through.
This example set the parameter StrikeThru on MyText drawing text.
MyText.StrikeThru = 1

Fernando Petre

RE: CAT VBA Macro for inserting text
(in response to Phanindra R)

If you will uncomment the other lines you will obtain other ways to write text drawings, in this case is TEST.


Sub CATMain()

Set drawingDocument1 = CATIA.ActiveDocument
Set drawingSheets1 = drawingDocument1.Sheets
Set drawingSheet1 = drawingSheets1.Item("Sheet.1" )
Set ActiveView = drawingSheet1.Views.Item(1)
Dim collection_textes As DrawingTexts
Set collection_textes = ActiveView.Texts
Dim Legende_texte As DrawingText
Set Legende_texte = collection_textes.Add("TEST", 1, 1)

Legende_texte.SetFontName 0, 0, "SSS1"

Legende_texte.SetFontSize 0, 0, 4.24

'~ Legende_texte.SetParameterOnSubString catItalic, 0, 0, 1
'~ Legende_texte.SetParameterOnSubString catSubscript, 0, 0, 1
'~ Legende_texte.SetParameterOnSubString catUnderline, 0, 0, 1
'~ Legende_texte.SetParameterOnSubString catOverline, 0, 0, 1
'~ Legende_texte.SetParameterOnSubString catSuperscript, 0, 0, 1
'~ Legende_texte.SetParameterOnSubString catBold, 0, 0, 1
Legende_texte.SetParameterOnSubString catStrikethrough, 0, 0, 1

End Sub

ehsan haji sadeghian

RE: CAT VBA Macro for inserting text
(in response to Fernando Petre)

tanks a lot for useful macros.I need macros to insert objects like table and pics to drafting.

best regards, 

Edited By:
ehsan haji sadeghian[spadantechnic] @ May 18, 2015 - 04:37 AM (IDLW)