Cause a Part to "RequireUpdate" without dirtying it

Cause a Part to "RequireUpdate" without dirtying it

DRoam
Mentor Mentor
723 Views
7 Replies
Message 1 of 8

Cause a Part to "RequireUpdate" without dirtying it

DRoam
Mentor
Mentor

I'm writing an add-in that auto-populates some part iProperties. If the user opens a part (or an assembly containing some parts) whose iProperties are out of date, I want it to turn on the "RequiresUpdate" flag for the part(s), so the little lightning bolt symbol lights up, informing the user the part needs to be updated. If they update the part, I'd then like to respond to that event and auto-populate the iProperties (how to do so will be another question, since there doesn't seem to be a "OnUpdate" event... but I'll cross that bridge after I figure this one out).

 

So, I need some way to turn on the "RequiresUpdate" flag for the part. However, I want to do this without dirtying the part, because I don't want my add-in to be modifying a bunch of files immediately upon being opened, causing them to need to be saved even though the user didn't change anything.

 

The only thing I've found that comes close to working is to create a dummy parameter, change its value, and then set the Dirty flag for the document to False. However, I don't like having a dummy parameter in every part my add-in works with. I'd like to find a way to turn on the "RequiresUpdate" flag without needing to change or add anything that the user will see.

 

I'd be happy with any clean solutions or workarounds, as long they don't impact performance or leave things like dummy parameters lying around for the user to see.

 

Thanks in advance for any suggestions!

0 Likes
Accepted solutions (1)
724 Views
7 Replies
Replies (7)
Message 2 of 8

yvandelafontaine
Advocate
Advocate

have you tough about using a shared variable?

something like

SharedVariable("SAVED") = True

 

0 Likes
Message 3 of 8

DRoam
Mentor
Mentor

Hi Yvan, thanks for the suggestion, but I'm not sure how that helps? I guess I could use it to help my add-in know which parts need to be updated or something, but I have other methods for doing that. The tough question in this case is how to make the "Update" button (lightning bolt icon) light up for a Part, indicating that it needs an update. Does you suggestion tie into that somehow?

0 Likes
Message 4 of 8

WCrihfield
Mentor
Mentor

The user wouldn't see an Attribute attached to the Document.  All Inventor documents have AttributeManager.  Perhaps you could use that?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 8

DRoam
Mentor
Mentor

Adding an Attribute doesn't cause the part to require an Update, so it doesn't cause the lightning bolt icon to light up, which is the main objective.

0 Likes
Message 6 of 8

nmunro
Collaborator
Collaborator
Accepted solution

Your approach will work with one tweak. The Parameter object has a hidden "Visible" property that you can use to hide the user parameter from view.

 

Neil

 

        


https://c3mcad.com

Message 7 of 8

DRoam
Mentor
Mentor

@nmunro This is fantastic, I had no idea you could do that! I've actually wanted to hide a parameter before, for other applications, but had no idea it was possible. Thanks for pointing this out! Is there a reference somewhere with hidden API's like this or did you just stumble across it?

 

For anyone interested, here's the code I'm using to essentially "raise" the RequiresUpdate flag, causing the "Update" lightning bolt icon to light up. It works for both parts and assemblies:

 

 

Sub RaiseRequiresUpdateFlag(modelDoc As Document)
	If modelDoc.RequiresUpdate Then Exit Sub

	Dim transacMan As TransactionManager = ThisApplication.TransactionManager

	Dim trans As Transaction = transacMan.StartTransaction(modelDoc, "RaiseRequiresUpdateFlag")

	Try
		Dim wasDirty As Boolean = modelDoc.Dirty

		Dim params As Parameters = modelDoc.ComponentDefinition.Parameters

		Dim param As Inventor.Parameter

		Try
			param = params.Item("RequiresUpdateParam")
		Catch
			param = params.UserParameters.AddByValue("RequiresUpdateParam", 0, "ul")
			param.Visible = False
		End Try

		param.Value += 1 ' <-- This is the line that actually causes the "Update" button to light up.

		modelDoc.Dirty = wasDirty ' <-- This prevents the document from needing to be saved due to raising the RequiresUpdate flag.

		trans.End

		If transacMan.CommittedTransactions.Count > 1 Then trans.MergeWithPrevious = True ' <-- This prevents raising the RequiresUpdate flag from adding an entry in the Undo list.
	Catch ex As Exception
		Try
			trans.Abort
		Catch
		End Try
		Throw ex
	End Try
End Sub

 

 

 

 

0 Likes
Message 8 of 8

nmunro
Collaborator
Collaborator

Good to hear it works for you. There is no Inventor documentation for hidden properties and methods but you can look up information on specific objects.

 

Inventor's VBA environment has an Object Browser (F2 shortcut). You can browse the entire Inventor object model and view information on any object. Right-click in the right side pane and select "Show hidden members" to reveal any hidden properties and methods.

 

In Visual Studio, right-click on an object name (i.e. Parameter) and select Go to definition. Everything about the object is displayed.

 

        


https://c3mcad.com

0 Likes