Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi All,
Struggling to get this code to work, so hoping someone on here can help.
- I have an assembly with a number of truss components in it called T1, T2, T3 and so on. (This is what they're renamed to in the browser tree, not the actual file names)
- Within that same assembly, I have a number of linked parameters called A1, A2, A3 and so on.
- I would like the code to run through each pairing and apply the constraints between their respective XY planes until it runs out of trusses, in this manner:
T1 & T2, apply A1 angle constraint between occurrence XY planes
T2 & T3 apply A2 angle constraint between occurrence XY planes
T3 & T4 apply A3 angle constraint between occurrence XY planes
When I run the code I get the error message saying "Conversion from string "T1" to type 'Integer' is not valid"
' Main logic Dim asmDoc As AssemblyDocument = ThisApplication.ActiveDocument Dim compDef As AssemblyComponentDefinition = asmDoc.ComponentDefinition Dim i As Integer = 1 ' Loop through the components named T1, T2, T3, etc. Do While True Try ' Check if the angle parameter exists Dim angleParamName As String = "A" & i Dim paramExists As Boolean = False ' Loop through all the parameters to see if it exists For Each param In compDef.Parameters If param.Name = angleParamName Then paramExists = True Exit For End If Next If Not paramExists Then MessageBox.Show("Parameter " & angleParamName & " not found. Stopping the rule.") Exit Sub ' Stop the rule if the parameter is not found End If ' Get the angle parameter value Dim angleValue As Double = compDef.Parameters.Item(angleParamName).Value ' Get the current and next components in the browser tree Dim compCurrent As ComponentOccurrence = compDef.Occurrences.Item("T" & i) Dim compNext As ComponentOccurrence = compDef.Occurrences.Item("T" & (i + 1)) If compCurrent Is Nothing Or compNext Is Nothing Then MessageBox.Show("Could not find components T" & i & " or T" & (i + 1)) Exit Do End If 'Setup Proxies Dim wPlane1 As WorkPlaneProxy Dim wPlane2 As WorkPlaneProxy 'Set proxies to occurence XY planes: compCurrent = compDef.Occurrences.Item("T" & i) compNext= compDef.Occurrences.Item("T" & (i + 1)) compCurrent.CreateGeometryProxy(compCurrent.Definition.WorkPlanes.Item(3), wPlane1) compNext.CreateGeometryProxy(compNext.Definition.WorkPlanes.Item(3), wPlane2) Dim flushConst As AssemblyConstraint = compDef.Constraints.AddAngleConstraint(wPlane1, wPlane2, angleValue) ' Provide feedback MessageBox.Show("Angle constraint applied between " & compCurrent.Name & " and " & compNext.Name & " with value " & angleValue) ' Move to the next set of components i += 1 Catch ex As Exception MessageBox.Show("Finished applying constraints or encountered an error: " & ex.Message) Exit Do End Try Loop
If someone could help that would be great 😀
Thanks
Solved! Go to Solution.