0

I'm currently trying to program a CATIA macro to search through a specific text:"DD/MM/YYY" on a 2D CATIA drawing sheet and replace that same text with a user inputted text. (Basically to update the text box)

I'm currently new to VBA scripting language and have zero to no experience in doing this. I've researched extensively on this but found no codes close to achieving the problems that I am trying to solve.

Textbox contents to be replaced by user

Click this link to see problem: Textbox contents to be replaced by user

what I wanted the CATIA macro to do Click this link to see what I wanted the CATIA macro to do

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
CATIA
  • 9
  • 1
  • 3
  • 1
    Can you give more information, and an example of what you want? – AAA Jun 08 '19 at 19:33
  • I've added the images of what I needed the macros to do. You may refer to the two images attached to have a better understanding of the problem that I am facing. Thanks a lot for the help, I really do appreciate it. – CATIA Jun 09 '19 at 08:37

2 Answers2

0

I'm quite sure that your date text string has a specific name in the title block, so search for that specific text string name and assign another value.

If you have a lot of drawings to do this task, you can do it in batch mode, open one by one drawings in a folder, replace the date, save drawing, close document...no input from designer, just assign the new date value inside your new macro.

ferdo
  • 178
  • 4
  • But what if the text string name for one drawing differs from the other? For example Text.5 refers to the date that I want to change but in another drawing, it is Text.6? – CATIA Jun 10 '19 at 14:27
  • Didi you checked ? If is like you said, you have to think to another solution, maybe checking the position (coordinates). – ferdo Jun 11 '19 at 15:08
0

This short snippet will search all Texts entities and try to replace with a fixed string:

Sub Catmain()

Dim oDoc As Document
Dim oView as DrawingView
Dim oText As DrawingTexts
Dim txt_to_src As String
Dim txt_to_place As String
Dim n As Integer

n = 0
Set oDoc = CATIA.ActiveDocument
Set oSheets = oDoc.Sheets
Set oViews = oSheets.ActiveSheet.Views
Set oView = oViews.ActiveView
Set oTexts = oView.Texts
txt_to_src = "STACK OVERFLOW."
txt_to_place = "REPLACED"

For Each srcText In oTexts
    If srcText.Text = txt_to_src Then
        srcText.Text = txt_to_place
        n = n + 1
    End If
Next
MsgBox n & " text frames have been replaced"

End Sub

This only searches all texts in the active view of the active sheet of the opened document. Consider to use a more specific check criteria such Instr (check if a string is contained into another string), the equality used is just a representative check. You'll probably need to cycle all views of a Sheet (i.e. all Items of oViews collection), and all Sheets of a document (i.e. all items of oSheets collection). Then extend to cycle all opened DrawingDocuments if you want.

Remember that an empty document with a title block already has 2 Views (background and Main) so if your drawing has, say, just 1 Front View, the script has to cycle through 3 views.

Dewydd
  • 81
  • 5
  • Thank you for help! Although there are still much to be done, you have provided a great solution to my problem. Once again, thank you, Thank you and thank you! – CATIA Jun 15 '19 at 17:37