constrain with loops

constrain with loops

Anonymous
Not applicable
586 Views
3 Replies
Message 1 of 4

constrain with loops

Anonymous
Not applicable

Is there a way to constrain parts using loops? The issue im having is I cant name constraints to be different names. I've used and tried about 10 different ways to name them within the loop and I get errors everytime.  It seems like they wont go valid as a string within a constraint.

0 Likes
Accepted solutions (1)
587 Views
3 Replies
Replies (3)
Message 2 of 4

dutt.thakar
Collaborator
Collaborator
Accepted solution

@Anonymous 

You can use loops to create multiple constraints, see below code, which I have created for an example. You need to use ToString to convert it as string, just like I have used in the below code,

 

The below code will create a total of eight mates, of four components (Two in each) and they will be named,

  • Mate-ICF-1-01, Mate-ICF-1-02       (Clamp Ferrule DIN-01, Skeleton :  are the components)
  • Mate-ICF-2-01, Mate-ICF-2-02      (Clamp Ferrule DIN-02, Skeleton :  are the components)
  • Mate-ICF-3-01, Mate-ICF-3-02      (Clamp Ferrule DIN-03, Skeleton :  are the components)
  • Mate-ICF-4-01, Mate-ICF-4-02     (Clamp Ferrule DIN-04, Skeleton :  are the components)

I have also created some axis inside my skeleton part, named "Inlet-01-Axis", Inlet-02-Axis.....Inlet-04-Axis and they are also used in the same loop to create the mates.

 

You also need to be careful that you name the mates also within this loop so that you won't get an error if the name already exists.

 

	For i = 1 To 4	

Constraints.AddMate("Mate-ICF" & i.ToString & "-01", "Clamp Ferrule DIN-0" & i.ToString, "X Axis", "Skeleton", "Inlet"& i.ToString &"Axis", solutionType := MateConstraintSolutionTypeEnum.kOpposedSolutionType) Constraints.AddMate("Mate-ICF" & i.ToString &"-02", "Skeleton", "Inlet" & i.ToString & "PipeDist", "Clamp Ferrule DIN-0" & i.ToString, "Work Point5")

Next

  

I hope this will help you.

If this answer has solved your problem please ACCEPT SOLUTION and hit like if you found it helpful..!


Regards,
Dutt Thakar
LinkedIn
0 Likes
Message 3 of 4

Anonymous
Not applicable
a = 1

For ii = 1 To 4

		Components.Add("LeftSideBlock:" & ii.ToString, "PAS " & mats & " - " & SB & " x " & wIDTH & " x " & SIDERAIL_t & ".ipt")
		
	
		Constraints.AddMate("help" & a.ToString, Origin, "XY Plane", "LeftSideBlock:" & a.ToString, "Block Bottom", solutionType := MateConstraintSolutionTypeEnum.kOpposedSolutionType)
		'Constraints.AddMate("Happy" & a.ToString, Origin, "XZ Plane", "LeftSideBlock:" & a.ToString, "Black Face")
		Constraints.AddMate("LeftSideRailChannelCenterline" & a.ToString, Origin, "ChannelCenterline", "LeftSideBlock:" & a.ToString, "Block Front", offset := -(B - offset + (SB * (ii - 1)) + (BE * ii)))

		a = a + 1
		
Next

I appreciate that worked well for the first constraint, it just wont do the other two constraints. Any ideas whats going on based on the above code?

 

 

0 Likes
Message 4 of 4

Anonymous
Not applicable

Found the issue it was just a few wrong values in the constraints

 

0 Likes