- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm curious if it's possible to access a constraint by name with the new Ilogic API?
My current attempt gives the following error:
MsgBox(Constraints("Mate:25").ToString())
The code here isn't meant to do anything other than let me know if I can access it by name. I have a program that generates assemblies with a known number of parts (known for each assembly, but this changes for every instance of the assembly and it has basically an infinite number of permutations, which is why I generate new assemblies rather than using one with a basic setup)
Currently I don't add a name, but below is the code where I constrain each new part. The basic concept is that if I later change my parameters, I should be able to run the overhead function again, find the constraints by name for each part based off that part name and tell it "This should be a mate. If it is, leave it. If it isn't, change it to a mate."
Does anyone know how to access the constraint through the new Constraints API or do I need to go back into ThisDoc.Document.ComponentDefinition.Constraints in order to access it? My preference would be to use my generation function and the creation function at the same time (i.e. check if it exists, if yes then update, if no then create)
'Creates constraints for picked faces off of the base planes for the file
Function CreateConstraints(DConstraintType, DConstraint, AConstraintType, AConstraint, DepthConstraintType, DepthConstraint, Orientation)
'Declare Document Variables
Dim oAssemblyDef=ThisDoc.Document.ComponentDefinition
Dim CompOcc As ComponentOccurrence = oAssemblyDef.Occurrences.Item(oAssemblyDef.Occurrences.Count)
Dim currentPlane As String
If DepthConstraintType = "Mate" Then Constraints.AddMate("", "", "XY Plane", CompOcc.Name, "XZ Plane", DepthConstraint)
If DepthConstraintType = "Flush" Then Constraints.AddFlush("", "", "XY Plane", CompOcc.Name, "XZ Plane", DepthConstraint)
If Orientation = "Vertical" Then
currentPlane = "XY Plane"
Else
currentPlane = "YZ Plane"
End If
'Constrain to XZ Plane
If AConstraintType = "Mate" Then Constraints.AddMate("", "", "XZ Plane", CompOcc.Name, currentPlane, AConstraint)
If AConstraintType = "Flush" Then Constraints.AddFlush("", "", "XZ Plane", CompOcc.Name, currentPlane, AConstraint)
If Orientation = "Vertical" Then
currentPlane = "YZ Plane"
Else
currentPlane = "XY Plane"
End If
'Constrain to YZ Plane
If DConstraintType = "Mate" Then Constraints.AddMate("", "", "YZ Plane", CompOcc.Name, currentPlane, DConstraint)
If DConstraintType = "Flush" Then Constraints.AddFlush("", "", "YZ Plane", CompOcc.Name, currentPlane, DConstraint)
End Function
Edit: Also, is it possible to check if the constraint exists without just writing a for each loop? Right now if I try to access it by name and it doesn't exist it just throws an error but I don't see a function to check if the overall ThisDoc.Document.ComponentDefinition.Constraints actually contains the constraints so I could just tell it to check beforehand. Perhaps something to do with the IQueryable conversion?
Thank you in advance!
Solved! Go to Solution.