Model states - More then 1 parameter to controll it

Model states - More then 1 parameter to controll it

jhhEFBNL
Enthusiast Enthusiast
854 Views
3 Replies
Message 1 of 4

Model states - More then 1 parameter to controll it

jhhEFBNL
Enthusiast
Enthusiast

So im trying to figure out how to creat model states based on 3 paramteres on the part. 

 

I have found/made a iLogic rule to make this, but i can only seem to get it to work with 1 parameter. 

Sub Main
	Dim doc As AssemblyDocument = ThisDoc.Document
	
	'Manage Lenght
	SetModelState(doc.ComponentDefinition.Occurrences.ItemByName("Bjelke:1"), BjelkeLengde)

	
	InventorVb.DocumentUpdate()
End Sub


Private Sub SetModelState(bracketOcc As ComponentOccurrence, Lengde As String)
	Dim bracketCompDef As PartComponentDefinition = bracketOcc.Definition.Document.ComponentDefinition
	'This factory document is new!
	Dim bracketFacDoc As PartDocument = bracketCompDef.FactoryDocument
	Dim bracketModelStates As ModelStates = bracketFacDoc.ComponentDefinition.ModelStates
	
	'Check if the model state exists already by looking at names
	Dim stateToSet As ModelState = (From foundModelState As ModelState In bracketModelStates
									Where foundModelState.Name = Lengde).FirstOrDefault
	If stateToSet IsNot Nothing Then
		bracketOcc.ActiveModelState = stateToSet.Name
	Else
		'Create a new model state
		stateToSet = bracketModelStates.Add(Lengde)
		'Activate the new model state before we update the user parameter as this is different per state
		stateToSet.Activate
		'Find the "Length" user parameter
		Dim foundParameter As UserParameter = (From param As UserParameter In bracketFacDoc.ComponentDefinition.Parameters.UserParameters
											   Where param.Name = "Lengde").FirstOrDefault
		foundParameter.Expression = Lengde
		
		'Finally set this new model state as active for the bracket occurrence we were given
		bracketOcc.ActiveModelState = stateToSet.Name
	End If
End Sub

 

This is the code im using so far. This is working fin and is changing the model and creating new model states if the paramter chosen do not match.

The model i want to creat model states in has 3 properties that can be changed. (Lenght/width/height)

 

Is it posibal and can someone guide me into the right directions on how i can use 3 diferent paramteres to creat 1 uniqe model state? 

I want to set all 3 paramteres and then check it the modell states exist or should be createt. 

0 Likes
855 Views
3 Replies
Replies (3)
Message 2 of 4

dalton98
Collaborator
Collaborator

I find working with model states easier in the model state excel file. Here is an example that uses that:

Dim oDoc As PartDocument = ThisApplication.ActiveDocument
Dim oWS As Object = oDoc.ComponentDefinition.ModelStates.ExcelWorkSheet
Dim rowCount As Integer = oWS.UsedRange.Rows.Count

'3 parameters
Dim oWidth As Double = 100 'excel column 2
Dim oHeight As Double = 150 'excel column 3
Dim oLength As Double = 200 'excel column 4

For i = 2 To rowCount
	If oWS.Range("B" & i ).Value = oWidth & " in"
'		If oWS.Range("C" & i).Value = oHeight & " in"
'			If oWS.Range("D" & i).Value = oLength & " in"
'				'it exists
				oDoc.ComponentDefinition.ModelStates.Item(i - 1).Activate
				Return
			End If
'		End If
'	End If
Next

'make new row
oWS.Range("2:2").Copy
oWS.Range(rowCount + 1 & ":" & rowCount + 1).PasteSpecial
oWS.Cells(rowCount + 1, 1).Value = "new"
oWS.Cells(rowCount + 1, 2).Value = oWidth & " in"
oWS.Cells(rowCount + 1, 3).Value = oHeight & " in"
oWS.Cells(rowCount + 1, 4).Value = oLength & " in"
oWS.Parent.Save
oWS.Parent.Close
0 Likes
Message 3 of 4

jhhEFBNL
Enthusiast
Enthusiast

Hi and thanks for the reply. 

 

Looking more into this i think i might have over complicated the procces we need.

(Im not to good whit all this coding so i might make it more copmlicated then what it needs to be)


Going to try explain what we need/want.

 

Using one of our models as example wich is a smal shelving rack.

This consist of different parts like:

  • The upright
  • Sheelves
  • Accessories 

Each of this parts consistes off different variations wich ar put together in an assembly to make a complete rack. 

This configuration will be diffrent each time we are making the modell.

 

The user will have X amount of choice they can make in the assembly

  • One box will define the size/shape of the upright
  • One box will define the size/deepth of the sheelve
  • ++

Im looking into to make all the parts be predefind with all the diffrent size that is posible to pick. 

This i find the Excel spread sheet to be an easy way to deffine this. And we can add info about part number and so on aswell. 

 

  • Making the parts and adding modelstates manualy is ok. This we can do.
  • Adding parts to an assembly and constrain all this we can do. 
  • Adding Ilogic rules for what to show and not we can do.

 

What im strugeling to find is how can i call for a modelstate to be chocen in the assembly?

Can you in the ILogic form get a drop down list that lists all modelstates of a part?

 

I can add that we are not a manufacture of the parts, we only order by partnumbers. 

0 Likes
Message 4 of 4

dalton98
Collaborator
Collaborator

Ok I think I see what your trying to do now. This seems like it will be a fairly large coding project. How I would go about setting it up:

1. create a model state for every possible shelf and support part

2. create one assembly with multi value parameters that link to the model state part

3. create an ilogic rule and form for the assembly based on the parameters

 

I wouldn't make too many, if any, model states for the assembly. You could just copy the file each time you need a different assembly configuration in your main assembly project. Creating a drop down list:

Dim oAss As AssemblyDocument = ThisApplication.ActiveDocument
Dim oOcc As ComponentOccurrence
oOcc = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "select model state part")
Dim oCompDef As PartComponentDefinition
oCompDef = oOcc.Definition

Dim oList As New ArrayList
Dim oMS As ModelState
For Each oMS In oCompDef.ModelStates
	oList.Add(oMS.Name)
Next

Dim oMSName As String = InputListBox("Prompt", oList)
Component.ActiveModelState(oOcc.Name) = oMSName

If you want it to be parameter based it will require more work on the front end but will easier to manage:

MultiValue.List("Blue_Param") =  oList.ToArray

Select Case Blue_Param 
	Case "multi-value1"
		Component.ActiveModelState("part1:1") = "ModelState1"
		Component.ActiveModelState("part1:2") = "ModelState1"
	Case "multi-value2"
		Component.ActiveModelState("part1:1") = "ModelState2"
		Component.ActiveModelState("part1:2") = "ModelState2"
End Select
0 Likes