Search code examples
vbafeature-selectioncatia

Using VBA in Catia for selection and changing and attribute


I'm attempting to change attributes in Catia on an active selection only. I'm looking to take this code and generalize it so that instead of targeting 1 specific item, it will activate the macro on whatever item I have selected.

Sub CATMain()

    Dim documents1 As Documents
    Set documents1 = CATIA.Documents

    Dim partDocument1 As PartDocument
    Set partDocument1 = documents1.Item("Test 1.CATPart")

    Dim product1 As product
    Set product1 = partDocument1.GetItem("Test 1")

    product1.Revision = "test"

    product1.Definition = "yo"

End Sub

Thank you for you help.


Solution

  • Answered my own question...

    Sub CATMain()
    
        Dim objSel As Selection
        Set objSel = CATIA.ActiveDocument.Selection
    
        objSel.Item(1).Value.ATTRIBUTE = "hi"
    
    End Sub
    

    This changes the desired attributes of the selected item.