×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Placing text via script?

Placing text via script?

Placing text via script?

(OP)

I would like to know if it's possible to add text to a drawing at a given point location?  I have some information that goes on a drawing - same place everytime, but I want to add a user interface that is filled out when the title block is inserted.

I tried recording a macro which had me selecting the point at which to add the text, but it was to no avail.  There was nothing the resultant macro.

Thank you.

-----------------------------------------------------------
Catia Design|Catia Design News|Catia V5 blog

RE: Placing text via script?

  Set Text = DrwTexts.Add("Text", x, y)
  CATFormatTBText "TitleBlock_Text_Label_PartNumber", catTopLeft, 2

RE: Placing text via script?

Earlier example was modified from the CATScript Titleblock code supplied with CATIA which placed the desired text in the x,y location and applied the formating via the CATFormatTBText function.

'This example retrieves in CharString the character string of the MyText drawing text.
CharString = MyText.Text 'retrieves
MyText.Text = CharString 'sets

'This example retrieves the x coordinate of the text MyText drawing text.
 CurrentX = MyText.X 'retrieves

'This example sets the y coordinate of the text MyText drawing text to 5 inches. You need first to convert the 5 inches into meters.
 NewYCoordinate = 5 * 25.4 / 1000
 MyText.Y = NewYCoordinate

RE: Placing text via script?

(OP)
I noticed that it was taken from that script.  Originally, I tried to modify the same script to work, but I can't seem to quite get it.

I need to get the script to plug in user defined text, to the same spot on the sheet every time.  It needs to be placed in the sheet view. (so the script has to automatically switch the view)  I'm not really sure how to define the "DrwTexts" variable.

Here is what I have so far:

Sub CATMain()

Set DrwTexts = Catia.ActiveDocument.Sheets.ActiveSheet.Views.ActiveView.Texts

  Some Text = InputBox("Review has been completed by:", "Reviewer's Name", "Reviewer")

  Set Designer = DrwTexts.Add("Designer",20 ,20)

End Sub


Set DrwTexts is not correct, I am sure.  I don't know exactly how to set the sheet, rather than current view.  Do I need to just remove the "Views.Activeview" portion of that line?

Also, while there is no error, there is no output generated by this code.  

Thanks for your help.

-----------------------------------------------------------
Catia Design|Catia Design News|Catia V5 blog

RE: Placing text via script?

Option Explicit

Public ActiveDoc      As Document
Public DrwDocument    As DrawingDocument
Public DrwSelect      As Selection
Public DrwSheets      As DrawingSheets
Public DrwSheet       As DrawingSheet
Public DrwView        As DrawingView
Public DrwTexts       As DrawingTexts
Public Text           As DrawingText
Public Designer       As String

Sub CATMain()
 Set ActiveDoc = CATIA.ActiveDocument
  Select Case TypeName(ActiveDoc)
    Case "DrawingDocument"
      Set DrwDocument = CATIA.ActiveDocument
      Set DrwSheets = DrwDocument.Sheets
      Set DrwSelect = DrwDocument.Selection
      Set DrwSheet = DrwSheets.ActiveSheet
      Set DrwView = DrwSheet.Views.Item(2)
        DrwView.Activate 'sets and activates background
      Set DrwTexts = DrwView.Texts
    Case "PartDocument"
    MsgBox "Please Activate a CATDrawing"
    Case "ProductDocument"
    MsgBox "Please Activate a CATDrawing"
  End Select

Designer = InputBox("Review has been completed by:", "Reviewer's Name", "Reviewer")

Set Text = DrwTexts.Add(Designer, 20, 20)

End Sub

RE: Placing text via script?

(OP)

OK, 2 more questions -

1)Set DrwView = DrwSheet.Views.Item(2) - what if there are no views yet?

2)How do I set the text size, color, and position?


Thank you.

-----------------------------------------------------------
Catia Design|Catia Design News|Catia V5 blog

RE: Placing text via script?


Set Text = DrwTexts.Add(Designer, 20, 20)
  Text.Name = "Designer"
  Text.anchorPosition = catMiddleCenter
  Text.SetFontName 0, 0, "Monospace821 BT"
  Text.SetFontSize 0, 0, 3.5  '3.5=fontSize
  DrwSelect.Add Text
  DrwSelect.VisProperties.SetRealColor 0, 0, 253, 0
  DrwSelect.Clear
  
  Set DrwView = DrwSheet.Views.Item(1) 'Create Drawing generates 2 views by default`
  DrwView.Activate
  

RE: Placing text via script?

(OP)

I'm a bit confused, here...  'DrwView.Activate' is no longer activating the background view.  Also, whether this page is new, or has 100 views on it, this text *should* always goes to current sheet background, and I know that's not the way that I've set it up.

What am I doing wrong?  Here is my code:



Sub CATMain()

    Set DrwDocument = CATIA.ActiveDocument
    Set DrwSheets   = DrwDocument.Sheets
    Set Selection   = DrwDocument.Selection
    Set DrwSheet    = DrwSheets.ActiveSheet
    Set DrwView     = DrwSheet.Views.ActiveView
    Set DrwTexts = Catia.ActiveDocument.Sheets.ActiveSheet.Views.ActiveView.Texts

    DrwView.Activate

    Designer = InputBox("This review has been done by:", "Designer's Name", "Designer's name")

    Set Designer = DrwTexts.Add(Designer,(13.5*25.4) ,(1.25*25.4))
        Designer.anchorPosition = catMiddleLeft
        Designer.SetFontName 0, 0, "Monospace821 BT"
        Designer.SetFontSize 0, ,7       '7=fontSize


End Sub

-----------------------------------------------------------
Catia Design|Catia Design News|Catia V5 blog

RE: Placing text via script?

Hello,

Unless I am wrong the Views collection have(by default with a new drawing) 2 items, the background and the main view. Any other view created will be listed after in the collection.

Eric N.
indocti discant et ament meminisse periti

RE: Placing text via script?

Set DrwView = DrwSheet.Views.Item(1) 'sheet.1
Set DrwView = DrwSheet.Views.Item(2) 'background view


Paste the '28 Sep 07 7:13' post and insert the '28 Sep 07 8:37' after the 'Set Text = DrwTexts.Add(Designer, 20, 20)' into a catvba file and it should work.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources