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 : Link Drawing Text to View Name 1

Status
Not open for further replies.

jagandeep

Automotive
May 27, 2013
82
Hello Everyone
I want to link drawing text to the View name so that whenever I change view name text is automatically updated. Is it possible through VBA ?
 
Replies continue below

Recommended for you

By default the name of the view shown on the drawing will match what is in your tree.
If you change it in the tree it will automatically change on the drawing.
If you change it on the drawing, then it doesn't change it in the tree and looses its link.
If link is lost or text is missing, you can rmb on the view name select object> add view name.

If you want a new piece of text somewhere else on the drawing to match a view name in the tree.
Create your text as you normally would, then select outside of the "text editor" window and rmb attribute link.
Then select the view from the tree. A second window will open, select view name from here then hit ok or apply.
Anytime you change the view name, this text should also change.

Not sure how to develop a macro for this, or if it would even be any quicker to use a macro.

 
When you change the view name using the "view properties" function, it should always update the text attribute. If you wish to link the view name to some other feature, simply do what rickyt suggests and apply an attribute link to the text block.
 
Actually I am developing a macro. I am more interested in how to do it through VBA rather than manually
 
Hello Friends
After a little bit of Hit n Trial I found the solution. Here is my code

Code:
Sub CatMain()
    
    Dim MyDoc As Document
    Set MyDoc = CATIA.ActiveDocument
    
    If TypeName(MyDoc) <> "DrawingDocument" Then
        
        MsgBox "This macro works in Drafting Workbench", vbCritical, "Error"
        End
        
    End If
    
    Dim MyDrawingDoc 'As DrawingDocument
    Set MyDrawingDoc = MyDoc
    
    Dim MySelection 'As Selection
    Set MySelection = MyDrawingDoc.Selection
    
    Dim Status As String
    Dim vFilter(0)
    
    vFilter(0) = "DrawingView"
    
    MySelection.Clear
    Status = MySelection.SelectElement2(vFilter, "Select Drawing View", True)
    
    If Status = "Cancel" Then
        End
    End If
    
    Dim MyDrawingView As DrawingView
    Set MyDrawingView = MySelection.Item(1).Value
    
    MyDrawingView.Activate
    
    Dim MyDrawingSheet As DrawingSheet
    Set MyDrawingSheet = MyDrawingView.Parent
    
    Dim TextLocation(1)
    
    Status = MyDrawingDoc.Indicate2D("Indicate Text Location", TextLocation)
    
    If Status = "Cancel" Then
        End
    End If
    
    Dim MyText As DrawingText
    Set MyText = MyDrawingView.Texts.Add(vbCrLf + "Scale", TextLocation(0), TextLocation(1))
    
    Dim ParameterName As String
    ParameterName = "Drawing\" + MyDrawingSheet.Name + "\" + MyDrawingView.Name + "\Name"
    
    Call MyDrawingView.InsertViewScale(1 + Len(MyText.Text), MyText)
    Call MyText.InsertVariable(1, 0, MyDrawingDoc.Parameters.GetItem(ParameterName))
    
End Sub

Any Suggestion for improvement of same are always welcome

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor