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!

Link lenghts from sketch to parameters

Status
Not open for further replies.

Wydaaadi

New member
Feb 9, 2014
1
MA
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.
 
Replies continue below

Recommended for you

Someting to start ..
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 Sub
 
an Approach... Be careful and test first on test file...

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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top