Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ilogic rectangular pattern

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
Arrush80_
1069 Views, 2 Replies

ilogic rectangular pattern

Hi,

 

I am looking to create a pattern for 2, 3 and sometimes 4 individual parts. Let's call them part A B C and D. The pattern will have equal spacing between each part and will always follow the same order, ABCDABCDABCD the problem is, I may not always have an even number of instances. I can for example need 10 instances of the parts total so the pattern will be missing two parts from a standard pattern ABCDABCDAB. I am trying to figure out how to write this so I can select a number of instances even or odd and have ilogic figure out what the pattern number for each needs to be.

 

I could use if statments, but I need the pattern adjustable from 2 to 50 instances, with the ability to select how many individual parts are present, wheter it is AB only, ABC, or ABCD.

 

Example patterns with 2 parts and 7-10 total instances

ABABABA (7)

ABABABAB (8)

ABABABABA (9)

ABABABABABA (10)

 

Example patterns with 3 parts and 8-11 total instances

ABCABCAB (8)

ABCABCABC (9)

ABCABCABCA (10)

ABCABCABCAB (11)

 

Example patterns with 4 parts and 8-13 total instances

ABCDABCD (8)

ABCDABCDA (9)

ABCDABCDAB (10)

ABCDABCDABC (11)

ABCDABCDABCD (12)

ABCDABCDABCDA (13)

 

Any help would be appriciated.

Below if just a pattern with two individual parts alternating, but like I said I would like to specify the total number of parts and have ilogic determine which pattern will need to have instances added or removed.

2 REPLIES 2
Message 2 of 3
MegaJerk
in reply to: Arrush80_

Assuming that you have some means of selecting the option of whether parts A,AB,ABC,or ABCD are being included, the following code should work. 

You'll notice that at the top of this code there are some commented out Parameters. Those are the parameters that I created in order to do this test, and if you create them yourself, then everything should work without breaking. Naturally when you create PartA~DQty, they will simply be blank 0 ul as the values will populate via iLogic. 

'PartAQty = 2 ul
'PartBQty = 2 ul
'PartCQty = 2 ul
'PartDQty = 2 ul
'MultiValue.SetList("PartSelection", "A", "AB", "ABC", "ABCD")
'TotalParts = 8 ul


Select Case PartSelection
	Case = "A"
		PartAQty = TotalParts
		PartBQty = 0
		PartCQty = 0
		PartDQty = 0
	Case = "AB"
		PartAQty = Ceil(TotalParts / 2) 'Floor(TotalParts / 2) + (TotalParts Mod 2)
		PartBQty = Floor(TotalParts / 2) 
		PartCQty = 0
		PartDQty = 0
	Case = "ABC"
		PartAQty = Ceil(TotalParts / 3)
		PartBQty = Floor(TotalParts / 3) + Floor((TotalParts Mod 3) / 2)
		PartCQty = Floor(TotalParts / 3)
		PartDQty = 0
	Case = "ABCD"
		PartAQty = Ceil(TotalParts / 4)
		PartBQty = Floor(TotalParts / 4) + Floor((TotalParts Mod 4) / 2)
		PartCQty = Floor(TotalParts / 4) + Floor((TotalParts Mod 4) / 3) 
		PartDQty = Floor(TotalParts / 4)
	Case Else 
		PartAQty = 0
		PartBQty = 0
		PartCQty = 0
		PartDQty = 0
End Select 

 
I'm sure that there may be an even math based way of approaching this, but it's past midnight and I don't feel like getting too fancy at the moment. 

At least with this method you will be able to turn on any instance of a pattern array based on the qty value. With no extra conditional statements you could simply say : 

 

Component.IsActive("PatternPartAHere:1") = PartAQty
Component.IsActive("PatternPartCHere:1") = PartCQty
Component.IsActive("PatternPartBHere:1") = PartBQty
Component.IsActive("PatternPartDHere:1") = PartDQty

 
If it's zero, then it'll turn off, and if it's not then it'll turn on! 

I hope that this helps you out. Please respond if you're having an issue. 



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
Message 3 of 3
Arrush80_
in reply to: MegaJerk

Thank you, that worked out great!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report