×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Catia Macro: Create Text Below Drawing Dimensions

Catia Macro: Create Text Below Drawing Dimensions

Catia Macro: Create Text Below Drawing Dimensions

(OP)
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 --> VBA

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 

RE: Catia Macro: Create Text Below Drawing Dimensions

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

Call MyDimension.GetBoundaryBox(oValues)

Eric N.
indocti discant et ament meminisse periti

RE: Catia Macro: Create Text Below Drawing Dimensions

(OP)
Sorry The Modified code is below. Replaced MyDimension with MyDimV (Popular Catia Limitation)

CODE --> VBA

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 

RE: Catia Macro: Create Text Below Drawing Dimensions

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

RE: Catia Macro: Create Text Below Drawing Dimensions

May I suggest another method ? Just select first your dimensions.

CODE --> CATScript

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

https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...

RE: Catia Macro: Create Text Below Drawing Dimensions

(OP)
@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.

RE: Catia Macro: Create Text Below Drawing Dimensions

Then try this

CODE --> CATScript

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

https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...

RE: Catia Macro: Create Text Below Drawing Dimensions

(OP)
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.

RE: Catia Macro: Create Text Below Drawing Dimensions

(OP)
I have created views from CSYS other than default(WCS) may be that's the culprit. Any possible workaround ?

RE: Catia Macro: Create Text Below Drawing Dimensions

OK, that's amother story....

Workaround...

CODE --> CATScript

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

https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...

RE: Catia Macro: Create Text Below Drawing Dimensions

(OP)
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.

RE: Catia Macro: Create Text Below Drawing Dimensions

(OP)
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 ?

RE: Catia Macro: Create Text Below Drawing Dimensions

(OP)
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?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources