Automating Update Model in Drawings

Automating Update Model in Drawings

m_elsabbahyMDT3V
Community Visitor Community Visitor
826 Views
6 Replies
Message 1 of 7

Automating Update Model in Drawings

m_elsabbahyMDT3V
Community Visitor
Community Visitor

Hi all,

I’m trying to create an ilogic external rule in Autodesk Inventor 2024 to automatically update all drawing views in all sheets of an open .idw or .dwg drawing. Specifically, I need to replicate the “Update Model” command you get when right-clicking a drawing view → Update Model.

Here’s what I’ve tried so far:

  • Using Sheet.Update() and DrawingDocument.Update(), but this only updates the sheet graphics/annotations, not the model link.

  • Attempting to call DrawingView.Update() directly, but this property doesn’t exist in the Inventor 2024 API.

  • Calling ControlDefinitions like "DrawingUpdateAll", which caused errors (“Class not registered”).

  • Experimenting with ReferencedDocument.Update(), but that risked corrupting files.

The goal is to loop through all sheets and all views in a drawing, and actually refresh the referenced model data (as if “Update Model” was clicked for each view).

Environment:

  • Autodesk Inventor 2024

  • Windows 10/11

  • Using iLogic external rules (VB.NET style)

Has anyone solved this before or knows the correct API call or workflow to programmatically trigger “Update Model” on all drawing views?
Any code snippets, API references, or guidance would be appreciated!

Thanks in advance.

0 Likes
827 Views
6 Replies
Replies (6)
Message 2 of 7

WCrihfield
Mentor
Mentor

Hi @m_elsabbahyMDT3V.  In iLogic rules, we have a convenient tool that is unique to iLogic, which gives us access to 'the model' document (ThisDoc.ModelDocument).  The term 'ThisDoc' is a 'Rule Object' which represents an 'ICadDoc' object.  I use that term in most of my iLogic rules, instead of using the 'ThisApplication.ActiveDocument' property, because it is far more dynamically useful & appropriate in more situations.

Anyways, we could simply try something like this:

ThisDoc.ModelDocument.Update

...but I usually like to avoid potential errors (such as no model yet), and be a bit more thorough, so I just quickly typed-up the example code below.  Sometimes updating a drawing has to be done in multiple steps.  Like when you update the drawing, then it tells you the model needs to be updated.  Then you update the model.  Then it tells you the drawing needs to be updated again, so you do that, then sometimes one or more views take a little while to update, and become 'raster' few seconds then back to accurate.  Doing a deep update on the model is usually a first step, when a code process is going between model and drawing, making changes to both.

The example below first gets the drawing.  Then gets 'the model'.  Then updates the model.  Then updates the drawing.  Then iterates through each sheet, simulating the process of replacing the model reference in each view, with the same model, just to force an update, just in case the previous step didn't get the job done.  Then it updates the sheet.

Dim oDDoc As DrawingDocument = TryCast(ThisDoc.Document, DrawingDocument)
If oDDoc Is Nothing Then Return
Dim oMDoc As Inventor.Document = ThisDoc.ModelDocument
If oMDoc Is Nothing Then Return
'oMDoc.Rebuild2(True)
oMDoc.Update2(True)
oDDoc.Update2(True)
For Each oSheet As Inventor.Sheet In oDDoc.Sheets
	For Each oDView As DrawingView In oSheet.DrawingViews
		Dim oRFD As FileDescriptor = oDView.ReferencedDocumentDescriptor.ReferencedFileDescriptor
		oRFD.ReplaceReference(oRFD.FullFileName)
	Next 'oDView
	oSheet.Update()
Next 'oSheet

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 7

martinxw
Enthusiast
Enthusiast

Not working.

 

open model doc, open drawing doc.

 

 modelDoc.Update2(true);
 drwDocument.Update2(true);
sheet.Activate();

foreach (DrawingView drawingView in sheet.DrawingViews)
{
    var rfd = drawingView.ReferencedDocumentDescriptor.ReferencedFileDescriptor;
    rfd.ReplaceReference(rfd.FullFileName);
}
                            
sheet.Update();

 

And still model is not updated. 

martinxw_0-1777877869149.png

 

So I was searching longer and right code is

 

sheet.Activate();

foreach (DrawingView drawingView in sheet.DrawingViews)
{
    var rfd = (Document)drawingView.ReferencedDocumentDescriptor.ReferencedDocument;
    rfd.Update2(true);
}
                            
sheet.Update();

 

Message 4 of 7

WCrihfield
Mentor
Mentor

Hi  .  Thanks for your input & feedback.  There are certainly multiple ways to do updates in drawings.  A process that meets the needs of some just fine may not not meet the needs of all others.  For many, their drawing files will only directly reference one model file, on purpose, because that's just the way they do things where they work.  This is the case where I work also.  Each part file and each assembly file has its own drawing file that only focusses on its own unique features/details, not features or details of any sub components, because each sub component has its own drawing.  When doing things that way, the updates are simpler and require less code.  Some folks incorporate all component details into their assembly drawings, with one component per sheet/page, requiring more updates & more code.  Some may include views that directly reference multiple different model files on each sheet, which is the most complex scenario, requiring the most updates, code, & most processing per drawing.  However, I believe a referenced model document should only need to be updated once in most situations, so if a drawing directly references multiple different model files, it may be more efficient to use a block of code that directly iterates through all of the drawing's referenced documents first, updating them.  Doing that may eliminate the need to iterate through each view on each sheet, extract its model, then update it, with some models potentially getting updated multiple times.  But there is no right or wrong way of doing things, as long as it works.

 

Below is a list of just a few (among many) 'command names' (names of ControlDefinition objects) that can be used for updating stuff.  But those are ones that get executed during manual user interactions, such as when clicking on ribbon buttons and context menu tools, some of which may require some selecting &/or unselecting things for before/after execution, so they work differently than Inventor API methods, and usually only work on the 'active' document (visible on screen & ready for editing), instead of on referenced documents in the background.

AppGlobalUpdateWrapperCmd

AppLocalUpdateCmd

DrawingPartsListUpdateCtxCmd

DrawingTableUpdateCtxCmd

DrawingUpdateAllSheetsCmd

DrawingUpdateComponentCmd

DrawingUpdateViewComponentCmd

LinkFileCheckForUpdatesCtxCmd

UpdateCopiedModeliPropertiesCmd

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 7

martinxw
Enthusiast
Enthusiast

You written:

I believe a referenced model document should only need to be updated once in most situations.

 

It is not true when you use "Model States".

 

I have a drawing file, where one model file is referenced.

But drawing file has 10 sheets.

Every single sheet has one view of model state (model hase 10 model states).

 

So in foreach cycle must activate every sheet and update model (referenced document) as I've written above.

 

I tested it and it worked.

 

Your method didn't work with model states.

 

0 Likes
Message 6 of 7

WCrihfield
Mentor
Mentor

There must have been some misunderstanding.  I meant no disrespect about anything.  In fact I did thank you, because what you posted is helpful.  I sincerely apologize if my reply insinuated in any way that there was anything wrong with anything you posted or that it would not work for your situation.  It clearly does work for you or you would not have posted it here.  You were clearly trying to help others by posting another working code example here that goes another step further to ensure all documents get updated in a more complex situation than the one originally posted here, which I do respect and find admirable.  I did not claim that my original code was in any way superior to yours, or that it would handle 'all possible scenarios'.  You mentioned in your last post that your drawings often contained multiple views of the same model file where they are set to different ModelState versions of the model.  That is also helpful information, and helps explain the need for additional step or actions to get everything updated properly.  I am aware that my earlier code example will not work properly in that type of situation.  My code example did seem to work OK for the original poster's unique situation, and it seemed to work OK for many of my own drawing updating needs.  This is why I mentioned that there are multiple ways of doing things that will work, but different tactics may be needed for different situations.  I used the word 'most' in the line you quoted instead of 'all', because I know about some even more complex scenarios where there may be multiple layers/levels of 'derived' processes involved, where one part may be derived into another part, which may be derived into yet another part, which is then put into an assembly as a component occurrence, and sometimes those types of situations need extra steps to ensure they are fully updated.

 

When we have a drawing open, and that drawing only contains views of a single single model, but has multiple views of it where some of its views are set to a different ModelState member versions of that one model file, there will 'usually' (may be not always) be multiple 'referenced documents' also.  Sometimes (again, maybe not always) as many as one for each ModelState member being represented by the drawing's views.  So one model 'File', but multiple model 'Document' objects.  In cases like that, when we iterate through that drawing's directly referenced documents (DrawingDocument.ReferencedDocuments), the FullFileName of each one will be the same, but their FullDocumentName will (usually) be different, because FullDocumentName starts with the FullFileName value, then is immediately followed by the ModelState member name within '<' & '> brackets.  If one of the views was set to the 'Master' or '[Primary]' ModelState, or the model file does not have any ModelStates, or the model file only has its one original ModelState, then the FullFileName & FullDocumetName may be exactly the same, and there may be fewer referenced documents.  I also just 'assumed' (without local testing at that moment) that iterating through the DrawingDocument.AllReferecedDocuments collection to update the documents might have been sufficient, and slightly more efficient, but I could certainly be wrong, due to the way ModelState 'member' documents get 'generated / updated'.  In Inventor 2022 through 2026, there was no UI button or API method/property for 'generate ModelState member document', so when we first create a ModelState (either manually or by code) it does not automatically generate a ModelState member document for it.  There are a few actions that will automatically generate a ModelState member document though, such as when we create a ComponentOccurrence for one within an assembly, create a DrawingView for one in a drawing, create a DerivedPart from one,  or DerivedAssembly from one, etc..  This may mean that Inventor may require that the sheet the drawing view is on be active when doing those types of updates, just like you are doing in your working code example above.  And that may invalidate my idea of iterating through all referenced documents to do the updates.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 7 of 7

J-Camper
Advisor
Advisor

I extracted this snippet from one of my drawing commands which performs a full model reference update as part of the script.  I loop through document descriptors instead of individual views because we often have multiple views of the same model in our drawings.

Dim dDoc As DrawingDocument = TryCast(ThisApplication.ActiveDocument, DrawingDocument)
If dDoc Is Nothing Then Logger.Debug("Not Run In Drawing Document") : Exit Sub

For Each refDocDesc As DocumentDescriptor In dDoc.ReferencedDocumentDescriptors
	Dim refDoc As Document = refDocDesc.ReferencedDocument
	If refDoc.RequiresUpdate = True Then refDoc.Update2(True) 
Next

dDoc.Update2(True)

 

0 Likes