Auto update columns in iPart table using iLogic

Auto update columns in iPart table using iLogic

Anonymous
Not applicable
2,209 Views
10 Replies
Message 1 of 11

Auto update columns in iPart table using iLogic

Anonymous
Not applicable

Hi! 

I have recently started creating iParts and iAssemblies, but I have run into an issue I can not solve.

 

I created a part that who's geometry is driven by several parameters/ variables that I define in iLogic using If-Then statements.  When I create my iPart, I input values in column A that are used in the iLogic rule in column B, but column B does not update until I activate the part and I click through several errors.  How can I complete the values in column B using the formulas from iLogic and values from column A without having to activate each part and click through errors?

0 Likes
Accepted solutions (1)
2,210 Views
10 Replies
Replies (10)
Message 2 of 11

A.Acheson
Mentor
Mentor

Can you post a screenshot of the errors and or part with ilogic? Even a simple part having the same issues updating. 

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

Anonymous
Not applicable

@A.Acheson 

 

Attached is a simple example of what I'm trying to do.  If you look at the excel table for the iPart you can see that the table is not filled in all the way.  These values come from an iLogic If-Then rule and Inventor will fill them in if I click through each iPart, but I want to make hundreds of iterations, so I would prefer not to click through every part.

0 Likes
Message 4 of 11

A.Acheson
Mentor
Mentor

I had an attempt at updating your part. To eliminate the “” errors I had to place something in the cells missing like 0, iParts don’t like empty cells. Then looped through the member and press the member activation to bring up the change to parameter do you want to accept message box. Unfortunately there is no way to eliminate this message box. So even in a loop of all the members you still get this message box which is a keyboard entry enter to accept. So if you have 500 

That is 500 clicks. 

Could the calculations you have in the rule be done in excel and paste all the data,therefore eliminating the need to calculate each member?

 

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

Anonymous
Not applicable

Thank you for the response.

 

I'm sure I will be able to build something in Excel to fill in the blanks I was just hoping to have a solution within the iLogic.

Would it be possible for you to attach the partial solution you developed that loops through each iteration. I was trying to figure out the code to do that, but was unsuccessful, so I'm curious about what that looks like.

 

Thanks,

0 Likes
Message 6 of 11

A.Acheson
Mentor
Mentor
Accepted solution

Below Is code for your situation, either run As internal Or external rule. You can use it for iProperties also. This still requires user input but it is less clicking. 

https://forums.autodesk.com/t5/inventor-customization/automate-idw-drawing-file-creation-for-all-ipa...
http://inventortrenches.blogspot.com/2013/03/determine-file-type-for-ilogic-rule.html

Instructions***************************************************

Before starting:

 Ensure the iPart table browser Is expanded.Step Required
2. Add parameter columns to the iPart factory table before running this rule.

'What will happen
> This rule will loop through each member applying the parameters then activate each member.
> This activation will force the System generated Message Box To appear reading
'"The values in the Active Row of the table do not match the document's current values.
Do you wish To update the table before continuing?"
> Manually accept this change and select yes.
> Cycle repeats.

 

