Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

ADDING A LINK TO EXISTING TITLE BLOCK

Status
Not open for further replies.

harlowmatt

Aerospace
Nov 11, 2014
71
US
Hi everyone,
I am needing help with adding a function to my titleblock that will generate text in a certain area when it is inserted in to my drawing. I want to add text that says "MODEL BASE: (.CATPart FILE NAME)". It would also be great if while generating the titleblock I could select whether or not to have the model base callout like you can with whether or not to have "PRELIMINARY" on the drawing. I am not sure how to do this given my lack of knowledge of how to edit a titleblock .CATscript file. this is something that is done to almost every drawing in the same location. Any help would be greatly appreciated.
 
Replies continue below

Recommended for you

I have attached the .catscript file of our title block. The title block is put in the sheet background. the "MODEL BASE: (.CATPART/.PRODUCT FILE NAME)" text only needs to be on sheet 1. you can see the position of the text in attached image file. the title block is proprietary to Harlow so please treat it as such.
 
 http://files.engineering.com/getfile.aspx?folder=96a97374-f8a7-4dab-8e02-0a70fa5741bb&file=Drawing_Titleblock_Harlow.CATScript
The CATScript is giving me an error (also the DS title blocks macros from which this macro is derived is giving me same error so I suppose has to be modified for my r21 version...).

Anyway, another macro to insert your text in this title block can be done but there is no image attached in the post.

Regards
Fernando

 
Bellow is an example how to add something in Background Sheet. You can adapt according to your needs.

Code:
Sub CATMain()

Set DrwDocument = CATIA.ActiveDocument
Set DrwSheets = DrwDocument.Sheets

For i = 1 to DrwSheets.count
Set DrwSheet = DrwSheets.Item(i)
DrwSheet.Activate
Set DrwView = DrwSheet.Views.Item("Background View")
DrwView.Activate
Set DrwTexts = DrwView.Texts
Set Fact = DrwView.Factory2D

MsgBox "Text Will be created on: " & DrwSheet.name & " " & DrwView.name
Set Text = DrwTexts.Add("Test text",50,100)

MsgBox "Line Will be created on: " & DrwSheet.name & " " & DrwView.name
Set Line = Fact.CreateLine(50,100,100,100)

next
End Sub

Regards
Fernando

 
From what I have figured out is that the CATscript has to be edited in a script editor not regular CATIA. I don't understand what you mean by "there is no image attached in the post."
 
Sorry, I just saw the doc file, stupid me :)

You can modify the code bellow in a normal text editor or Script Editor from CATIA...you can change myFontName or myFontSize or x,y position of the text - bellow is 100, 100 .

Code:
Sub CATMain()

Dim drawingTexts1 As DrawingTexts
Dim drawingText1 As DrawingText
Dim Text_string As String

Dim myFontSize As Double
myFontSize = "0.079"
Dim myFontName As Double
myFontName = "SSS1"


Set DrwDocument = CATIA.ActiveDocument
Set DrwSheets = DrwDocument.Sheets
Set DrwSheet = DrwSheets.Item(1)
DrwSheet.Activate
Set DrwView = DrwSheet.Views.Item("Background View")
DrwView.Activate

set drawingtexts1 = catia.activedocument.sheets.activesheet.views.activeview.texts

Text_string = "MODEL BASE: (.CATPART/.PRODUCT FILE NAME)" 

Set drawingText1 = drawingTexts1.Add(Text_string, 100, 100)
drawingText1.Text = Text_string

drawingText1.SetFontSize 0,0,myFontSize
drawingText1.SetFontName 0,0, myFontName

End Sub

Regards
Fernando

 
THIS QUESTION IS BECAUSE OF MY LAKE OF KNOWLEDGE OF SCRIPT READING AND WRITTING. WILL THIS PULL IN THE ACTUAL FILE NAME OF THE MODEL THAT THE DRAWING IS CONNECTED TO. SO FOR EXAMPLE THE FILE NAME OF THE MODEL IS 123ABC. WHEN I OPEN MY DRAWING AND INSERT THE TITLE BLOCK IN THE SHEET BACKGROUND IT WILL HAVE THE TEXT THAT SAYS MODEL BASE: 123ABC?
 
