Index a Parameter Name during Assignment - Ilogic

Index a Parameter Name during Assignment - Ilogic

Nickefth61
Contributor Contributor
1,140 Views
4 Replies
Message 1 of 5

Index a Parameter Name during Assignment - Ilogic

Nickefth61
Contributor
Contributor

Hello Inventor Forum,

 

This is a question about Inventor Ilogic. I have an assembly with 5 parts that are all the same except for a difference in height. The part names are "Part: 1", "Part: 2", Part: 3" etc.  The height parameters are "PartHeight1", "PartHeight2", "PartHeight3" etc. I also have a parameter "NumberOfParts" which dictates how many of the parts are present in the assembly.

 

I want to write a for loop such that:

for i in range(0, NumberOfParts):

    PartHeight[i] = InputBox("What is the Height of Part" + str(i), "Part Height")

end for loop

 

I could also do the same thing with a while loop:

i = 0

while i<NumberOfParts

    i=i+1

    PartHeight[i] = InputBox("What is the Height of Part" + str(i), "Part Height")

end While

 

My question is: How do I index the parameter name "PartHeight1", "PartHeight2", "PartHeight3" etc. during the loop? It throws a syntax error if I do something like ("PartHeight"+str(i)) = InputBox(....). Is there a way to index through the names?

 

I would rather not hard code in the numbers, because the number of parts in the assembly can increase beyond the point of convenient hard coding.

 

Thank you!

Nicholas

0 Likes
Accepted solutions (1)
1,141 Views
4 Replies
Replies (4)
Message 2 of 5

Mark.Lancaster
Consultant
Consultant

You may get a better results by posting this question in the Inventor Customization forum: http://forums.autodesk.com/t5/inventor-customization/bd-p/120  Also always indicate which version of Inventor you are using.

Mark Lancaster


  &  Autodesk Services MarketPlace Provider


Autodesk Inventor Certified Professional & not an Autodesk Employee


Likes is much appreciated if the information I have shared is helpful to you and/or others


Did this resolve your issue? Please accept it "As a Solution" so others may benefit from it.

0 Likes
Message 3 of 5

Nickefth61
Contributor
Contributor

Mark,

 

I will move the posting. Would you say that the customization page is the best place of all iLogic questions?

 

I'm also adding a tag with my Inventor Version.

 

Thanks,

 

Nicholas

0 Likes
Message 4 of 5

Mark.Lancaster
Consultant
Consultant

iLogic posting can happen here and they do.  Should yours be posted here?  It can, but you may not get any response because you are writing VB/.NET stuff into your iLogic code.

 

Many users here may use iLogic but they are only using the iLogic functions and may not have any true programming experience.   Where-as the customization forum is probably monitored by those who do have an extensive programming background or experience.

 

In addition (and this is my opinion)...  I don't considered your code as being iLogic, its VB or .NET.   When I think of someone saying I have a iLogic code, I see their entire code written using only the iLogic functions.  But that's my 2 cents...

Mark Lancaster


  &  Autodesk Services MarketPlace Provider


Autodesk Inventor Certified Professional & not an Autodesk Employee


Likes is much appreciated if the information I have shared is helpful to you and/or others


Did this resolve your issue? Please accept it "As a Solution" so others may benefit from it.

0 Likes
Message 5 of 5

Nickefth61
Contributor
Contributor
Accepted solution

Mark,

 

Thanks for sharing your opinion. I suppose you would be correct in saying that is not true Ilogic snippet code. I tried moving this post and couldn't find the option to do so. Truth be told, I had trouble navigating back to the post after posting it...couldn't find it! Then I remembered the option to see all activity in my account page, and here I am.

 

I ended up finding the solution to my problem anyway. I'll post it here in case anyone else happens to come upon this post...

 

To index a parameter, I cannot use the str() code because when it converts my integer to a string, it adds a space. Ilogic has a snippet, Cstr() which converts to a string without the space. With a parameter it would be:

 

i = 0

while i<NumberOfParts

    i=i+1

    Parameter("PartHeight"+Cstr(i)) = InputBox("What is the Height of Part" + Cstr(i), "Part Height")

end While

 

The "Parameter" data type can be used not only when assigning parameter names, but when calling them. So if you need to ever index or alter a parameter name, call it, or do anything of that nature, Parameter() can help. I hadn't realized in my lack of experience that Parameter() is actually an Ilogic datatype.

 

Anyway, thank you Mark for your reply. I hope this helps anyone else having a similar issue.

 

Nicholas