Sub Main
Check = MessageBox.Show("Loop through iPart factory and populated members, This will take a while. Are you sure?" _
, "Ilogic Instructions", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
If  Check = vbYes Then 
 	
	Dim oDoc As Document
	oDoc = ThisDoc.Document
	
    'Check if ODoc is a Part Document
	If oDoc.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject  Then
	   'MessageBox.Show("This is a part file.", "iLogic")
		      
		'Set a reference to the component definition
		oDef = ThisApplication.ActiveEditDocument.ComponentDefinition

		'Make sure we have an iPart factory.
	    If oDef.IsiPartFactory  = False Then
	        MsgBox ("Chosen document is not a factory.", vbExclamation)
	        Exit Sub
	    End If
			
		' Set a reference to the factory.
		Dim oFactory As iPartFactory
		oFactory = oDef.iPartFactory

		'iPartF = oDef.iPartMember.ParentFactory
		'Get the number of rows in the factory.
		Dim iNumRows As Integer
		iNumRows = oFactory.TableRows.Count 
		 
		Dim iRow As Integer
		'Set iRow = First Member
		oStart = InputBox("Pick a Start Row", "Member Start Row#", 1)
		oEnd = InputBox("Pick a Start Row", "Member Start Row#", iNumRows)

		Try
			For iRow = oStart To oEnd
				'Use if this main rule is external
				iLogicVb.RunRule("HolePlacement")

				'Change ipart Row
				iPart.ChangeRow("", iRow)
				
				'Use if memberfile name needed
				'MemberFileName = oFactory.FileNameColumn(iRow).Value
				'MessageBox.Show(MemberFileName, "Title")

				'[---Call external "function" or rule or do something---

				'[Select by UI the node of current member in order to bring up the message ipart has change contents,
				'If this is not used parameters will only apply to last member active
				'https://forums.autodesk.com/t5/inventor-customization/possible-to-check-all-members-of-factory-for-errors-using-ilogic/td-p/3863094

				Dim oErrorManager As ErrorManager
				   oErrorManager = ThisApplication.ErrorManager
				 
				Dim oTop As BrowserNode
				     oTop = oDoc.BrowserPanes("Model").TopNode
				   
				Dim bHasErrorOrWarning As Boolean
				'To skip without messages, this will not work for change of parameter
				'ThisApplication.SilentOperation = False
				   
			    ' Highlight the iPart table row 
			    oTop.BrowserNodes("Table").BrowserNodes.Item(iRow).DoSelect
		
			    ' Activate the iPart table row, this will trigger the "Do you want to change table contents accept yes to allow parameters to be saved to ipart member row. 
			    Dim oCommand As ControlDefinition
			    oCommand = ThisApplication.CommandManager.ControlDefinitions("PartComputeiPartRowCtxCmd")
			    oCommand.Execute
			
				 If oErrorManager.HasErrors Or oErrorManager.HasWarnings Then
				        MsgBox (oErrorManager.LastMessage, vbOKCancel)
				 End If
					 
					'Use if required
				'ThisDoc.Document.Rebuild() 
				'Create each member
'					Try	
'					 	Call oFactory.CreateMember
'					 Catch
'						MessageBox.Show("Error creating Member", "iLogic") 
'					 End Try
			Next
	
			Catch
			MessageBox.Show("Error Exiting", "iLogic")	
			End Try
			
			iLogicVb.UpdateWhenDone = True
			
				'open folder	
			'oFolder = ThisDoc.Path &"\" & ThisDoc.FileName(False)
			'Call Shell("explorer.exe" & " " & oFolder, vbNormalFocus)
		Else
		End If
	Else
	End If
End Sub

 

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

Anonymous
Not applicable

Thats 10x faster than anything I had come up with!

 

Thank you very much!

0 Likes
Message 8 of 11

Anonymous
Not applicable

What changes to the code would have to be made in order for this to work for an iAssembly?

0 Likes
Message 9 of 11

A.Acheson
Mentor
Mentor

@Anonymous 

Change "iPartFactory" to "iAssemblyFactory".

I think this is the only change I made. 

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

thfZPXHA
Explorer
Explorer

I got at code that calculates 2 parameters, which i want it to do in each member of the ifactory.

But it doesnt update them, nor ask me if i wanna update the member.

 

I can see it runs the code, after each change of row. and i can do it manually with my code, but it doesnt update it with yours

0 Likes
Message 11 of 11

A.Acheson
Mentor
Mentor

The issue you may be facing is how the parameters are typed. If you use Parameter("pRodLength") this will automatically update as the rule is running where as if you use  "pRodLength" then this will only update the last member at the end of the rule.

AAcheson_0-1659123848367.png

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