ilogic to place specified number of part instances within assembly

ilogic to place specified number of part instances within assembly

bengee5454
Collaborator Collaborator
750 Views
15 Replies
Message 1 of 16

ilogic to place specified number of part instances within assembly

bengee5454
Collaborator
Collaborator

Hi, I need help. I have to design a frame where the posts are to be spaced either at 620mm or 800mm (or a mix of both). The overall length, L can vary. The End Posts are fixed at 20mm from each end.

 

I have created a form that allows  the user to specify the total number of 620mm and 800mm spacings, nspacings. This in turn, controls my overall length, L.

 

What I would like is to control the number of instances of 'post' to nspacings-1. So I dont have to manually suppress the extra items.

 

How would i achieve this?

0 Likes
751 Views
15 Replies
Replies (15)
Message 2 of 16

bengee5454
Collaborator
Collaborator

sorry, it would help if i remember to attach the screenshot!

bengee5454_0-1670513075994.png

 

0 Likes
Message 3 of 16

A.Acheson
Mentor
Mentor

Have you tried a linear pattern? No need to suppress occurrences then. Then just drive the spacing and qty via parameters. 

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

bengee5454
Collaborator
Collaborator

I did think about that, but dismissed it (probably foolishly) as I may have irregular pattern spacings, i.e 800,800,800,620,620,620,620,620. I couldn't see how this could be done. 

 

Can it be done?

0 Likes
Message 5 of 16

bengee5454
Collaborator
Collaborator

I've been looking at patterns and can now see how I could get my irregular spacings from a sketch driven pattern......but how can I choose the number of occurrences, without editing the sketch driven pattern? Is this possible. 

 

I guess what i really want is to open the assy, go to an ilogic form, enter how many bays there are, the individual size (spacing) of each bay, then bish bash bosh I have my assembly!

 

Surely this is possible 😁

0 Likes
Message 6 of 16

A.Acheson
Mentor
Mentor

You may need multiple patterns if they are irregular spacing. Just drive it with a parameter. Set it up manually then just drive the parameter/ delete/add patterns as needed. 

 

The alternative which has way more setup is to place one occurrence and then drive the position. You then need a for loop from 1 to count to place and position each one accordingly based on a spacing array list of integer/ double. If you capture snippet the occurrence added with constraints then you can adjust the constraints. When placing first constraints try to use origin planes this will avoid unecessary proxy faces. 

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

A.Acheson
Mentor
Mentor

Here is a quick sample that will allow spacing to be used on constraints offsets. Just change the list values.

Dim offset As Integer = 0

Dim SpacingList As Integer() = {600, 600, 600, 800, 800, 800, 800 }

For i = LBound(SpacingList) To UBound(SpacingList)

	offset = offset + SpacingList(i)

	Dim Part1 = Components.Add("", "Part1.ipt")
	Dim OccName As String = Part1.Name
	
	Constraints.AddFlush("", "", "XZ Plane", OccName,
	                    "XZ Plane")
	Constraints.AddFlush("", OccName, "YZ Plane", "",
	                     "YZ Plane",offset)
	Constraints.AddFlush("", "", "XY Plane", OccName,
	                     "XY Plane")
Next

 

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

bengee5454
Collaborator
Collaborator

Thank you. 

I've copied the code into a rule and it works! Just got to work out how to change the plane the pattern is on.

 

0 Likes
Message 9 of 16

bengee5454
Collaborator
Collaborator

Perhaps I was a little hasty.........it kind of works, but I'm getting many extra parts that I dont want! Obviously something I've done. Below is an example, there's meant to be about 8 divisions - clearly a lot more.

bengee5454_0-1670922634414.png

The code I'm using (i'd like to stress that I am a novice at coding!):

Dim offset As Integer = 0

Dim SpacingList As Integer() = {b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14}

For i = LBound(SpacingList) To UBound(SpacingList)

	offset = offset + SpacingList(i)

	Dim Part1 = Components.Add("", "P0211-802-001.iam")
	Dim OccName As String = Part1.Name
	
	Constraints.AddFlush("", "", "YZ Plane", OccName,
	                  "XY Plane")
	Constraints.AddFlush("", OccName, "YZ Plane", "",
	                    "XZ Plane",offset)
	Constraints.AddFlush("", "", "XY Plane", OccName,
	                  "XZ Plane")
Next
			
If b8 = 0 Then
	Component.Visible("P0211-802-001:16") = False
	
End If

If b9 = 0 Then
	Component.Visible("P0211-802-001:17") = False
	
End If

If b10 = 0 Then
	Component.Visible("P0211-802-001:18") = False
	
End If

If b11 = 0 Then
	Component.Visible("P0211-802-001:19") = False
	
