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: 

Change iPart member with iLogic

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
karthur1
5638 Views, 12 Replies

Change iPart member with iLogic

I have a subassembly that is made up of several parts (4 or 5 actually).  All the parts are from the same parent, just a different length.  I have my iPart table setup where I can just choose the length that I want (within .25in increments).  The sub assembly is put together and then I will cut the end at an angle with an extrude cut at the assembly level. It will look like this when it is finished.  I do this so that I can get an accutate parts list of the lengths that I need.

 

footboards.jpg

 

If I want to make a new sub assembly, I just copy this one, and then change the length of each member to what I need.  It is easy to do... just really time consuming.  I would like to be able to enter an amount and then iLogic would step thru the assembly, open each ipart memeber and then change the length to the appropriate ipart member based on the new length.

 

I this something that could be done with iLogic?

 

Thanks,

Kirk

12 REPLIES 12
Message 2 of 13

Hi karthur1,

 

Here's a real quick example that might or might not be what you're after.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

'ipart member names and values
'Part1-01 = 12"
'Part1-02 = 15"
'Part1-03 = 18"

oLength = InputBox("Enter a length.", "iLogic", "12")

'assembly browser names are:
'Part1
'Part2
'Part3

If oLength <= 12 Then
'change ipart to row 1
iPart.ChangeRow("Part1", "Part1-01")
iPart.ChangeRow("Part2", "Part1-01")
iPart.ChangeRow("Part3", "Part1-01")
ElseIf oLength >= 18 Then 
'change ipart to row 3
iPart.ChangeRow("Part1", "Part1-03")
iPart.ChangeRow("Part2", "Part1-03")
iPart.ChangeRow("Part3", "Part1-03")
Else 'between 12 and 18
'change ipart to row 2
iPart.ChangeRow("Part1", "Part1-02")
iPart.ChangeRow("Part2", "Part1-02")
iPart.ChangeRow("Part3", "Part1-02")
End If


Message 3 of 13

I don't really know what row the new length will be in the ipart... I just know how much I want to change the length by.  The length is a "key" in the ipart

 

How will the macro search the table and find the correct row or is that even necessary since the length is a key for the ipart?

 

Kirk

Message 4 of 13

Hi karthur1,

 

I might still be missing the mark, but this example finds the value for the length (d2) in the ipart table that matches the input.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

'ipart row / member names and values
'Part1-01 = 12"
'Part1-02 = 15"
'Part1-03 = 18"

'assembly browser names are:
'Part1
'Part2
'Part3

'd2 is the length column in the iPart factory

oLength = InputBox("Enter a length.", "iLogic", "12")

'syntax example
'oRow = iPart.FindRow("iComponentName:1", "columnName", "<=", 0.2, "columnName", "<=", 4.1)

oRow = iPart.FindRow("Part1", "d2", "=", oLength)
iPart.FindRow("Part2", "d2", "=", oLength)
iPart.FindRow("Part3", "d2", "=", oLength)

If oRow < 0 Then
MessageBox.Show("No matching row found in iPart.", "iLogic")
Else
MessageBox.Show("iPart set to row: " & oRow , "iLogic")
End If
Message 5 of 13

That gives me some ideas on how I might can make it work.

 

It will have to do this:

ask for change amount

go to each part in the assembly and get the name of it

find the row for the current length

find the row with the "current length + change mount"

Set the member to this new row

 

Go to next part in assembly and do the above steps

Stop when the members have been changed.

 

Can you tell me  the signifigance of the "o" prefix on the variable name, i.e. oLength, oRow?  I really need to learn how to program more in iLogic.

 

Thanks,

Kirk

 

 

Message 6 of 13

Hi karthur1,

 


karthur1 wrote:

 

 

Can you tell me  the signifigance of the "o" prefix on the variable name, i.e. oLength, oRow?  

  


There really isn't any. Generally speaking variables are often named such as shown below, with the first letters indicating the varible type.

 

srtTest ( a String )

intTest ( an Integer )

lngTest ( a Long )

objTest ( an Object )

 

see this link for more: https://msdn.microsoft.com/en-us/library/aa240858(v=vs.60).aspx

 

But I picked up the habit of just naming everything with an o, from this forum. I ran across a thread on here where one of the Autodesk employees confessed to starting the oName trend years and years ago, but I forget who it was.

 

The main thing the prefix does, is it helps you know that it's a constant or variable when you're reading through the code.

 

I'm sure using oName for everything annoys some people, but it's never caused me any grief.

 

 

 

Note too there are some other iPart related snippets that you might look into.

 

You access the available snippets from the Snippets area of the Edit Rule dialog box:

 

Autodesk Inventor ilogic iPart Snippets.PNG

 

If you click those snippets it'll add them to your rule, and then you can search this forum for related examples too.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

Message 7 of 13

Curtis,

I was able to play around with the code and figure it out.  I can get it to change the member like I want if I pick it.  I would like for it to automatically cycle thru the assembly and change each ipart member by the amount that I entered.

 

2016-03-17_2234.png

 

My iPart table uses the "Size" and "Length" keys to select the member.

 

I am sure I need a for/Next loop, but not quite sure how to make it work.

 

Kirk

 

