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!

Edit an existing Title Block using VBA Macro 1

Status
Not open for further replies.

CheeseMaker13

Aerospace
Sep 25, 2012
42
GB
Hi,

First post!!

I've been tasked to automatically create drawings based on an excel spreadsheet with all the required data.

I've managed to get a script to open a new drawing, add the required text and save it using the correct naming scheme.

The problem I'm up against is that some of the information in the spreadsheet needs to go into a company set title block.

All the scripts I've found so far create the block from scratch, which isn't useful.

I was thinking I could open up a template drawing and then input all the required data like that, but I still need to be able to edit the stock title block!!!

Anybody got any thoughts on either:

A) How to add a title block inputting the required data.
B) Edit an existing title block.

This is the code that opens the drawing:

Code:
Set oDocument = CATIA.Documents.Add("Drawing")
Set iDocument = CATIA.ActiveDocument
Set iSheets = iDocument.Sheets
Set iSheet = iSheets.Item(1)
Set iView = iSheet.Views.Item("Background View")
Set iTexts = iView.Texts
 
Replies continue below

Recommended for you

Can't work out to edit my post so here is the rest of it:

If anybody has any thoughts that would be great.

Many Thanks,
CR.
 
More on this:

My company has a macro with a toolbar (Supplied by ext company so no access to it) which imports parts of the title block from another .CATdrawing, arranges them and inputs the data given in a User Input form.

Is there any way of running this "Create_Title_Block" toolbar/tool button from my script, inputting the required data into the userform automatically, before clicking 'ok'.

Pain in the backside but there you go!
 
Few clarifications for us:

The title block is created in macro or ?

If is created in macro then you can modify it or you can input a text at a specific position in a specific view/sheet. I believe there are few codes in this forum as examples.

Yes,, you can run from your script another one, depending on what is it your second one (exe file, CATScript or whatever). If you want to type in a user form something you can use sendkeys method for example (is not so nice but it can be done). Search on Internet, I"m sure you can find something.

Regards
Fernando

 
Hi,

I have NO access to the script that generates the title block, nor do I know where it is stored within the CATIA files (even after searching!)

There is a button on the tool bars, but that is all I have to launch this script!!
 
OK, now is clear. In this case you can write on the drawing sheet a text in a specific point location. Put a point where you want to add text, take the coordinates and do it in a separate macro. Your text still can be added in the title block field, is not neccessary to open and edit the title block (I suppose is not a picture).

Let me know if you manage to do it.

Regards
Fernando

 
dear author:

Code:
Language="VBSCRIPT"

Sub CATMain()
Dim DrwDocument As Document
 Dim drwsheets As DrawingSheets
 Dim drwsheet As DrawingSheet
 Dim drwviews As DrawingViews
 Dim drwview As DrawingView
Dim DrwTexts As DrawingTexts
Dim DrwText  as DrawingText
Set DrwDocument   = CATIA.ActiveDocument
Set drwsheets = DrwDocument.Sheets
set drwsheet = drwsheets.item(1)    ////Only one sheet
set drwviews = drwsheets.item(1).views
set drwview = drwviews.item(2)
'msgbox drwviews.item(2).name   ////BackgroundView item ID=2 - to find appropriate View
Set DrwTexts     =  drwview.Texts
Set DrwText     = DrwTexts.GetItem("TitleBlock_Text_Design")   ///How to find text box name - just right-click on the desired text and find "... Object" - those dots are Text Item name
'msgbox DrwText.text
DrwText.text = "ASDF"  //change text to ASDF
End Sub

if You have any questions feel free to ask

With regards
Lukasz
 
I'm new to creating macros for CATIA. This was very helpful because I have the same issue. The question I have is how do I apply this to a multi sheet drawing. Any assistance is greatly appreciated.
 
Hi,

Check with tools -> Macros -> and macro libraries.
This should give the details of path of one or more directories from which you can use the edit option to check on macro.

However, as it is an VBA macro and it has been supplied by ext company, i assume there will be security (Password) for the macro without which you can't do any editing in it.

Regards,
Maddy
 
CATIA.ActiveDocument.Sheets.Count
(as Integer) will gave You number of sheets in Your drawing


the next step is to insert loop

If You have any problems feel free to ask
 
i apologise for resuming an old thread, but i am wondering, what is the benefit of using a macro for the title block versus a catdrawing template that has it drawn (or imported from a dwg)?

also, is it possible to populate the template (from dwg) title block automatically like in solidworks (based on custom properties, part properties - weight... or filename)?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top