Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Is there a faster way?

karthur1
Mentor

Is there a faster way?

karthur1
Mentor
Mentor

I have a ilogic code that changes all my memebers lengths by a specific amount. The code is here in this thread.  The line that changes the member is 

 

i = iPart.FindRow(comp.Name, "Length", "=", oLength)

 

The problem that I have is that this iPart has a couple thousand rows (not exactly sure how many... I just know it a lot).  When the code runs, it will take over 6 minutes to change out two parts.  The CPU is running at 25-26% during this time, so its working hard at it. If I manually change the components, it will take the ipart table about 45 seconds to come up so I can change the part.

 

I take it that the code is actually running thru the table until it finds a match. Since the table is rather large, it takes awhile to scan thru it.

 

Is there a faster way to set the member?

 

Thanks,

Kirk

 

 

0 Likes
Reply
Accepted solutions (1)
948 Views
14 Replies
Replies (14)

Jef_E
Collaborator
Collaborator

Could you post the code you are really using? Or is the accepted as solution the real code?

 



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes

karthur1
Mentor
Mentor

I don't have the exact code with me at the moment.  It is very similar to the accepted solution.  The code gathers some information about the current row before it gets to the for/next with the "i = iPart.FindRow(comp.Name, "Length", "=", oLength) " line.

 

I can post the entire code later this afternoon.

 

Kirk

0 Likes

Jef_E
Collaborator
Collaborator

@karthur1 wrote:

I don't have the exact code with me at the moment.  It is very similar to the accepted solution.  The code gathers some information about the current row before it gets to the for/next with the "i = iPart.FindRow(comp.Name, "Length", "=", oLength) " line.

 

I can post the entire code later this afternoon.

 

Kirk


That would be helpfull.



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes

karthur1
Mentor
Mentor

Below is the entire code.  I just looked at the ipart and it has 3,683 rows.

 

Thanks,

Kirk

 

oLength = InputBox("Enter the length change (+ or -)in inches.", "iLogic", "0.25")
Dim oAsmDoc as Inventor.AssemblyDocument
oAsmDoc = ThisDoc.Document
Dim comp As Inventor.ComponentOccurrence
For Each comp In oAsmDoc.ComponentDefinition.Occurrences
rowName = iPart.RowName(comp.Name)
RowValue=iPart.CurrentRowValue("Cutlength")
StockNoStringValue=iPart.CurrentRowStringValue("Stock Number")
NewLength=RowValue+oLength
MemberStringValue=StockNoStringValue & "-" & NewLength
i = iPart.FindRow(comp.Name, "Member", "=", MemberStringValue)
If i < 0 Then
MessageBox.Show("Some problem occurred", "iLogic")
Else
'MessageBox.Show("iPart set to row: " & MemberStringValue , "Change ALL members iLogic")
End If
Next

 

 

0 Likes

Jef_E
Collaborator
Collaborator

Maybe, you can save the row into a variable. And then refer to that variable instead of looking into the table's current row. Don't know if it would do much. But maybe a little.

 

Dim iPartRow As iPartTableRow

What I don't quite understand, is this line. Does it also activate the new found row?

 

i = iPart.FindRow(comp.Name, "Member", "=", MemberStringValue)

Maybe you can shorten you code a little. The rowName varaible is unused? you should delete or comment it out.

 

This is you loop;

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

	rowName = iPart.RowName(comp.Name)
	RowValue = iPart.CurrentRowValue("Cutlength")
	StockNoStringValue = iPart.CurrentRowStringValue("Stock Number")
	NewLength = RowValue + oLength
	MemberStringValue = StockNoStringValue & "-" & NewLength
	
	i = iPart.FindRow(comp.Name, "Member", "=", MemberStringValue)
	If i < 0 Then
		MessageBox.Show("Some problem occurred", "iLogic")
	Else
		'MessageBox.Show("iPart set to row: " & MemberStringValue , "Change ALL members iLogic")
	End If
Next