So I have added it to the end of the original script and changed the first line of myfontname to Monoscript821 BT. When I bring in the title block to a drawing it did not add the "MODEL BASE:" call out. What am I missing? What else do I need to do if anything? Sorry for all the questions, I just don't know anything about script writing.
 
Check the line

Set drawingText1 = drawingTexts1.Add(Text_string, 100, 100) - this is saying that the text will be written in 100, 100 coordinates of the background sheet. Modify 100, 100 according to your needs.

If you want to write the name of the linked 3D model there are different options:
1. InputBox - here the user can write himself the name of the file
2. Switching between CATIA windows and pick the desired one.
3. Using a code like this

Dim Name_of_3D
Name_of_3D = drawingView1.GenerativeBehavior.document.ReferenceProduct.Parent.Name

This has to be chosen depending if you use a PLM system or not.



Regards
Fernando

 
So the 100, 100 background coordinates, is that x direction = 100 and y direction = 100? I added #3 of your options above and still get nothing.[sad]
 
Run this CATScript separate to understand what is doing then you can "merge" with yours.

Code:
Sub CATMain()

    Exe = MsgBox("Please select a view from where you want to retrieve the model base name ", vbOK, "Retrieve the Pointed Document Name")

If Exe = vbCancel Then
Exit Sub
End If

Dim InputObject(0)
InputObject(0) = "DrawingView"

Dim DrwSelect As Selection
Set DrwSelect = CATIA.ActiveDocument.Selection

Status = DrwSelect.SelectElement2(InputObject, "Select View", False)
CATIA.StartCommand"Activate View"

Set drawingDocument1 = CATIA.ActiveDocument
Set Sheets = drawingDocument1.Sheets
Set activeSheet = Sheets.ActiveSheet
Set views = activeSheet.Views

	Dim sSel As Selection
    Set sSel = drawingDocument1.Selection
    sSel.Search "CATDrwSearch.DrwView,sel"
    Dim drwView                 As DrawingView
    Set drwView = sSel.Item(1).Value

Dim drawingDocument1 As Document
Set drawingDocument1 = CATIA.ActiveDocument
Dim drawingSheets1 As DrawingSheets
Set drawingSheets1 = drawingDocument1.Sheets

Dim drawingSheet1 As DrawingSheet
Set drawingSheet1 = drawingSheets1.ActiveSheet
Dim drawingViews1 As DrawingViews
Set drawingViews1 = drawingSheet1.Views
Dim drawingView1 As DrawingView
Set drawingView1 = drawingViews1.ActiveView

Dim DocName
DocName  =  drawingView1.GenerativeBehavior.document.ReferenceProduct.Parent.Name

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim drawingTexts1 As DrawingTexts
Dim drawingText1 As DrawingText
Dim Text_string As String

Dim myFontSize As Double
myFontSize = "0.079"
Dim myFontName As Double
myFontName = "Monoscript821 BT"
Set DrwDocument = CATIA.ActiveDocument
Set DrwSheets = DrwDocument.Sheets
Set DrwSheet = DrwSheets.Item(1)
DrwSheet.Activate
Set DrwView = DrwSheet.Views.Item("Background View")
DrwView.Activate
set drawingtexts1 = catia.activedocument.sheets.activesheet.views.activeview.texts
Text_string = "MODEL BASE: " & DocName

On Error Resume Next
Set drawingText1 = drawingTexts1.Add(Text_string, 980, 85)
drawingText1.Text = Text_string

drawingText1.SetFontSize 0,0,myFontSize
drawingText1.SetFontName 0,0, myFontName

drawingSheet1.Views.Item(1).Activate

End Sub

Regards
Fernando

 
Works great by itself. haven't been able to get it to work in the title block script yet. I did get it positioned in the correct location and text size how I want it.
 
well i'm also wondering how to grab file name ind insert it on title block.following code works well but it gives me also a path to a file.
i need just a file name

Texts.GetItem("TitleBlock_Text_Title_7").Text=ProductDrawn.Parent.FullName
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top