Modelstates, iProperties & Parameters - continued

Modelstates, iProperties & Parameters - continued

NachoShaw
Advisor Advisor
617 Views
2 Replies
Message 1 of 3

Modelstates, iProperties & Parameters - continued

NachoShaw
Advisor
Advisor

Hey

 

seeing as i dint get any response on my last similar topic, i tohught id create a fresh one as the requirement is different.

 

So far, we have established-

  • Text parameters cannot be exported as iProperties
  • Text Parameters cannot be linked to other components parameters
  • ModelStates do not allow for Text parameter values per ModelState like it does with numerical
  • ModelStates do allow for individual values but only if the ModelState is manually activated....

ok!

 

If i place a component into an assembly and that component has multiple ModelStates, i can assign a ModelState to each occurrence. in the Bill of Material, i can manually type in separate properties in the same iProperty field for each ModelState version of that occurrence and that iProperty value per occurrence is saved per ModelState which IS what im trying to do.

 

In code, i turned to iLogic to try and do the same but once again, it doesnt work as expected

iProperties.Value("Test" &":1", "Custom", "PARTNo") = Parameter("TestBM:1", "PartNo1")
iProperties.Value("Test" &":2", "Custom", "PARTNo") = Parameter("TestBM:1", "PartNo2")
iProperties.Value("Test" &":3", "Custom", "PARTNo") = Parameter("TestBM:1", "PartNo3")

this 'should' look at each occurrence (1,2 & 3) and update the PartNo iProperty "PARTNo" with the retrieved Parameter value collected from TestBM:1 occurrence parameters but it doesnt.

 

Questions:

how would i successfully get the ModelState iProperty value to receive the required value per modelstate so that the BOM shows them correctly without a manual intervention? 

 

Thanks

 

 

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes
618 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor

After a lot of trial & error testing, I don't think I'm any further along in understanding this whole situation than I was to start with. 🙄  I've tried doing this kind of thing completely by the API route (avoiding any iLogic only stuff), and I've tried it using almost entirely iLogic only stuff.  It almost seems like there is some kind of 'random' aspect somewhere in the midst of it all.  At times, all methods I was using seemed to be working, then other times only certain ones were working some of the time.  Seemingly no explanations as to why.  At one point I could only get the API route to work for getting the parameter value, while the iLogic snippet route was failing.  Then later they were both working just fine.  Sometimes none of them were working on one of the 3 components (the one set to Master), but they were working just fine on the other 2 components (set to non-master).  I haven't been able to 100% nail it down quite yet, so everything is working all the time.  Here is some of my testing code, but I'm sure you've got plenty of your own by now.

 

Repeat :
oObj = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select a Component.")
If IsNothing(oObj) OrElse (TypeOf oObj Is ComponentOccurrence = False) Then Exit Sub
Dim oOcc As ComponentOccurrence = oObj

oPName = "Numeric1" 'name of iProperty & Parameter

'the iLogic snippet route
oIPropVal2 = iProperties.Value(oOcc.Name, "Custom", oPName)
MsgBox("iLogic Snippet iProperty Value = " & oIPropVal2,,"")
oParamVal2 = Parameter(oOcc.Name, oPName)
MsgBox("iLogic Snippet Parameter Expression = " & oParamVal2,,"")

'the API route
Dim oOccMSDoc As Document
If oOcc.ActiveModelState = "Master" Then
	oOccMSDoc = oOcc.Definition.Document
Else
	oOccMSDoc = oOcc.Definition.ModelStates.Item(oOcc.ActiveModelState).Document
End If
oIPropVal1 = oOccMSDoc.PropertySets.Item("Inventor User Defined Properties").Item(oPName).Value
MsgBox("API iProperty Value = " & oIPropVal1,,"")
oParamVal1 = oOccMSDoc.ComponentDefinition.Parameters.Item(oPName).Expression
MsgBox("API Parameter Expression = " & oParamVal1,,"")

GoTo Repeat

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 3

NachoShaw
Advisor
Advisor

Hey

 

Thanks for the reply. Yes i have been getting random results too. I say 'tongue in cheek' that my current process appears to be working so maybe try that? Here is what i have

 

Base Model Parameters

Param1 = 100 in

Param2 = 120 in

Param3 = 150 in

 

Part Parameters

Length = 0 in

Param1 (derived from Base Model)

Param2 (derived from Base Model)

Param3 (derived from Base Model)

 

Part ModelStates

ModelState1

ModelState2

ModelState3

 

Each ModelState will accept a parameter per ModelState HOWEVER, there is an issue if you set a parameter like Length that i have to another value of another Parameter. At part level, you will see the correct value. If you export the Parameter Length to an iProperty, you will also see the length. If you put the part in an Assembly then look ast the Bill of Materials, the column Length will show 'Param1' as the parameter expression text instead of the Param1.Value of 100 in... Frustrating.

 

Back to the part.

To get this method to work (getting the iProperty to populate from a ModelState value), This is what i needed to do-

Make sure the parameter Length was not exported (else it wont work)

Set this parameter to the respective linked parameter per ModelState

ModelState1 Length = Param1 (derived from Base Model)

ModelState2 Length = Param2 (derived from Base Model)

ModelState3 Length = Param3 (derived from Base Model)

 

Then in iLogic, add a line of code to run automatically

iProperties.Value("Custom", "Length") = Length

This takes the value of parameter Length and places it into the iProperty of Length. If the parameter Length is set to export, you will get the parameter name as text in the BOM.... This seems to work per ModelState

 

Text Parameters

I have had to do this at assembly level per occurrence (which i really didnt want to do because occurrences change but thanks to Autodesk, yet another limitation we need to deal with)

iProperties.Value("OccurrenceName:1", "Custom", "iPropertyName") = Parameter("Base Model:1", "ParameterName")

I did this for each occurrence and each occurrence had a different model state. This was the only way i could find to populate a Text iProperty from a text Parameter value... Long & clumbsy but it does work.

 

IF autodesk could fix it so that-

  • Text Parameters can be exported
  • Text Parameters can be linked to other components
  • Text Parameters can be ModelState specific 

it would im sure, save a headache for lots of people but i think it falls on deaf ears most of the time. I like to think of Inventor & coding like a pinball machine where Inventor is the game, coding is the ball the bottom hole is the result and the flicker arms are the API developers. Just as the ball is rolling to the hole, out comes a flicker arm as an obstacle to push you back.. 😂😂

 

 

Anyway, hope this works for you, it is working for me as a reasonable fix 😀

 

 

Best

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.