Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

Link two parameters CATIA V5

Status
Not open for further replies.

xPAIVAx

Industrial
Jul 12, 2023
21
0
0
PT
Hello guys,

How can i connect two parameters "Espessura_8" and "Espessura_C8" with a formula, create a formula in the relations tab, i already have this code

Option Explicit

Dim CATIA As Object ' Declare CATIA as Object

Sub RelateParameters()
On Error Resume Next

' Define the CATIA application
Set CATIA = GetObject(, "CATIA.Application")
If CATIA Is Nothing Then
MsgBox "CATIA is not running. Please start CATIA and try again.", vbExclamation, "Error"
Exit Sub
End If

Dim partDocument As Object ' Change data type to Object
Set partDocument = CATIA.ActiveDocument

Dim product As Object ' Change data type to Object
Set product = partDocument.Product

Dim parameter8 As Object ' Change data type to Object
Set parameter8 = product.Parameters.Item("Espessura_8")

If parameter8 Is Nothing Then
MsgBox "Parameter 'Espessura_8' not found.", vbExclamation, "Parameter Not Found"
Exit Sub
End If

Dim parameterC8 As Object ' Change data type to Object
Set parameterC8 = product.Parameters.Item("Espessura_C8")

If parameterC8 Is Nothing Then
MsgBox "Parameter 'Espessura_C8' not found.", vbExclamation, "Parameter Not Found"
Exit Sub
End If

' Store the value of Espessura_8 in a variable
Dim valueToPass As Double ' Change the data type to match the parameter type
valueToPass = parameter8.Value

' Relate the parameters by setting the value of Espessura_C8 to the stored value
parameterC8.Value = valueToPass

MsgBox "Parameters related successfully. Value passed: " & valueToPass, vbInformation, "Success"
End Sub
 
Replies continue below

Recommended for you

Hi xPAIVAx-San.

We can do it this way.
Code:
・・・
    ' Store the value of Espessura_8 in a variable
    'Dim valueToPass As Double ' Change the data type to match the parameter type
    'valueToPass = parameter8.value
    
    ' Relate the parameters by setting the value of Espessura_C8 to the stored value
    'parameterC8.value = valueToPass

    Dim prms As Parameters
    Set prms = product.Parameters

    Dim prmName As String
    prmName = prms.GetNameToUseInRelation(parameter8)

    Dim relations1 As Relations
    Set relations1 = product.Relations

    Dim formula1 As Formula
    Set formula1 = relations1.CreateFormula("", "", parameterC8, prmName)
・・・
 
Hello kantoku-San.

I've done something like that but with no success, i'm going to show you with some pictures what i want exactly.

2Component_x9l0cq.png


In this picture i have the component i insert, and it has some parameters, i want to get the parameter "Espessura_C8"

1Part_b9moqd.png


Then in this picture i have the parameter "Espessura_8"

I want to create a new raltions set on the product or inside the component (preferably on the product) and relate the parameter "Espessura_C8" with the parameter "Espessura_8", witrh a formula.

And then when this above works i want the Macro to let me select the product i want to search for that parameters and create a relation on the new set for every parameter "Espessura_C8" that he founds.

i really hope that this is possible beacuse it's kinda my last hope to do it for my job :).

All the help is welcome.

Ty in advance.

Best Regards,
Paiva
 
I your parameters are located in different parts then you can't create a relation between them programmatically.

Relation within a part must include local parameters only that's why when you create a formula manually "External parameters" set gets created.

This can be replicated by copying sorc paramet to your part with Selection.Copy and then creating formula referring that copy.
 
Hi Little Cthullu, i actually could do want i wanted but its missing some things.

Code:
Option Explicit

Sub main()

Dim productDocument1 As productDocument
Set productDocument1 = CATIA.ActiveDocument

Dim product1 As product
Set product1 = productDocument1.product

Set product1 = product1.ReferenceProduct

Dim relations1 As relations
Set relations1 = product1.relations


Dim documents1 As Documents
Set documents1 = CATIA.Documents

Dim par As partDocument
Set par = documents1.Item("E_1.CATPart")

Dim p As Parameter
Set p = par.Part.Parameters.GetItem("Espessura_C8")

Dim relations2 As relations
Set relations2 = par.Part.relations

Dim formula1 As Formula
Set formula1 = relations1.CreateFormula("", "", p, "Part1\Espessura_8 ")

End Sub]

Now i want when i click to run the macro to let me choose what product i want, and then search inside that product all the components that have the paramenter name "Espessura_C8" and if it has create the relation.
 
Status
Not open for further replies.
Back
Top