Monday, July 2, 2012

CATIA Drawing CATScript Features

Scripting Drafting features

One area I have to admit I have neglected to write about in these posts and articles is how to write CATScripts for drafting and 2D drawings. I have not used this workbench myself as extensively as some of the others (like GSD) but I will share any information or tips as I pick up on them. Here we go.

CATIA’s drafting workbench features two basic types of grouping all 2D features: Generative Drafting takes the 3D CATIA objects and represents them in 2D views within a drawing while InteractiveDrafting represents 2D features directly created in the 2D views with no 3D data associated with it.

Scripting Drafting features Overview

Listed below are some of the key features used in macros for CATIA drawings.
  • DrawingSheets and DrawingViews
  • Main View and Background view.
  • ActiveSheet.
  • ActiveView.
  • The Front View and the others
  • Generative Views
  • Interactive Views
  •  Filling the Title block
  • Extract Dimensions

DrawingSheets and DrawingViews

The DrawingDocument object aggregates a DrawingSheets collection. Each DrawingSheet of this collection aggregates a DrawingViews collection.

Main View and Background view.

A drawing contains at least two views: the background view and the Main View, that is the view in which you can draw just after creating a drawing. The ActiveSheet: The active sheet can be found in the DrawingSheets collection. The ActiveView can be found in the DrawingViews collection

CATIA Drawing viewer: The Front View and the others

A DrawingView can be the “Front View” or another view relative to the “Front View”.DrawingViewGenerativeBehavior can define both behavior: DefineFrontView() defines the “Front View” and its direction. DefineProjectionView() defines another view relative to the “Front View”
Other methods allow creating other types of views such as Section Views, Detail Views, etc. Generative Views - DrawingViewowns a “document” property that allows you to specify the associated 3D document from which the “generative view” is created.

Interactive Views - DrawingViewowns a “Factory2D” property that allows you to create 2D features.This kind of view is called an “Interactive View”.

Filling the Title block - The Texts collection allows you to create 2D texts in the drawing

Extract Dimensions - A DrawingSheet has the method called GenerateDimension() that generates dimensions automatically in all the views from the 3D geometry.

Below are example scripts to help you get started! Then sign up to the VB Scripting for CATIA V5 newsletter for even more CATIA macros.

Download Architects Cad Drawings: Subsribe To Access Our Huge Database Of Downloadable Cad Symbols, Drawings & Detail
'Revised June 21, 2012
'This macro will unlock all drawing views 

Sub CATMain() 

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,all" 
For i = 1 To sSel.Count 
If sSel.Count = 0 Then MsgBox "Select one view!", vbCritical,
 "Lock/Unlock": Exit Sub 
If TypeName(sSel.Item(i).Value) <> "DrawingView" Then MsgBox 
"Selected element is not a drawing view! Select a drawing view.",
 vbCritical, "Lock/Unlock": Exit Sub 
Dim drawView As DrawingView 
Set drawView = sSel.Item(i).Value 
      drawView.LockStatus = False 
End Sub

'This macro will change drawing dimensions from mm to inch 

Sub CATMain() 

Dim drawingDocument1 As DrawingDocument 
Set drawingDocument1 = CATIA.ActiveDocument 
Dim selection1 As Selection 

Set selection1 = drawingDocument1.Selection 
selection1.Search "CATDrwSearch.DrwDimension,all" 
For i = 1 To selection1.Count 
 Dim Dimension1 As DrawingDimension 
 Set Dimension1 = selection1.Item(i).Value 
 Dim DimDimValue As DrawingDimValue 
 Set DimDimValue = Dimension1.GetValue 
 DimDimValue.SetFormatName 1, "NUM.DINC" 

End Sub 


  1. more and more information about CAD drafting is mentioned in this blog. Please read them and keep in mind. ----- Thanks

  2. how to update the TEXT of annotation in CATSCRIPT


I'd love to hear from you!