Dim comp = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter,"Select Component to change:")
'MsgBox(comp.Name)
'DefaultRowNumber = iPart.RowNumber(comp.Name)
'rowstringvalue=iPart.CurrentRowStringValue("Member")
'rowstringvalue=iPart.CurrentRowStringValue("Length")
oLength = InputBox("Enter the length change.", "iLogic", "0")
rowName = iPart.RowName(comp.Name)
RowValue=iPart.CurrentRowValue("Length")
SizeStringValue=iPart.CurrentRowStringValue("Size")
NewLength=RowValue+oLength
MsgBox("Size==>  " & SizeStringValue & "   RowName==> " & rowName & "   New Length ==>  "& NewLength)

'syntax example
'oRow = iPart.FindRow("iComponentName:1", "columnName", "<=", 0.2, "columnName", "<=", 4.1)
i = iPart.FindRow(comp.Name, "Size", "<=",SizeStringValue , "Length", "<=", NewLength)

 

Message 8 of 13

Hi karthur1,

 

I was hoping to get back to this today, but I've run out of time.

 

I think you're right, you'll want to loop through the assembly and look for iparts, see this example for some code to determine if a part is an iPart:

https://forums.autodesk.com/t5/inventor-customization/ilogic-test-for-ipart/m-p/3761988#M42030

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

Message 9 of 13

I got my "Test" assembly to work, but when I moved over to my actual model, it did not.  I think probably the reason its not working is because the iparts in my "test" ipart only has one key.... the iparts in my working model actually has two keys for the iparts.

 

In my working model, the ipart has the keys "Member" and "Cutlength".  My iLogic command looks something like this:

 

MemberStringValue=iPart.CurrentRowStringValue("Member")
NewLength=RowValue+oLength
i = iPart.FindRow(comp.Name, "Member", "=",MemberStringValue , "Cutlength", "=", NewLength)

MsgBox (i)

 

When I run this code, the member does not change.  Can you explain what the command is actually looking for in order for the conditions to be satisfied?  The last line will print "i" in the FindRow command.  It reports "-1".  From what I have read that means the condition was not met.

 

Thanks,

Kirk

 

 

Message 10 of 13
karthur1
in reply to: karthur1

I am a little closer.  I can now select a ipart and enter a "New" length and it will change to the new length.  This is much better than having to select it from the ipart tables.  However, I would like to enter a length and the iLogic code would then change ALL the members in the subassembly.

 

I know all the members in the sub are iparts, so no real need to check for that.

 

Here is what I have got so far:

 

Dim comp = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter,"Select Component to change:")
'MsgBox(comp.Name)
oLength = InputBox("Enter the length change (+ or -).", "iLogic", "0")
rowName = iPart.RowName(comp.Name)
RowValue=iPart.CurrentRowValue("Cutlength")
StockNoStringValue=iPart.CurrentRowStringValue("Stock Number")
NewLength=RowValue+oLength
MemberStringValue=StockNoStringValue & "-" & NewLength
'MsgBox("Size==> " & MemberStringValue & " RowName==> " & rowName & " New Length ==> "& NewLength)
'syntax example
i = iPart.FindRow(comp.Name, "Member", "=<", MemberStringValue) 'This will change the row To the new length

If i < 0 Then
MessageBox.Show("No matching row found in iPart.", "iLogic")
'Else
'MessageBox.Show("iPart set to row: " & oRow , "iLogic")
End If

 

How do I make it cycle thru to each ipart and change it based on the "New" length?

 

Thanks

Message 11 of 13
wayne.brill
in reply to: karthur1

Hi,

 

Here is an example I used to test. It uses a for loop to change the row of each of the iParts in the assembly. My iParts where very simple but it does change all of them.  This example is getting a value of a Length parameter and using that to change the row of the iPart. (in my iPart the values could be 1.0 in, 2.0 in, or 3.0 in)

 

You may have to add some test in your code to run different code based on which occurrence the code is going to change.

 

oLength = InputBox("Enter the Length parameter", "iLogic", "3.0 in")

Dim oAsmDoc as Inventor.AssemblyDocument
oAsmDoc = ThisDoc.Document

Dim comp As Inventor.ComponentOccurrence
For Each comp In oAsmDoc.ComponentDefinition.Occurrences

    i = iPart.FindRow(comp.Name, "Length", "=", oLength)
    
    If i < 0 Then
        MessageBox.Show("Some problem occurred", "iLogic")
    Else
        MessageBox.Show("iPart set to row: " & oLength , "iLogic")
    End If
Next

Thanks,

Wayne



Wayne Brill
Developer Technical Services
Autodesk Developer Network

Message 12 of 13
karthur1
in reply to: wayne.brill

Wayne,

I was able to change the variables to work with my iparts and that works great!  So much easier than selecting one-at-time.

 

Thanks,

Kirk

 

 

 

Message 13 of 13
forbillian
in reply to: wayne.brill

Wayne.

 

Exactly what I needed to help me find certain iPart members in an assembly by row name to change the BOM status to reference.

 

I have a sub assembly which features many possible ipart Bolts & locations - some of which turn on & off depending on rules but I need to ensure the Bolts that are set to reference only have a reference BOM status

 

Thankyou so much Wayne:

 

SyntaxEditor Code Snippet

Dim oAsmDoc as Inventor.AssemblyDocument
oAsmDoc = ThisDoc.Document

Dim comp As Inventor.ComponentOccurrence 
For Each comp In oAsmDoc.ComponentDefinition.Occurrences

If iPart.RowName(comp.Name) = "BOLT_NUT_ASM_REFERENCE" Then
        comp.Definition.BOMStructure = 51972 'Reference 
    Else 
        comp.Definition.BOMStructure = 51973 'Purchased
    End If
    
Next
 

 

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

Post to forums  

Autodesk Design & Make Report