In short it could also be this, same effect ( haven't tested it ).

Also I have no idea if this has a real impact on the speed. But you could give it a shot. (let me know the result, i'm just learning to code efficiently myself).

 

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

	MemberStringValue = iPart.CurrentRowStringValue("Stock Number") & "-" & iPart.CurrentRowValue("Cutlength") + oLength
	
	i = iPart.FindRow(comp.Name, "Member", "=", MemberStringValue)
	If i < 0 Then
		MessageBox.Show("Some problem occurred", "iLogic")
	Else
		'MessageBox.Show("iPart set to row: " & MemberStringValue , "Change ALL members iLogic")
	End If
Next

I also have a question about the IF ELSE END IF statement on the end.

 

i = the row number and when there is a error, it goes to -1 or how does this check work? I don't have a clue :slightly_smiling_face:

 

	i = iPart.FindRow(comp.Name, "Member", "=", MemberStringValue)
	If i < 0 Then
		MessageBox.Show("Some problem occurred", "iLogic")
	Else
		'MessageBox.Show("iPart set to row: " & MemberStringValue , "Change ALL members iLogic")
	End If

Hope you find this post helpfull.



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes

karthur1
Mentor
Mentor

Jeff,

From the help in the iLogic, the FindRow command will find the row that mets the condition and change to that row if found.... if not, it sets i=-1. So the error check at the end is so that if i=-1, it will give a message that something went wrong.... otherwise it assumes it completed successfully and continues.

 

If I comment out the line "rowName = iPart.RowName(comp.Name)".... I then get the error of:

 

"iPart.CurrentRowValue("Cutlength"):  This function was called without a previous call to iPart.ChangeRow or iPart.FindRow.

 

Maybe there is a way to avoid this, but I am not sure.

 

 

Kirk

 

 

0 Likes

karthur1
Mentor
Mentor

I had an idea of rather than searching the table for the correct value, I would just tell it what value to set it to. It seems that the command 

"iPart.ChangeRow("iComponentName:1", "RowMemberName")  "  would do exactly what I need.  The code would work something like this.

 

Start with the first iPart.. Get its Component Name and length.  Add the increment to the length.... then change this with the "iPart.ChangeRow " command.  Go to the next part in the assembly and do the same thing.  Continue until all the parts are changed.

 

I can get this code to work for the first part, but then it errors out when it gets to the second part.  The "Lista" variable is the component browser name.

 

I am probably going about this all wrong. Any Suggestions?

 

Thanks,

Kirk

 

 

SyntaxEditor Code Snippet

oLength = InputBox("Enter the length change (+ or -)in inches.", "iLogic", "0.25")
Dim oAsmDoc as Inventor.AssemblyDocument
oAsmDoc = ThisDoc.Document
Dim comp As Inventor.ComponentOccurrence 
        Lista = ""
        For Each oOcc In ThisApplication.ActiveDocument.ComponentDefinition.Occurrences.AllLeafOccurrences
            Lista=oOcc.Name        
        MsgBox(Lista)
    
            For Each comp In oAsmDoc.ComponentDefinition.Occurrences
        
            rowName = iPart.RowName(comp.Name)
            RowValue=iPart.CurrentRowValue("Cutlength")
            StockNoStringValue=iPart.CurrentRowStringValue("Stock Number")
            NewLength=RowValue+oLength
            MemberStringValue=StockNoStringValue & "-" & NewLength
            MsgBox("New Size==> " & MemberStringValue & " Current RowName==> " & rowname & " New Length ==> "& NewLength)
            'MsgBox("Size==> " & MemberStringValue & " RowName==> " & iPart.RowName(comp.Name) & " New Length ==> "& NewLength)
            'MemberStringValue = iPart.CurrentRowStringValue("Stock Number") & "-" & iPart.CurrentRowValue("Cutlength") + oLength
            iPart.ChangeRow(Lista, MemberStringValue)
            
            'iPart.ChangeRow("iComponentName:1", "RowMemberName")
            
            'i = iPart.FindRow(comp.Name, "Member", "=", MemberStringValue) 
             Next
            
    If i < 0 Then
        MessageBox.Show("Some problem occurred", "iLogic")
    Else
        'MessageBox.Show("iPart set to row: " & MemberStringValue , "Change ALL members iLogic")
    End If
Next

 

 

0 Likes

wayne.brill
Collaborator
Collaborator

Hello Kirk,

 

I am not sure what is causing the error just looking at the code. Can you upload a small assembly that will allow me to recreate the error? If you want to keep it private you can send it to wayne.brill@autodesk.com

 

Thanks,

Wayne



Wayne Brill
Developer Technical Services
Autodesk Developer Network

0 Likes

karthur1
Mentor
Mentor

Wayne,

I am sending you an email.

 

Thanks,

Kirk

0 Likes

wayne.brill
Collaborator
Collaborator
Accepted solution

Hi Kirk,

 

Thanks for sending the assembly. Here is the iLogic rule that works for me. (no error about missing occurrence) Not exactly sure this is what you want.

 

oLength = InputBox("Enter the length change (+ or -)in inches.", "iLogic", "0.25")

Dim oAsmDoc as Inventor.AssemblyDocument
oAsmDoc = ThisDoc.Document

Dim comp As Inventor.ComponentOccurrence

		'Lista = ""
		
		For Each oOcc In ThisApplication.ActiveDocument.ComponentDefinition.Occurrences.AllLeafOccurrences
			'Lista=oOcc.Name
			'WB commented above, it helps me to have a variable name that indicates what the varible is
			occName = oOcc.Name
			
			'WB added - just wanted to see the names of the occurrences and exit
			'MsgBox("occName = " & occName)
		'Next
		'Return

	        'WB commented, not sure what this for loop was supposed to do
			'For Each comp In oAsmDoc.ComponentDefinition.Occurrences
		        'WB commented 
				'rowName = iPart.RowName(comp.Name)
				rowName = iPart.RowName(occName)
				RowValue = iPart.CurrentRowValue("Cutlength")
				StockNoStringValue = iPart.CurrentRowStringValue("Stock Number")
				NewLength = RowValue+oLength
				MemberStringValue = StockNoStringValue & "-" & NewLength

				'MsgBox("New Size==> " & MemberStringValue & " Current RowName==> " & rowname & " New Length ==> "& NewLength)
				'MsgBox("Size==> " & MemberStringValue & " RowName==> " & iPart.RowName(comp.Name) & " New Length ==> "& NewLength)

				MemberStringValue = iPart.CurrentRowStringValue("Stock Number") & "-" & iPart.CurrentRowValue("Cutlength") + oLength

				
				'iPart.ChangeRow(Lista, MemberStringValue)
				MsgBox("occName = " & occName & " Changing to " & MemberStringValue)
				iPart.ChangeRow(occName, MemberStringValue)
					
				
				'iPart.ChangeRow("iComponentName:1", "RowMemberName")
				
				'i = iPart.FindRow(comp.Name, "Member", "=", MemberStringValue) 
	 		Next
   			If i < 0 Then
       			MessageBox.Show("Some problem occurred", "iLogic")
    		Else
        		'MessageBox.Show("iPart set to row: " & MemberStringValue , "Change ALL members iLogic")
    		End If
	
		'WB commented
		'Next

Thanks,

Wayne



Wayne Brill
Developer Technical Services
Autodesk Developer Network

karthur1
Mentor
Mentor

Wayne,

Many thinks.... That is slick.  It does exactly what I was trying to do.  The for/next loop that you commented on was used to gather the information about each part in the assembly.  It would then search the ipart table and add the increment to the member.

 

I will try this later with the ipart member that is over 3,000 members long.  I think it will be faster..... will let you know how it goes.

 

Thanks again,

Kirk

 

 

 

 

 

 

 

 

0 Likes

karthur1
Mentor
Mentor

Wayne,

Normally when I am changing out these members, it will take about 45secs for the table to be displayed so I can select a different member.  I have to go thru each part and change them and it gets frustrating after awhile.

 

I tried this on my "working" ipart with over 3,000 rows in the table.  Attached is a video of this code working. It actually takes less than 20 secs to change 4 members. Smiley Happy

 

Thanks again,

Kirk

0 Likes

Jef_E
Collaborator
Collaborator

I can't see a video. Glad it's sorted for you!



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes

karthur1
Mentor
Mentor

I forgot to attach it, but I just edited my post.  See if its there now.

0 Likes