iLogic Create Model State in Part won't run again

iLogic Create Model State in Part won't run again

zoe.baker-bushby
Enthusiast Enthusiast
648 Views
6 Replies
Message 1 of 7

iLogic Create Model State in Part won't run again

zoe.baker-bushby
Enthusiast
Enthusiast

Hi I have the following rule:

	MessageBox.Show("START")
	Dim doc As PartDocument = ThisDoc.Document
	oPCD = doc.ComponentDefinition
	oMStates = oPCD.ModelStates
	Dim masterMS As ModelState = oMStates.Item("Master")
	masterMS.Activate()
	oMState = oMStates.Add(PartNumber)
	ThisDoc.ActiveModelState = "Master"
	
	PartNumber = PartNumber
	
	iLogicVb.UpdateWhenDone = True

 

I call this via a button in a form. On first run it works fine.

 

When trying to run again, ModelStateName being set to a different name, it will not execute.

The 'START' message box doesn't even appear. 

 

Is there something wrong with my code or is this a bug??

 

Any advice would be great 🙂

 

649 Views
6 Replies
Replies (6)
Message 2 of 7

vpeuvion
Advocate
Advocate

Hi, this line is the problem for me :

ThisDoc.ActiveModelState = "Master"

It may be unnecessary since the state of the activated model does not change with the execution of the code.

You can test by commenting it.

Hope this will help you. Vincent.

0 Likes
Message 3 of 7

zoe.baker-bushby
Enthusiast
Enthusiast

The activated model state does change though?

When you create a new model state it automatically changes to the new state?

Just running something as small as:

MessageBox.Show("START")
Dim doc As PartDocument = ThisDoc.Document
oPCD = doc.ComponentDefinition
oMStates = oPCD.ModelStates
oMState = oMStates.Add(PartNumber)
iLogicVb.UpdateWhenDone = True

Changes the state.

 

You are however correct in saying that:

ThisDoc.ActiveModelState = "Master"

Is the line that is making it so that the rule does not run again.

However, I need it to toggle back to Master.

 

Changing syntax to:

Dim masterMS As ModelState = oMStates.Item("Master")
masterMS.Activate()

Also doesn't work. It again runs once but won't run again.

 

However if I make a separate rule which just has:

ThisDoc.ActiveModelState = "Master"

 

I can then call this from my other rule and everything works fine...

MessageBox.Show("START")
Dim doc As PartDocument = ThisDoc.Document
oPCD = doc.ComponentDefinition
oMStates = oPCD.ModelStates
oMState = oMStates.Add(PartNumber)
iLogicVb.RunRule("Master")
iLogicVb.UpdateWhenDone = True

 So the order I am trying to do things is fine.

 

This has got to be a bug?

Unless I am just overlooking something 😕

0 Likes
Message 4 of 7

vpeuvion
Advocate
Advocate

Hello, Yes you are right, it is changing to the new state. I did some tests on ilogic and I need to open the rule to be able to run the code again.
I've never encountered this scenario and I don't know what's going on.
I hope that using a second rule has allowed you to unblock the situation.
I can't help you more, maybe someone has already encountered this problem and can help you? Either way, I'd be curious to know what's wrong.

Vincent.

Message 5 of 7

CattabianiI
Collaborator
Collaborator

I tested your rule in Inventor 2022.3 and it works as expected.
Which version are you using?

Is this the behaviour in any new part document? 
If you run the rule manually instead through button do you have the issue?

0 Likes
Message 6 of 7

zoe.baker-bushby
Enthusiast
Enthusiast

Hi,

 

I am using 2022.3.

 

I have tried running it in a new part, see screen recording:

Rule doesn't run twice | Search | Autodesk Knowledge Network

 

This is running the original code I posted.

As you can see it runs once, but to be able to run again you have to open and then close the rule??

Once opened and closed, you can choose to right click and run or click the button in the form.

 

Thanks,

Zoe

Message 7 of 7

CattabianiI
Collaborator
Collaborator

Hi @zoe.baker-bushby,
you're right and I've the exact behaviour now.

I simplified the rule, and just switching between model states causes the issue.
 
Create another model state named "Model State1" , add and run the rule, first time it runs then nothing.

	MessageBox.Show("START")
	Dim doc As PartDocument = ThisApplication.ActiveDocument
	Dim modelStates As ModelStates = doc.ComponentDefinition.ModelStates
	Dim masterMs As ModelState = modelStates.Item("Master")
	Dim ms1 As ModelState = modelStates.Item("Model State1")
	ms1.Activate()
	masterMs.Activate()	

 
@johnsonshiue could you look into this?