Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Placing text via script?

Status
Not open for further replies.

solid7

Mechanical
Jun 7, 2005
1,403

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
 
Replies continue below

Recommended for you

Set Text = DrwTexts.Add("Text", x, y)
CATFormatTBText "TitleBlock_Text_Label_PartNumber", catTopLeft, 2
 
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
 
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
 
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
 

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
 

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
 

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
 
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
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor