iLogic rule to update custom iproperties with ipart

iLogic rule to update custom iproperties with ipart

rederle
Enthusiast Enthusiast
2,668 Views
10 Replies
Message 1 of 11

iLogic rule to update custom iproperties with ipart

rederle
Enthusiast
Enthusiast

Ciao all,

 

I made a rule with iLogic to have, in automatic, the 3 maximum dimensions (lenght, hight, width) as 3 fields on custom iproperties (that iproperties don't drive any dimensions, but they are driven by some parameters)

 

Dim Length As Decimal = 0.0

Dim Height As Decimal = 0.0

Dim Width As Decimal = 0.0

 

Length = Measure.ExtentsLength

Height = Measure.ExtentsHeight

Width = Measure.ExtentsWidth

 

Dim SLength As String = Length.ToString()

Dim SHeight As String = Width.ToString()

Dim SWidth As String = Height.ToString()

 

iProperties.Value("Custom", "LUNGHEZZA_EXT") = SLength

iProperties.Value("Custom", "LARGHEZZA_EXT") = SWidth

iProperties.Value("Custom", "ALTEZZA_EXT") = SHeight

and the rule works well

 

the issue is when I add some iparts;

 

in this case I have to launch the iLogic rule for every ipart on table; if I don't do this the 3 custom iproperties don't update and it's a problem beacause if you measure of the 3d model you have the right max dimensions but the value on custom iproperties are wrong

 

is it possibile to make a rule of iLogic that update in automatic all iparts with my rule?

 

thanks

 

0 Likes
2,669 Views
10 Replies
Replies (10)
Message 2 of 11

A.Acheson
Mentor
Mentor

@rederle 

Edit

 

 Is the complete ilogic rule in the post above? Are the iparts changing with geometry or are they fixed? The iproperties should be driven from the factory/master file out to each member. So the ilogic rule would need to act on the factory file then update the member/members then show up in your assembly. 

 

In message 6 of 26  of the link below you will find a rule, place your ilogic rule or it's contents inside the for loop  just above the line below. 

oFactory.CreateMember(oRow)

https://forums.autodesk.com/t5/inventor-forum/ipart-quot-generate-files-quot-hot-key/td-p/6344555

This will then carry out the iproperty creation and create the ipart member, please ensure all iproperties you want to include in the ipart members have there column title on the factory excel table otherwise the rule will only apply to the last member the rule acts on. 

 

Could you explain in a little more detail your workflow and provide some screenshots if this has not answered your question?

 

Hope this helps 

Alan

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

rederle
Enthusiast
Enthusiast

Ciao,

 

thanks for your answer but it seem not working; I have the same problem; maybe I did some mistake...

 

I try to explain better and I attach some screens; I want to have on custom iproperties the external dimensions of 3d model; this is because I need 3 fields where our PLM (we don't use Vault) and erp SAP will pick up these values (it's for logistic dept); I'd like find an automatic mode to fill these 3 fields so there isn't risk to have a wrong value

 

So I find the iLogic rule that I posted above, and it works well; the problem, as wrote, is  when I use iparts; 

 

in these pictures you can see an example;

 

I build a solid where the main dimensions are driven by 3 parameters (DIM_1=500mm, DIM_2=200mm, DIM_3=1000mm), also there is a cylinder of 150mm hight

 

so his external dimensions are: 1150X500X200; and when I launch my iLogic rule on custom iproperties the 3 fields are right filled

4.JPG

now, I add 3 iparts where I change just the DIM_3 (so just 1 of external dimension field will change, the others 2 will be the same),  if I don't launch for every ipart the iLogic rule, the field of external dimension LARGHEZZA_EXT will be not update; so the measure on the solid model are ok, while the custon iproperties are wrong

7.JPG

 I need something to launch my iLogic rule for whole iparts, not one by one; 

 

 

0 Likes
Message 4 of 11

rederle
Enthusiast
Enthusiast

I attach also the ipt example that I used

0 Likes
Message 5 of 11

A.Acheson
Mentor
Mentor

The previous example I posted whilst it creates the members from the factory it does not allow iProperties to be added to each member. I had worked on this issue before you posted over the holidays  I was using this to import MRP/inventory information  in to the iParts. The iPart table is difficult to arrange all columns in the correct order for a mass copy and paste so this was a solution for that.

 

There seems to be two methods to update the iProperties through ILogic and if you read the instructions you should see the difference when you run the code using either Method A or Method B.

I like Method A as it is the method that you would use for any parameters changing so iProperties should also follow this method. 

 

If you want to test this follow Method B first then add the iProperties columns and follow method A

Test on a sample part first to ensure results are accurate enough before running in production. 

 

Below is code for for your situation, either run as internal or external rule, event triggers should be easy enough to set up. .

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

'Instructions***************************************************
'Method A:Rule run when iProperties columns are added to the iPart factory table:
'Add iProperties columns to the iPart factory table before running this rule.
'1.This rule will loop through each member applying the iProperties then activate each member.
'2.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?" '3. Manually accept this change and select yes. '4. Cycle repeats. 'Method B:Rule run without iProperties columns added to the iPart factory table: '1.This rule will loop through each member applying the iProperties then activate each member. '2.iPart members are created/updated and receive the iProperties but the factory iProperties will show only the last member the iProperties were added Too. '3.Cycle repeats.
' 'This method can be confusing as you cannot check the results of the rules, Solution add any column that changes to the Table. 'Instructions End *************************************************** 'start of iLogic rule - - - - - - - - - - - - - - - - - - Check = MessageBox.Show("Add required iProperties to first member then add columns to iPart factory table" _ & vbNewLine & "" _ & vbNewLine & "If iProperty columns are not present only one member will have iProperties updated correctly" _ & vbNewLine & "in the factory file, member properties will be updated" _ & vbNewLine & "" _ & vbNewLine & "This rule will work on all iPart members,if there are many it will take a long time!" _ & vbNewLine , "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 Try For iRow = 1 To iNumRows '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--- Dim Length As Decimal = 0.0 Dim Height As Decimal = 0.0 Dim Width As Decimal = 0.0 Length = Measure.ExtentsLength Height = Measure.ExtentsHeight Width = Measure.ExtentsWidth Dim SLength As String = Length.ToString() Dim SHeight As String = Width.ToString() Dim SWidth As String = Height.ToString() iProperties.Value("Custom", "LUNGHEZZA_EXT") = SLength iProperties.Value("Custom", "LARGHEZZA_EXT") = SWidth iProperties.Value("Custom", "ALTEZZA_EXT") = SHeight ' '[Select by UI the node of current member in order to bring up the message ipart has change contents, 'If this is not used iproperties 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 'ThisApplication.SilentOperation = True ' 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 iproperties to stick to the member row. Dim oCommand As ControlDefinition oCommand = ThisApplication.CommandManager.ControlDefinitions("PartComputeiPartRowCtxCmd") oCommand.Execute 'ThisApplication.SilentOperation = False If oErrorManager.HasErrors Or oErrorManager.HasWarnings Then MsgBox (oErrorManager.LastMessage, vbOKCancel) End If '] 'Rebuild as create member can sometimes fail ThisDoc.Document.Rebuild() Try 'Create each member 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) End If Else MessageBox.Show("Rule Canceled Exiting", "iLogic") End If

 

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

dutt.thakar
Collaborator
Collaborator

@rederle 

 As far as I understand you want to reflect the dimensions of the parameters in the custom iProperties for each iPart instance.  You can accomplish the same without iLogic rule. I have recreated your iPart as I am using Inventor 2019. See the screencast video below for more information. I have created extra parameter H_DIM, to get the  DIM_3 +150 mm dimension.

 

You need to export the parameters and link them with iProperties. Hope this will be helpful.

If this answer has solved your problem please ACCEPT SOLUTION and hit like if you found it helpful..!


Regards,
Dutt Thakar
LinkedIn
0 Likes
Message 7 of 11

rederle
Enthusiast
Enthusiast

thanks for help, but I think, I make wrong something because the rule is not working

 

I copied the rule that you shared me but it's gave me error message  

8.JPG

 

I put in ipart table the custom iproperties and I launch your rule but table didn't update..

9.JPG

0 Likes
Message 8 of 11

A.Acheson
Mentor
Mentor

@rederle 

 

I added the rule to your file and it worked first time. I think I came across that error before regarding the member creation. If the members have been deleted in windows during the same inventor session it can be difficult for them to be created. Only a manually generate file can get around this or close the inventor session. You could just place a message box at various points down the code and debug until you get to the error point. I'm on inventor 2020 and there may be differences from version to version.

 

Hope this helps

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

rederle
Enthusiast
Enthusiast

I'm using Inventor 2020 too

 

tomorrow I'm trying to follow your suggest

 

thanks

0 Likes
Message 10 of 11

J-Camper
Advisor
Advisor

If this rule is going to live locally inside the iPart, then you could simply reference the parameters that are changing in your rule.  This will make the rule automatically trigger anytime one of those dimensions change.  This simple change could be all you need to get the iProperties to update when you change members:

'Gets rule to trigger if Parameter values changes
Dim Length As Decimal = DIM_3
'Gets rule to trigger if Parameter values changes
Dim Height As Decimal = DIM_2
'Gets rule to trigger if Parameter values changes
Dim Width As Decimal = DIM_1

'Set Actual value to model value
Length = Measure.ExtentsLength
'Set Actual value to model value
Height = Measure.ExtentsHeight
'Set Actual value to model value
Width = Measure.ExtentsWidth
 
'This Step Could be condensed with previous line: Dim SLength As String = Measure.ExtentsLength.ToString
Dim SLength As String = Length.ToString()
'This Step Could be condensed with previous line: Dim SHeight As String = Measure.ExtentsHeight.ToString
Dim SHeight As String = Width.ToString()
'This Step Could be condensed with previous line: Dim SWidth As String = Measure.ExtentsWidth.ToString
Dim SWidth As String = Height.ToString()

'Set Custom iProperty
iProperties.Value("Custom", "LUNGHEZZA_EXT") = SLength
'Set Custom iProperty
iProperties.Value("Custom", "LARGHEZZA_EXT") = SWidth
'Set Custom iProperty
iProperties.Value("Custom", "ALTEZZA_EXT") = SHeight

 

This trick will not work if you want this rule to live as an external rule.  Let me know if you have any questions, or if this is not working as intended

Message 11 of 11

rederle
Enthusiast
Enthusiast

thanks!

 

essentially, maybe this is the easier solution; I think, it's accettable

 

I tryed faster today with a sample and it worked; tomorrow I'm making other tests just to be sure.

0 Likes