Using forms to set assembly configuration

Using forms to set assembly configuration

gwallaceCJ39B
Explorer Explorer
2,047 Views
14 Replies
Message 1 of 15

Using forms to set assembly configuration

gwallaceCJ39B
Explorer
Explorer

I'm sure this has been beat to death already, I tried searching the forums but most examples were way over my head.

 

I'm trying to get back into forms and iLogic, as it's been years and my prior experience was limited.  Basically, I want to use a form to select the configuration of the breaker stabs in the attached assembly (_V_FIXED filename).  I'm starting out with just one type of breaker stab and trying to use a form to determine if it should be rotated vertical or horizontal.  I thought iMates would be something that would help, but my understanding is limited to the basic "alt-drag" operation.

 

My thought process so far:

-set up multi-value parameters for the top and bottom row of stabs, add those to the form for when the logic is done

-set up composite iMate for the breaker stab (two inserts, one flush) for positioning

-set up a matching composite iMate for the breaker, also set up the same composite iMate rotated 90° (I was going to try and enable one and disable the other based on the form selection)

-set up a rule that will enable/disable a set of iMates based on form selection

 

Assuming the thought process is in the right direction, I'm running into a brick wall when it comes to writing the rule.  Programming has never been my strong suit, so most examples I found were way over my head.  If anyone could nudge me in the right direction, I'd appreciate it.  At the end of this exercise, I'm hoping to be able to change the top and bottom rows of stabs independently between Type 1 vertical, Type 1 horizontal, and Type 2

0 Likes
Accepted solutions (1)
2,048 Views
14 Replies
Replies (14)
Message 2 of 15

dhaval3112
Advocate
Advocate

dhaval3112_0-1674196421712.png

 


If
BottomConfig = "Front Connection" Then Component.IsActive("Standard Breaker Stab:1") = True Component.IsActive("Standard Breaker Stab:2") = False Constraint.IsActive("iComposite:1") = True Else If BottomConfig = "Sideways" Then Component.IsActive("Standard Breaker Stab:1") = False Component.IsActive("Standard Breaker Stab:2") = True Constraint.IsActive("iComposite:2") = True End If

 

Message 3 of 15

A.Acheson
Mentor
Mentor
Accepted solution

Here is a simple way to control the manually constrained imates

 

Select TopConfig

	Case "Sideways"
		Try
			Constraint.IsActive("iComposite:2") = False
			Constraint.IsActive("iComposite:1") = True
		Catch
		End Try
	
	Case "Up/Down"
		Try
			Constraint.IsActive("iComposite:1") = False
			Constraint.IsActive("iComposite:2") = True
		Catch
		End Try
		
End Select

 

 If you want to get a little more creative and add the component and constrain while giving the constraints meaningful names.

 

Dim Vert_iMateName As String 
Dim Horiz_iMateName As String 
Dim Comp1Name = "Standard Breaker Stab"

Try
     'Reference the occurrence
	Dim Standard_Breaker_Sta = Component.InventorComponent(Comp1Name)
	
    'Create imate names
	Vert_iMateName = Standard_Breaker_Sta.Name & "-Vert"
	Horiz_iMateName = Standard_Breaker_Sta.Name & "-Horiz"
Catch
   'Occurrence not found so add one.
	Dim Standard_Breaker_Sta  = Components.Add(Comp1Name,"Standard Breaker Stab.ipt")

   'Create imate names.                          
	Vert_iMateName = Standard_Breaker_Sta.Name & "-Vert"
   
  'Add imate.
	Vert_iMate = Constraints.AddByiMates(Vert_iMateName, Standard_Breaker_Sta.Name, "iMates","232", "TopLeftSideways")

  'Switch off imate to avoid conflict in adding a seperate one.
	Vert_iMate.IsActive = False
  
'Repeat for next imate.
	Horiz_iMateName = Standard_Breaker_Sta.Name & "-Horiz"
	Horiz_iMate = Constraints.AddByiMates(Horiz_iMateName, Standard_Breaker_Sta.Name, "iMates","232", "TopLeftUpDown")                   		
   Horiz_iMate.IsActive = False
End Try

Select TopConfig

	Case "Sideways"
		Try
			Constraint.IsActive(Vert_iMateName) = False
			Constraint.IsActive(Horiz_iMateName) = True
		Catch
		End Try
	
	Case "Up/Down"
		Try
			Constraint.IsActive(Horiz_iMateName) = False
			Constraint.IsActive(Vert_iMateName) = True
		Catch
		End Try
		
End Select

 

 

