×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Link lenghts from sketch to parameters

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.

RE: Link lenghts from sketch to parameters

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 

RE: Link lenghts from sketch to parameters

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 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources