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!

Change attribute links path in CATDrawing 1

Status
Not open for further replies.

DDRS91

Mechanical
Apr 21, 2021
2
Greetings
following scenario:

I have a drawing with a title block in which individual textblocks are linked to properties of a 3D model using attribute links. I want to use this drawing as a template, and when a view of a new 3D model is created, the attributes should point to the properties of the new 3D model. I can see the links under Edit> Links. But if I want to replace the pointed document path, I get the message "The link refused the document."

Can this be solved with a macro? I tried to record the process with a macro, with no success. Do you have any other suggestions?

Thanks in advance!

BR
Dani
 
Replies continue below

Recommended for you

The short answer is yes, you can automate your text boxes being re-linked to 3D attributes. **but** some attributes may not be accessible through visual basic. The document refusing link can be tricky, for instance replacing a catproduct with a catpart will fail(there are work-arounds for this). What I usually find is if the geometry(although identical in 2 files) was created fundamentally differently, it will fail. As a side note, trying to record a macro in a drawing is usually worthless. I cant recall anytime when it worked across several revisions of V5.
 
The trick that worked for me is to make the desired parameters in drawing. For now keep the drawing "geometry free" Then link the text boxes (attribute link) to those parameters. In the final step you link the parameters in the drawing to the ones in the part or product (keep link). These parameters in part or product NEED TO BE PUBLISHED beforehand. Save this drawing and your dummy part as your "master". Whenever you need a new drawing just go to FILE - NEW FROM. Select the master drawing, Save as new and then change the links of the drawing to match the new part or product.

Works for me as I don't have the skills necessary to build scripts to make my own titleblock. It's a little bit tedious at first,you need to make different paper formats "master" drawings, but it's a usable approach.


Best regards,

Costin Ruja
 
Hello,

thanks for your responses!

Would it be easier and more stable, if a macro creates the attribute links, instead of relinking them?

The idea is to have a drawing with no geometry, create a view and link a 3D file, run the macro once (the macro should recognize the link to the 3d and read the added properties) and then link textblocks to the added properties in the 3D via attribute links. Important is, that the macro should only be runned once and not everytime a change is made in the 3D.

It should be automated as much as possible. Manually relinking drawings to parts/product is not an option...

BR
Dani
 
Assuming you complete a working script, yes it would be easier. You'll find it difficult to populate textboxes on a drawing, they tend to be named textbox.somerandomnumber. Same with charts. If there are multiple occurrences on your drawing, VB can't tell the difference unless they are named specifically and the exact same on every drawing you run the macro on. The only other way I can think of getting past this is if the textbox had the same text in the textbox to start. example; one text box has "Weight:" the next "Volume:". you could possibly search for those strings within each textbox and go from there.

If you're doing this from a template drawing, it's a snap. just rename the textboxes whatever you want and program accordingly.
 
Hmmmm... I used to play with a similar solution (not exactly same but similar). I came upon a "problem" that an user can create multiple attribute links of "same value" - if the script is initialized multiple times. That's why I decided to delete old text and recreate it with attribute link and same properties. Maybe this isn't a optimal solution but it works for me. See if you can use something from it...

Code:
Private Sub ConnectParameters(oParaSet As ParameterSet, oDraw As drawingdocument)

    If oParaSet.name <> "Podaci za sastavnicu" Then
            MsgBox ("Niste odabrali odgovarajući set parametara.")
            Exit Sub
    End If
   
    '''''''''''''''''''''''''''''''''''''''''''''''''''''
    Dim intIndex1 As Integer
    Dim oText As DrawingText
    Dim oSheet As DrawingSheet
    Dim oView As DrawingView
    Dim x As Double
    Dim y As Double
    Dim tName As String
    Dim tSize As Double
    Dim tAngle As Integer
    Dim tAnchor As Integer
    For Each oSheet In oDraw.Sheets
        oSheet.Activate
        Set oView = oSheet.Views.item("Background View")
        oView.Activate
    
        For Each oText In oView.Texts
            If oText.name = "Broj dijela" Or oText.name = "Naziv dijela" Or oText.name = "Masa" Or oText.name = "Naziv sirovine" Or oText.name = "Sirovina" Then
                x = oText.x
                y = oText.y
                tName = oText.name
                tAngle = oText.Angle
                tSize = oText.TextProperties.FONTSIZE
                tAnchor = oText.AnchorPosition
                            
                Set oSelection = CATIA.ActiveDocument.selection
                oSelection.Clear
                oSelection.Add oText
                oSelection.Delete
                
                Set oText = oView.Texts.Add("", x, y)
                SetProperties oText, tName, tSize, tAnchor, tAngle
            
                Select Case oText.name
                    Case "Broj dijela"
                        oText.InsertVariable 0, 0, oParaSet.DirectParameters.item(6)
                    Case "Naziv dijela"
                        oText.InsertVariable 0, 0, oParaSet.DirectParameters.item(4)
                    Case "Masa"
                        oText.InsertVariable 0, 0, oParaSet.DirectParameters.item(7)
                    Case "Naziv sirovine"
                        If oParaSet.DirectParameters.Count > 7 Then
                            oText.InsertVariable 0, 0, oParaSet.DirectParameters.item(9)
                        Else
                            oText.Text = ""
                        End If
                    Case "Sirovina"
                        If oParaSet.DirectParameters.Count > 7 Then
                            oText.InsertVariable 0, 0, oParaSet.DirectParameters.item(8)
                        Else
                            oText.Text = ""
                        End If
                End Select
            End If
        Next
        oSheet.Views.item("Main View").Activate
    Next
    
    '''''''''''''''''''''''''''''''''''''''''''''''''''''
    
End Sub

Private Sub SetProperties(oText As DrawingText, oName As String, oSize As Double, oAnchor As Integer, oAngle As Integer)
    oText.name = oName
    oText.SetFontSize 0, 0, oSize
    oText.AnchorPosition = oAnchor
    oText.Angle = oAngle
    oText.SetFontName 0, 0, "ISOCPEUR (TrueType)"
    oText.TextProperties.Blanking = 1
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor