Let’s Start Programming! Forums CATIA Macro Programming to change parameter in CATProduct

This topic contains 4 replies, has 2 voices, and was last updated by  vlastimil.kovarik@brano.eu 3 years, 1 month ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • #1414

    I have one question. How to change parameter in top assembly (marked by blue in the picture) from the formular? If I have tried it parameter was changed in first Part only (marked by red in the picture) in the tree structure not in top assembly…
    Notice: parameter in top assembly has to have like parameter in single part.
    Could anybody help me, please?
    Thank you very much.



    Are you writing a macro to change the value of the parameter in the assembly?


    Yes, I do.



    There are a few ways to do it. Would you be able to post your code so we can see what you tried?

    Below loops through the Product’s parameters until it finds the one you want, then changes the value.

    Dim oRootProduct as Product
    Dim oParameters as Parameters
    Dim oParameter as Parameter

    Set oRootProduct=catia.activedocument.product
    Set oParameters=oRootProduct.Parameters

    For I = 1 to oParameters.Count
    If instr(ucase(oParameters.item(i).Name), “NAZEV”) <> 0 then
    Set oParameter = oParameters.Item(I)
    oParameter.Value = “YourValue”
    End if

    You can also find the parameter by name instead of looping. I think the name of the parameter is actually the path.

    On Error Resume Next
    oParameter = oParameters.Item(oRootProduct.Name & “\” & “Nazev”)
    If err.number <> 0 then
    Msgbox “Parameter does not exist”
    oParameter.Value = “YourValue”
    End if
    On error GoTo 0


    Hello Matt,
    thanks for reply. Piece of my code is here:
    ‘transfer parameters from formular to CATIA

    Private Sub cmbUlozParametry_Click()

    Set MujDokument = CATIA.ActiveDocument
    NazevDokumentu = MujDokument.Name ‘to get Name of the Document
    Extract = Right(NazevDokumentu, 7) ‘to save type of the document to variable

    Dim MojeParametry As Selection

    Select Case Extract

    Case “CATPart”

    Set MujPart = MujDokument.Part
    Set oParam = MujPart.Parameters

    Set sNazev = oParam.Item(“Nazev”)
    sNazev.Value = txbNazev

    Case “Product”

    Set MujProdukt = MujDokument.Product
    Set oParam = MujProdukt.Parameters

    Set sNazev = oParam.Item(“Nazev”)
    sNazev.Value = txbNazev

    Case “Drawing”

    NeniCATPartNeniCATProduct = MsgBox(“Active document isn’t CATPart or CATProduct!”, 48, “Bad Type of Document”)

    End Select

    End Sub

    Problem is that name of the parameter has to be same in CATProduct and in all his CATParts. I’m thinking about this solution – to select desired CATProduct interactive (this is what I’m to able do ) and change parameter in this selection (I don’t know how arrange it…)
    Thank you.

Viewing 5 posts - 1 through 5 (of 5 total)

The forum ‘CATIA Macro Programming’ is closed to new topics and replies.