Link lenghts from sketch to parameters
Link lenghts from sketch to parameters
(OP)
Hello all,
I have a big problem, I try to link automatically using macros constraints (Lenght for exemple) from sketchers to parameters. I renamed about 300 constraints (lenghts) using specifically names and I need to link them to paramaters using the same names.
My parameters should have the constraints name and value. Is this possible using macros?
Thank's in advance.
I have a big problem, I try to link automatically using macros constraints (Lenght for exemple) from sketchers to parameters. I renamed about 300 constraints (lenghts) using specifically names and I need to link them to paramaters using the same names.
My parameters should have the constraints name and value. Is this possible using macros?
Thank's in advance.





RE: Link lenghts from sketch to parameters
Take a look here
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...
RE: Link lenghts from sketch to parameters
CODE -->
Sub Link_Parameter_to_Dimension() Dim oPart As Part Set oPart = CATIA.ActiveDocument.Part Dim D1Name As Object Set D1Name = oPart.FindObjectByName("Diameter_1") Dim D1 As RealParam Set D1 = oPart.Parameters.CreateReal("D1", 2) Dim oRelations As Relations Set oRelations = oPart.Relations Dim Param As Parameters Set Param = oPart.Parameters.SubList(D1Name, True) Dim oFormula As Formula Set oFormula = oRelations.CreateFormula("", "", Param.Item(1), "(D1*1in )/2") End SubRE: Link lenghts from sketch to parameters
CODE -->
Sub Test() Set Document = CATIA.ActiveDocument Dim oPart As Part Set oPart = Document.Part Dim oBody As Body Set oBody = oPart.Bodies.Item("PartBody") Dim oSketch As Sketch Set oSketch = oBody.Sketches.Item("Sketch.1") Dim oConstraints As Constraints Set oConstraints = oSketch.Constraints For i = 1 To oConstraints.Count Set Cst = oConstraints.Item(i) If Cst.Type = catCstTypeDistance Then Dim sName As String sName = Cst.Name Dim Dime As Object Set Dime = Cst.Dimension Dim sParam As String sParam = Dime.Name Dim lValue As Double lValue = Dime.Value / 25.4 Link_Parameter_to_Dimension sName, sParam, lValue Else End If Next i End Sub Function Link_Parameter_to_Dimension(sName As String, sParam As String, lValue As Double) Dim oPart As Part Set oPart = CATIA.ActiveDocument.Part Dim D1Name As Object Set D1Name = oPart.FindObjectByName(sName) Dim D1 As RealParam Set D1 = oPart.Parameters.CreateReal(sName, lValue) Dim oRelations As Relations Set oRelations = oPart.Relations Dim Param As Parameters Set Param = oPart.Parameters.SubList(D1Name, True) Dim sBodyFormula As String If Right(sParam, 6) = "Radius" Then sBodyFormula = "(" & sName & "*1in)/2" Else sBodyFormula = "(" & sName & "*1in)" End If Dim oFormula As Formula Set oFormula = oRelations.CreateFormula("", "", Param.Item(1), sBodyFormula) End Function