Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

CATIA Macro to give Overall Dimensions to a View

AbhishekChavan

Automotive
Mar 2, 2025
6
1746683678342.png

I need a CATIA Macro that can create overall or maximum dimensions of a projected drawing view. The geometrical elements from the view has GenerativeBehaviour associated with it and the objects are named "GeneratedItem" with type View. Therefore, I cannot access the geometrical elements to give Dimensions with Dimensions.Add2 Method. Can anyone help me here?

1746684074846.png


I tried with the below code to return geometrical elements and was planning to use Dimensions.Add2 once I can get the elements as reference.



Code:
Sub MeasureElements()


    Dim drawDoc As DrawingDocument
    Set drawDoc = CATIA.ActiveDocument
    
    Dim drawSheet As DrawingSheet
    Set drawSheet = drawDoc.Sheets.ActiveSheet
    
    Dim drawView As DrawingView
    Set drawView = drawSheet.Views.activeView
    
    Dim geoElements As GeometricElements
    Set geoElements = drawView.GeometricElements
    
    Dim geoElement As GeometricElement
    
    
    
'    For Each geoElement In geoElements
'
'
'        Debug.Print TypeName(geoElement)
'
'
'
'    Next geoElement
'
'
'
'    Debug.Print geoElements.Count
    
    
    
    
    Dim sel1 As Selection
    Set sel1 = drawDoc.Selection
    
    sel1.Add drawView
    
    sel1.Search "Name=GeneratedItem,sel"
    
    
    
    
    For i = 1 To sel1.Count2
    
        Debug.Print TypeName(sel1.Item2(i).Value)
        
    Next i
    
    

End Sub
 
Replies continue below

Recommended for you

 
Hi LWolf,

Thank you for the reply.

I tried using selection.search query but there is no object of type Line in my view. As you can see in the below image, the query does not return any object as the object type seems to be "GeneratedItem" instead of "Line".

Notice that the query from 1st Image does not return any object but the second query does.


Img 1: Search Query

1746797689028.png


1746797340980.png
 
Try this in CATScript (is just an example, you need to modify for your needs)

Code:
Language="VBSCRIPT"
Sub CATMain()
Set drawingDocument1 = CATIA.ActiveDocument
Set drawingSheets1 = drawingDocument1.Sheets
Set drawingSheet1 = drawingSheets1.Item("Sheet.1")
Set drawingViews1 = drawingSheet1.Views
Set drawingView1 = drawingViews1.Item("Front view")
Dim BoundingBox(3)
drawingView1.Size BoundingBox
msgbox BoundingBox(0) & " " & BoundingBox(1) & " " & BoundingBox(2) & " " & BoundingBox(3)
end sub
 

Part and Inventory Search

Sponsor