Late Binding issue - Tips needed for data/sync handling

Late Binding issue - Tips needed for data/sync handling

llorden4
Collaborator Collaborator
729 Views
5 Replies
Message 1 of 6

Late Binding issue - Tips needed for data/sync handling

llorden4
Collaborator
Collaborator

I'm frequently running into a this Late Binding issue as I continue to expand my use of iLogic and the API and it would appear I'm missing a workflow process somewhere.  Sorry for the wall of text as it's a complex issue, do me the favor of actually reading this is you'd like to assist.

 

The Late Binding error is typically an issue with failing to declare a variable before using it (ie.  Dim VARIABLE as Double)

I am confident I have all my variables declared properly, but am including the current state of the files & coding for anyone wanting to review and point out where I have not.  My error is occurring when changing a Parameter value, running the rule a second time results in success, further evidence that the error appears to be a timing/synchronization issue of processed data.

 

As I understand iLogic, and the API, they operate at different speeds and independently of each other.

While the rule is running, any changes to Parameter values do not keep up with rule and are updated sometime after the rule has completed its run; depending upon the processes used.

For example:

Parameter("MyParameter") = "New Value" (as shown in the Snippet menu in iLogic) will not visually change the parameter value to the user unless the rule is run a 2nd time, but does update the value within ilogic immediately.  However,

MyParameter = "NewValue" will immediately update the Parameter for the user (and Forms), but does not update the value for use within iLogic while the rule is still running.

 

 

As such,  I make it a habit to set a new variable name with a current Parameter value, make modifications to that new variable, and then update Parameter value for the user in a follow up command.  Example:

Dim NewParam as String = MyParameter

NewParam = "Something New"

MyParameter = NewParam

 

This process usually works for me, but I am still running into occasions where I don't feel this is taking care of all my data sync issues, especially when working with multiple files in an assembly; which is where I am with this issue.

 

So I'm reaching for a little help or confirmation that there's a data sync management issue being unmet here and a better way to workflow this to ensure successful data handling.  If that isn't the issue, then perhaps you have the experience to point out what it is I'm missing in this current workflow.

 

Thanks in advance for any assist.

Inventor 2021.3.1

llorden4_2-1624642295842.png

 

 

Autodesk Inventor Certified Professional
0 Likes
Accepted solutions (1)
730 Views
5 Replies
Replies (5)
Message 2 of 6

llorden4
Collaborator
Collaborator

After continuing to add code and taking note of some tree browser results, I have confirmed that the issue I currently face is not a parameter handling issue but is instead proving to be a constraint handling issue.

 

Rather than taking the time to evaluate any constraints found, I have taken an approach to simply delete any constraints currently found and start anew with each run of the rule.  It seems to me that the call to delete the existing constraint is not completing and clearing before the command to create a new one is called; even with a InventorVb.DocumentUpdate(False) added directly after the calls to delete any existing constraints.  The constraints appear to clear after the rule exits and therefore the next run of the rule allows the rule to successfully add the new constraints on the next run.

 

Suggestions on a way to successfully handle this?

 

FYI, REMming out these lines of codes allow the rule to run successfully each time.

'Add constraints
		Constraints.AddMate("FSMate:1", "FSVang:1", "X Axis", "", "X Axis", offset :=0)
		Constraints.AddFlush("FSFlush:1", "FSVang:1", "XY Plane", "", "XY Plane", offset :=0)
		Constraints.AddFlush("FSFlush:2", "FSVang:1", "YZ Plane", "", "YZ Plane", offset :=(0.125 in + oSVThick))
Autodesk Inventor Certified Professional
0 Likes
Message 3 of 6

nmunro
Collaborator
Collaborator

A couple of things you might try.

 

  1. Call ThisApplication.UserInterfaceManager.DoEvents after your constraint deletions and before adding new constraints.
  2. Try wrapping the constraint deletions in a transaction, and perhaps the additions in a second transaction.

        


https://c3mcad.com

0 Likes
Message 4 of 6

Ralf_Krieg
Advisor
Advisor
Accepted solution

Hello

 

There is at least one big missunderstanding in your code. I think in the code block below you try to write back the values of variables oRodDia, oHSSsize and so on back to the fx-Parameters RodDia, HSSsize and so on. No, you don't do that.

 

'Data sync
'Parameter.UpdateAfterChange = True
If RodDia <> oRodDia Then RodDia = oRodDia
If HSSsize <> oHSSsize Then HSSsize = oHSSsize
If HSSthick <> oHSSthick Then HSSthick = oHSSthick
....

 

If you use the name of an existing parameter like in assigning a value to the variables oRodDia, oHSSsize like below, Inventor creates a variable "RodDia" and assigns the current value of the fx-Parameter "RodDia" to it.

 

'Rounding & basic checks
Dim oRodDia As Double = Round(RodDia / 1 in * 8 ) / 8 * 1 in
Dim oHSSsize As Double = Round(HSSsize / 1 in * 4) / 4 * 1 in
.....

 

Changing the value of the Inventor generated variable "RodDia" does not immediatly change the value of fx-Parameter "RodDia". To do this, you can use two ways. First, if you don't need Inventor generated variable "RodDia" no longer, assign value of variable "oRodDia" to fx-Parameter "RodDia" like

 

If RodDia <> oRodDia Then Parameter.Param("RodDia").Expression  = oRodDia
If HSSsize <> oHSSsize Then Parameter.Param("HSSsize").Expression = oHSSsize
.....

 

Second, use the following methods right after the code block with all the "parameter changing"

 

'Data sync
'Parameter.UpdateAfterChange = True
If RodDia <> oRodDia Then RodDia = oRodDia
If HSSsize <> oHSSsize Then HSSsize = oHSSsize
.....
If TopStripEdge <> oTopStripEdge Then TopStripEdge = oTopStripEdge
If HSS2MidStiff <> oHSS2MidStiff Then HSS2MidStiff = oHSS2MidStiff

RuleParametersOutput()
InventorVb.DocumentUpdate()

 

 

Can you try an alternative way deleting constraints in a for each loop?

 

If FSV.Constraints.Count Then
	For Each oObj As Object In FSV.Constraints
		oObj.Delete
	Next
End If

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 5 of 6

llorden4
Collaborator
Collaborator

Thanks for these tips @nmunro, unfortunately both failed to clear the issue.

 

However, thanks for the introduction to Transactions; that's been on my bucket list of things to figure out!

Autodesk Inventor Certified Professional
0 Likes
Message 6 of 6

llorden4
Collaborator
Collaborator

Thanks @Ralf_Krieg, using the Object method was the winning move.

If FSV.Constraints.Count Then										'remove any current constraints
	For Each oObj As Object In FSV.Constraints
		oObj.Delete
	Next
End If

I also took a look at your comments on the Parameter handling, many appear to mimic my comments in my original post.  If tried your suggested path before and have performance/sync issues between iLogic and Parameters (and thus Forms).  A quick separate test I setup yielded some unexpected results, so I need to spend some more time experimenting with handling these with your comments in mind.  Appreciate the tips!

Autodesk Inventor Certified Professional
0 Likes