And if you want to eliminate constraint naming and use imate system names then here is a method using some of the API.

 

Dim Vert_iMateName As String 
Dim Horiz_iMateName As String 
Dim Comp1Name = "Standard Breaker Stab"

Try
	Dim Standard_Breaker_Sta = Component.InventorComponent(Comp1Name)

	Vert_iMateName = Standard_Breaker_Sta.Constraints.Item(1).iMateResult.ParentComposite.Name
	Horiz_iMateName = Standard_Breaker_Sta.Constraints.Item(2).iMateResult.ParentComposite.Name
Catch
	Dim Standard_Breaker_Sta  = Components.Add(Comp1Name,"Standard Breaker Stab.ipt")
                                   
	Vert_iMate = Constraints.AddByiMates("", Standard_Breaker_Sta.Name, "iMates","232", "TopLeftSideways")
	Vert_iMate.IsActive = False
	Vert_iMateName = Vert_iMate.iMateResult.Name
	
	Horiz_iMate = Constraints.AddByiMates("", Standard_Breaker_Sta.Name, "iMates","232", "TopLeftUpDown")                   	
	Horiz_iMate.IsActive = False
	Horiz_iMateName = Horiz_iMate.iMateResult.Name
End Try

Select TopConfig

	Case "Sideways"
		Try
			Constraint.IsActive(Vert_iMateName) = False
			Constraint.IsActive(Horiz_iMateName) = True
		Catch
		End Try

	Case "Up/Down"
		Try
			Constraint.IsActive(Horiz_iMateName) = False
			Constraint.IsActive(Vert_iMateName) = True
		Catch
		End Try
		
End Select

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 4 of 15

gwallaceCJ39B
Explorer
Explorer
So in this scenario, you've basically got both breaker configurations constrained in place, you're just using an if statement to turn off whichever ones are not selected?
0 Likes
Message 5 of 15

