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!

Catia Macro: Create Text Below Drawing Dimensions

Status
Not open for further replies.

jagandeep

Automotive
May 27, 2013
82
IN
Hello All,
I have to create text indicating number below each and every dimension for every view. See the attached image for more clarity. Right now I am doing it manually. I want to automate this process. I have created a macro for it. But the problem is that I text is not coming at a desired place. Its location is far away from dimensions. Any help regarding this will be highly appreciated. Here is my code.

Code:
Sub CATMain()

    Dim MyDoc As DrawingDocument
    Dim MySelection As Selection
    Dim MySheet As DrawingSheet
    Dim MyDrawingView As DrawingView
    Dim MyDimensions As DrawingDimensions
    Dim MyDimension As DrawingDimension
    Dim MyText As DrawingText
    Dim oValues(5)
    
    Set MyDoc = CATIA.ActiveDocument
    Set MySheet = MyDoc.DrawingRoot.ActiveSheet
    
    Set MySelection = MyDoc.Selection
    
    If MySelection.Count = 0 Then
    
        MsgBox "Nothing Selected"
        End
        
    Else
    
        If MySelection.Item(1).Type = "DrawingView" Then
        
            Set MyDrawingView = MySelection.Item(1).Value
            Set MyDimensions = MyDrawingView.Dimensions
            
            Set MyDimension = MyDimensions.Item(1)
            
            Dim MyDimV
            Set MyDimV = MyDimension
            
            Call MyDimension.GetBoundaryBox(oValues)
            'MsgBox oValues(1)
            Set MyText = MyDrawingView.Texts.Add("Temp", oValues(0), oValues(1))
            
        Else
        
        MsgBox "Wrong Selection"
        
        End If
        
    End If

End Sub
 
Replies continue below

Recommended for you

trying your code on R20, I have error on line:

Call MyDimension.GetBoundaryBox(oValues)

Eric N.
indocti discant et ament meminisse periti
 
Sorry The Modified code is below. Replaced MyDimension with MyDimV (Popular Catia Limitation)

Code:
Sub CATMain()

    Dim MyDoc As DrawingDocument
    Dim MySelection As Selection
    Dim MySheet As DrawingSheet
    Dim MyDrawingView As DrawingView
    Dim MyDimensions As DrawingDimensions
    Dim MyDimension As DrawingDimension
    Dim MyText As DrawingText
    Dim oValues(5)
    
    Set MyDoc = CATIA.ActiveDocument
    Set MySheet = MyDoc.DrawingRoot.ActiveSheet
    
    Set MySelection = MyDoc.Selection
    
    If MySelection.Count = 0 Then
    
        MsgBox "Nothing Selected"
        End
        
    Else
    
        If MySelection.Item(1).Type = "DrawingView" Then
        
            Set MyDrawingView = MySelection.Item(1).Value
            Set MyDimensions = MyDrawingView.Dimensions
            
            Set MyDimension = MyDimensions.Item(1)
            
            Dim MyDimV
            Set MyDimV = MyDimension
            
            Call MyDimV.GetBoundaryBox(oValues)
            'MsgBox oValues(1)
            Set MyText = MyDrawingView.Texts.Add("Temp", oValues(0), oValues(1))
            
        Else
        
        MsgBox "Wrong Selection"
        
        End If
        
    End If

End Sub
 
yeah I was about to post this

The text comes in right position for me on a simple length dim.

Eric N.
indocti discant et ament meminisse periti
 
May I suggest another method ? Just select first your dimensions.

Code:
Sub CATMain()
 
Dim MySel As Selection
Set MySel = CATIA.ActiveDocument.Selection
 
Dim MyDim As DrawingDimension
Dim Array1 As String
Dim Array2 As String
Dim Array3 As String
Dim Array4 As String
For i = 1 To MySel.Count
If TypeName(MySel.Item(i).Value) = "DrawingDimension" Then
Set MyDim = MySel.Item(i).Value
MyDim.GetValue.GetBaultText 1,Array1,Array2,Array3,Array4
Dim myTXT
myTXT = "No. 000" & i 
MyDim.GetValue.SetBaultText 1,Array1,Array2,Array3,myTXT
End If
Next
 
End Sub

Regards
Fernando

 
@Ferdo Earlier I was thinking of same method but we want text font size to be different than the dimension font and the text must be easily editable by double clicking. That's why I chosen the method I posted. That's what we do manually.
 
Then try this

Code:
Sub CATMain()
 
    Dim MyDoc As DrawingDocument
    Dim MySelection As Selection
    Dim MySheet As DrawingSheet
    Dim MyDrawingView As DrawingView
    Dim MyDimensions As DrawingDimensions
    Dim MyDimension As DrawingDimension
    Dim MyText As DrawingText
    Dim oValues(5)
   
    Set MyDoc = CATIA.ActiveDocument
    Set MySheet = MyDoc.DrawingRoot.ActiveSheet    
    Set MySelection = MyDoc.Selection    
    If MySelection.Count = 0 Then
    
        MsgBox "Nothing Selected"
        Exit Sub
        
    Else
        If MySelection.Item(1).Type = "DrawingView" Then
        
            Set MyDrawingView = MySelection.Item(1).Value
            Set MyDimensions = MyDrawingView.Dimensions
            
            For i = 1 To MyDimensions.Count
            Set MyDimension = MyDimensions.Item(i)  
            Dim MyDimV
            Set MyDimV = MyDimension
             Call MyDimV.GetBoundaryBox(oValues)
            Set MyText = MyDrawingView.Texts.Add("No. 000" & i, oValues(0), oValues(1))
            
            Next            
        Else        
        MsgBox "Wrong Selection"
        
        End If
        
    End If
 
End Sub

Regards
Fernando

 
Ferdo problem is not of for loop( which is not included my code) but with the position of text in the view.
3D model has many axis systems. is it creating some problem in my case ??
Text is created at position that is far away from the respective dimension.
 
I have created views from CSYS other than default(WCS) may be that's the culprit. Any possible workaround ?
 
OK, that's amother story....

Workaround...

Code:
Sub CATMain()
 
msgbox "Select View to Activate"
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"
DrwSelect.Clear
 
Dim ZAEHLER As integer
Dim Status
Dim Position(1)
Dim drawingTexts1 As DrawingTexts
Dim drawingText1 As DrawingText
Dim Textbezeichnung As String
 
set drawingtexts1 = catia.activedocument.sheets.activesheet.views.activeview.texts
counter = inputbox ("Starting Numberr : default is written No. 000", "Input", 1)
msgBox "You can EXIT at any moment using ESC taste"
do 
 
Status = CATIA.ActiveDocument.Indicate2D("Select point (EXIT with ESC)", Position)
If (Status = "Cancel") Then
MsgBox "Aborted"
Exit Sub
End If
 
On Error Resume Next
 
TextCounter = "No. " & "000" & counter
Set drawingText1 = drawingTexts1.Add(TextCounter, Position(0), Position(1))
drawingText1.Text = TextCounter
 
counter = counter+1
loop
 
End Sub

Regards
Fernando

 
Thanks for your help dear. However I think I have to have a look at drafting interface as most of the times no of dimensions are much more than in the picture.
 
Now Its working, View was not activated we I ran this macro. Stupid me.

Now I have another problem. Can we specify text Position and orientation link with VBA during its creation ?
 
Anyone please help me how to specify orientation link of text according to dimension ?

I used MyText.AssociatedElement = MyDimension but it only creates positional link. However my requirement is for orientation link otherwise I have to manually orient each and every dim in case of non-horizontal orientation.

Is there any direct way to get orientation of dim text and apply same to the text?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top