Changing Iproperties material in a part

Changing Iproperties material in a part

JorisSteurs1246
Advocate Advocate
1,650 Views
11 Replies
Message 1 of 12

Changing Iproperties material in a part

JorisSteurs1246
Advocate
Advocate

I want to change the part material trough an iLogic form.

 

The code below reads the available materials and puts them in a multivalue list.

The problem I have is that the rule doen't make the part material change to what I've selected in from the multivalue list.

 

Please Help.. Man Sad

 

SyntaxEditor Code Snippet

Try
Sl = Parameter.Param("SheetMetalType") 
Catch
oMyParameter=ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters
oParameter=oMyParameter.AddByValue("SheetMetalType","undefined", UnitsTypeEnum.kTextUnits)
 End Try 
Dim smStyleList As New ArrayList

For Each smStyle As SheetMetalStyle In ThisDoc.Document.ComponentDefinition.SheetMetalStyles
    smStyleList.Add(smStyle.Name)
Next smStyle



Parameter.Param("SheetMetalType").Comment = "Parameter set by Rule -- RunOnSheetMetal-- "

MultiValue.List("SheetMetalType") = smStyleList

Try
 p = Parameter.Param("Partmaterial") 
Catch
oMyParameter=ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters
oParameter=oMyParameter.AddByValue("Partmaterial","Steel, Mild", UnitsTypeEnum.kTextUnits)
 End Try 
MultiValue.List("Partmaterial") = iProperties.Materials

RuleParametersOutput()
iLogicVb.UpdateWhenDone = True
iProperties.Material = Partmaterial
Parameter.Param("Partmaterial").Comment = "Parameter Set by Rule -- RunOnSheetMetal-- "

0 Likes
Accepted solutions (1)
1,651 Views
11 Replies
Replies (11)
Message 2 of 12

Anonymous
Not applicable
I've something at work that should achieve this. If nobody posts a solution I'll help you out if I can on Monday.
0 Likes
Message 3 of 12

Mike.Wohletz
Collaborator
Collaborator

Add the below to the end of your list and it should work just fine. 

 

Dim osmCompDef As SheetMetalComponentDefinition = ThisApplication.ActiveDocument.ComponentDefinition
                                For Each s As SheetMetalStyle In osmCompDef.SheetMetalStyles
                                    If s.Name = SheetMetalType Then
                                        s.Activate()
                                    End If
                                Next
0 Likes
Message 4 of 12

JorisSteurs1246
Advocate
Advocate

HI Mike,

 

Thanks for looking in to this.

Your suggestion to add your bit of code is not helping.

The reason is most likely because it is dealing whith the sheetmetal style.

Sheetmetal style selecting is working ok already.

It is the part material selecting that doesn't make the changes on the part.

The rule also gives an error ( see attachment)

 

Thanks 

 

Joris

0 Likes
Message 5 of 12

Anonymous
Not applicable

I created the multi value list allowing custom values then created this rule to show the form and allocate the material.

Maybe you can use this in your code somewhere?

 

iLogicForm.Show("CONFIGURATION", FormMode.NonModal)
MultiValue.List("MATERIAL") = iProperties.Materials
iProperties.Material=MATERIAL
Trigger=iTrigger0 

 

Now when the form is used to select the material it updates to the part.

It is probably obvious that I am no expert but it seems to work fine and I hope this helps in some way.

0 Likes
Message 6 of 12

JorisSteurs1246
Advocate
Advocate
Thanks for your contribution 🙂

Your line of code is what I have also, but it is not working for me .
I added the triggers as you have but it made no change, I still get the
same error message.
0 Likes
Message 7 of 12

Anonymous
Not applicable

Sorry about that I've been running this for some time now without any issues. Maybe somebody more knowledgeable than me can tell you why there is an error?

Sorry I couldn't be of any help.

0 Likes
Message 8 of 12

JorisSteurs1246
Advocate
Advocate
No Worries,

All attempts to help are very much appreciated , even if they were not
successful it will hopefully help me to narrow down the problem.

Thanks

Joris
0 Likes
Message 9 of 12

Mike.Wohletz
Collaborator
Collaborator
Accepted solution

I guess I dont see what part is not working as the posted code does not change the SheetMetal defaults and the material type does change so I have posted a solution for the part that does not work. can you tell us what version of Inventor you are using?

see Screencast included in this post.

http://autode.sk/1I6efWB

 

Message 10 of 12

MechMachineMan
Advisor
Advisor

Does swapping between flat pattern and folded model make a difference?


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 11 of 12

JorisSteurs1246
Advocate
Advocate

No, folded or unfolded state of the sheetmetal part gives the same error.

0 Likes
Message 12 of 12

JorisSteurs1246
Advocate
Advocate

Hi Mike,

 

The way you show it in the screencast is exactly what I' aiming for.

Happy to seeing it working.

I'm using AI2015-PRO

I can see you get the same error, but that nevertheless, after ignoring the error the part will adjust the material after selection of the material in the form.

The only difference I'm doing here is that both the rule and the form that is used are global.. nothing local like in your screencast.

Do you get the same result when setting everything as global?

 

Thank you so much for your contribution so far,

 

Joris

0 Likes