gwallaceCJ39B
Explorer
Explorer
Thanks for the reply and examples! I'll spend some time going through each to try and learn them this morning. Once I get it working where I can change the orientation of the top left stab, is there anything special I would need to do in order to have my form selection apply to all three on the top row? I'm guessing I just add and name the composite iMates for the other two stab locations and then add them into the rule? (sorry for the really dumb naming conventions in the file, as soon as I uploaded it they were changed to things that aren't nonsense)

Also, would you mind explaining the purpose of line 1 to 20? It doesn't have to be in-depth of every line, just a line or two should be enough to figure it out. I'm not entirely sure what a dim and try/catch statement does, as far as I can tell those lines are setting up the components and iMates prior to the Select/Case section.

Again, thank you so much! I wanted a simple part to help re-learn some things, I didn't realize I've fallen so far behind. I feel like an old man lol
0 Likes
Message 6 of 15

A.Acheson
Mentor
Mentor

I have updated the second rule posted above with comments. As for Dim this is auto added when you use the capture tool to add the components and constraints etc. Dim is used to declare a variable within the code. So declaring a variable name ( easy to understand) as string in order to hold a value. 

Dim TempName as String = "Value" 

 

Try ' Attempt to do something

Catch' If attempt fails do something else

End Try 'End Attempt

 

If you add in more matching imates in your base part you should be able  to use a for loop to add more than 1 component and contrain them using matching imates. This isn't really necessary if you only building a manual model and want to constrain manually but it can speed up things for multiple placements. Just ensure each component/imate is named uniquely. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 7 of 15

gwallaceCJ39B
Explorer
Explorer
Thank you so much! I really appreciate it
0 Likes
Message 8 of 15

gwallaceCJ39B
Explorer
Explorer

Do you know what I'm doing wrong here?  I'm trying the simple rule you wrote, it worked perfectly when I had only one stab in the assembly, but now that I'm trying to add the entire top row I can't create another composite iMate.  After creating composite:3, the iMate glyph disappears and I can not alt drag it to create composite:4 after suppressing composite:3.  It worked fine on the first stab and nothing I have tried so far has allowed me to create another composite using the same iMate in the breaker stab part.

 

Edit:  Well, I noticed I had horizontal and vertical backwards from what was selected and which mates were active, so I swapped the true/false for composite1 and 2 in the rule, now it outright doesn't work and I have no idea why.  I had no idea this would be such a frustrating task, I'm beginning to regret even trying

 

0 Likes
Message 9 of 15

A.Acheson
Mentor
Mentor

Unfortunately I'm not able to open your files due to work version but can you show the code and images of the issue? If its the rule for just suppression I would suggest carry out manual adding and suppression of imates then do the same in the code following the order of suppression. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 10 of 15

gwallaceCJ39B
Explorer
Explorer
Ok I got it working, i wasn't considering the order of operations when the rule is run! I had a mate unsuppressing before the compliment was suppressed, so it wasn't working right.

As for the composite iMate issue, I just made a duplicate iMate set on the breaker stab so that when the first is consumed in making the vertical constraint set, I still have another available for the horizontal set.

Thank you so much again! I'm still going to try and get the longer options working
0 Likes
Message 11 of 15

A.Acheson
Mentor
Mentor

Here is another method to approach this. It is using standard workplanes, workaxis along with named faces to constrain the parts instead of imates. I think it is a little easier. You can manually add the parts if you want and place a parameter in the angle constraint edit dialog. The code is doing all this so convienant for multiple assemblies following a pattern.  

AAcheson_0-1674625029322.png

 

 

Dim AssyDoc As AssemblyDocument = ThisDoc.Document
Dim UserParams As UserParameters = AssyDoc.ComponentDefinition.Parameters.UserParameters
Dim Userparam As UserParameter
Try
	Userparam = UserParams("StabAngle")
Catch
	 Userparam = UserParams.AddByvalue("StabAngle", 0 ,UnitsTypeEnum.kDegreeAngleUnits)'

End Try


Select TopConfig

	Case "Horizontal"
		 StabAngle = "0"

	Case "Vertical"
		
		StabAngle = "90"
		
End Select




For i = 1 To 3
	
	Dim FaceName As String = "Stab" & i
	Dim AxisName As String = "Cente Stab" & i				
	Dim Comp1Name As String = "Standard Breaker Stab:" & i

	Try
		 Dim Standard_Breaker_Sta = Component.InventorComponent(Comp1Name)
	Catch
	
		 Dim Standard_Breaker_Sta  = Components.Add(Comp1Name,"Standard Breaker Stab.ipt")
	                            
		Constraints.AddMate("", Standard_Breaker_Sta.Name, "Z Axis",
		                    {"232", "231", "230", "_20-32E3_FIX_P_ASM_1_ASM_1_ASM"},
		                    AxisName,
		                    solutionType := MateConstraintSolutionTypeEnum.kAlignedSolutionType)
		 Dim AngConstraint = Constraints.AddAngle("",{"232", "231", "230", "_20-32E3_FIX_P_ASM_1_ASM_1_ASM"},
												  "XZ Plane", Standard_Breaker_Sta.Name,
													"YZ Plane", 0.00 deg)
		'Set the Expression if needed.
		AngConstraint.Constraint.Angle.Expression = Parameter.Param("StabAngle").Name

		Constraints.AddMate("", Standard_Breaker_Sta.Name, "XY Plane",
		                    {"232", "231", "230", "_20-32E3_FIX_P_ASM_1_ASM_1_ASM"},
		                    FaceName)
	End Try

Next

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 12 of 15

gwallaceCJ39B
Explorer
Explorer
Thanks! I do like this a little better than the iMates
0 Likes
Message 13 of 15

A.Acheson
Mentor
Mentor

And if you were to take away all ilogic code and techniquies used for automatically adding and assembling such as axis in the part, named faces etc. Because it may not be necessary to add and constraint parts by code.  The code for switching part direction is this

Select TopConfig

	Case "Horizontal"
		 StabAngle = "0"

	Case "Vertical"
		
		StabAngle = "90"
		
End Select

With manual constraints you could go straight to constrain stab origin to center of assembly.  If the center hole was not there this method might have failed of course. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 14 of 15

don.boresky
Participant
Participant

Not an answer to your specific question, but you might find helpful info in this Autodesk University session,

 

- iLogic - Your Foundation for CPQ

 

There are lots of good resources for iLogic, but I find they tend to be focused on part design and individual productivity enhancements for Inventor.   In contrast, this session explores the higher-level capabilities of iLogic to control product / assembly design.  There is also a short piece at the end on an option to cost effectively deploy the models Online, without the deep technical knowledge typically needed. 

 

- https://www.autodesk.com/autodesk-university/class/iLogic-Your-Foundation-CPQ-2022

Message 15 of 15

gwallaceCJ39B
Explorer
Explorer
Thank you so much! I'll definitely bookmark that one for when there's a lull at work. I struggle with where to start when it comes to courses or learning, I really only was taught basic stuff and the rest has just been figured out as I went along. I'm sure there are a LOT of things that I'm doing inefficiently or outright incorrectly