End If
If b12 = 0 Then
	Component.Visible("P0211-802-001:20") = False
	
End If

If b13 = 0 Then
	Component.Visible("P0211-802-001:21") = False
	
End If

If b14 = 0 Then
	Component.Visible("P0211-802-001:22") = False
	
End If

Where am i going wrong?

 

 

Also, when i enter the parameters in my form, while the form is active i get a randoms part - in the wrong orientation.  No idea why

bengee5454_1-1670923058783.png

 

0 Likes
Message 10 of 16

A.Acheson
Mentor
Mentor

In my testing it is adding 14 occurrences which is the exact number of spacing in the single array list. Did you happen to run it twice at any point?  I have added a message box in the below so you can see where the count is coming from. Also if you want to you can use a case statement instead of all the if statements. 

Dim offset As Integer = 0

Dim SpacingList As Integer() = {b8, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14 }

MessageBox.Show(LBound(SpacingList), "LBound(SpacingList)-Qty")
MessageBox.Show(UBound(SpacingList), "UBound(SpacingList)-Qty")

For i = LBound(SpacingList) To UBound(SpacingList)' 

	offset = offset + SpacingList(i)

	Dim Part1 = Components.Add("", "P0211-802-001.iam")
	Dim OccName As String = Part1.Name
	
	Constraints.AddFlush("", "", "YZ Plane", OccName,
	                  "XY Plane")
	Constraints.AddFlush("", OccName, "YZ Plane", "",
	                    "XZ Plane",offset)
	Constraints.AddFlush("", "", "XY Plane", OccName,
	                  "XZ Plane")
Next
	
Select Case b8 Or b9 Or b10 Or b11 Or b12 Or b13 Or b14
Case 0
		'MessageBox.Show("In Case","iLogic")
		Component.Visible("P0211-802-001:16") = False
		Component.Visible("P0211-802-001:17") = False
		Component.Visible("P0211-802-001:18") = False
		Component.Visible("P0211-802-001:19") = False
		Component.Visible("P0211-802-001:20") = False
		Component.Visible("P0211-802-001:21") = False
		Component.Visible("P0211-802-001:22") = False
End Select

 

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

bengee5454
Collaborator
Collaborator

hi,

Yes I did run it twice (well, a few times actually). Is there a way to clear the previous inputs?

What I would like is (to get it clear in my head!):

 

  • The user to open the read only file - which then can be saved to a project
  • user to open ilogic form
  • user to specify total number of bays
  • user to specify width of each bay
  • base length to be calculated (sum of all bay widths+20+20) - 20 being the offset at each end
  • base to be populated with correct number of partitions to achieve the correct number of bays

 

 

There bays are to house pipes (of varying ODs) stacked upon one another (see below). So the end result ideally would be a form where the stacks could be controlled.....but fist things first...

bengee5454_1-1671024289164.png

 

 

Did you happen to run it twice at any point?  I have added a message box in the below so you can see where the count is coming from. Also if you want to you can use a case statement instead of all the if statements. 

0 Likes
Message 12 of 16

A.Acheson
Mentor
Mentor

If you want to clear all occurrences in the assembly you could use the below code. Create a Boolean parameter and call it ClearAssy. Note this will clear all occurrences so if you want to clear only the the pattern ones then it can be done a different way. 

 

If ClearAssy = True
   For each occ As componentOccurrence in ThisDoc.Document.ComponentDefinition.Occurrences
   occ.Delete
   Next
End If 

 

 

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

bengee5454
Collaborator
Collaborator

Thank you for all your help. I have run your ClearAssy code and am faced with an error:

 

bengee5454_0-1671033745094.png

I think its this bit it doesnt like:

   For Each  As ComponentOccurrence In ThisDoc.Document.ComponentDefnition.Occurrences
0 Likes
Message 14 of 16

A.Acheson
Mentor
Mentor

There was a spelling error in "ComponentDefinition". Corrected now in the original. 

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

bengee5454
Collaborator
Collaborator

The ClearAssy did the trick in clearing the assembly (obviously)! you mentioned earlier about just clearing the patterned components. At first i thought clearing everything was the way to go, but now i'm thinking i was wrong.

 

Is it an easy task just to delete the pattern?

 

 

0 Likes
Message 16 of 16

A.Acheson
Mentor
Mentor

So for this you need to record the occurrences your adding in a list then work through the list afterwards to delete. These three sections needs to be placed in your  code. Instructions above each section. 

' Place before you add the occurrence
Dim OccList as New List (Of ComponentOccurrence)

'Place after you add
OccList.add(Part1)

'Replace the loop through all 'occurrences with the list loop
For Each occ in OccList
Occ.Delete
Next 

 

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