Updating a View/Model from a Drawing with iLogic

Updating a View/Model from a Drawing with iLogic

chris.johnstoneQP8NN
Participant Participant
3,788 Views
12 Replies
Message 1 of 13

Updating a View/Model from a Drawing with iLogic

chris.johnstoneQP8NN
Participant
Participant

Hi guys, I trying to figure out how to update a View (Model file) within a drawing while running some iLogic code.

 

The iLogic code I'm running, inside the drawing, changes some parameter sizes in the referenced model. However, these changes do not update the drawing view. I have tried things like:

 

iLogicVb.UpdateWhenDone = True

and 

InventorVb.DocumentUpdate()

 However, this only works if the drawing as a whole needs updated (as far as my understanding goes).

 

Right clicking on the View and updating is the only way I can get it to work but as I want the whole process to be automated, obviously this is no use. Any ideas?

 

Thanks in advance!

0 Likes
Accepted solutions (2)
3,789 Views
12 Replies
Replies (12)
Message 2 of 13

JhoelForshav
Mentor
Mentor

Hi @chris.johnstoneQP8NN 

I just did some testing and what worked for me was to first update the actual referenced document. I'm sure you have it stored in a variable in the code since you're updating its parameters. Say you call it oDoc. Then just add the line:

oDoc.Update

Then after that line, update the sheet the view is on (the views parent).

If you dont have it stored in a variable you can call:

oView.Parent.Update

 

Hope this helps 🙂

Message 3 of 13

chris.johnstoneQP8NN
Participant
Participant

Thanks for the quick reply @JhoelForshav! I have inserted what you said and I'm getting this error message. Any ideas?

0 Likes
Message 4 of 13

JhoelForshav
Mentor
Mentor

@chris.johnstoneQP8NN 

I see.. You're using an iLogic snippet to get the view so it's not an object of type DrawingView... You could probably get the DrawingView object from that though. Could you share your code? 🙂

0 Likes
Message 5 of 13

chris.johnstoneQP8NN
Participant
Participant
Dim oDoc As DrawingDocument
oDoc = ThisDoc.Document 

Dim oView As DrawingView
oView = ActiveSheet.View("VIEW1")   

oDoc.Update
oView.Parent.Update

 This is just a bi of test code I'm trying to get to work but this is coming up with an error. I appreciate your help @JhoelForshav!

0 Likes
Message 6 of 13

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @chris.johnstoneQP8NN 

What needs to be updated is the model document (not drawing document) and the sheet.

I hope this makes sense to you.

 

'Dont really need the drawing document for this
'Dim oDoc As DrawingDocument
'oDoc = ThisDoc.Document 

Dim oView As DrawingView
oView = ActiveSheet.View("VIEW1").View 'Add .View to get the DrawingView object.   
Dim oModelDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument 'Get the model document
'---------------------------------------------------
'Do whatever you do to change model parameters here
'---------------------------------------------------

oModelDoc.Update 'Upodate model document
oView.Parent.Update 'Update the sheet
Message 7 of 13

chris.johnstoneQP8NN
Participant
Participant

Thanks @JhoelForshav that's the one. I appreciate your help

0 Likes
Message 8 of 13

roberto_infanti
Contributor
Contributor

I have N View with non-consecutive names (View1,View2,View34,.....). How could I do the update to all views? Thanks

0 Likes
Message 9 of 13

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @roberto_infanti,

 

Here is a quick example that looks at all the sheets, and all the views and updates the model document and view.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

Dim oDoc As DrawingDocument
oDoc = ThisDoc.Document

Dim oSheets As Sheets
oSheets = oDoc.Sheets

Dim oSheet As Sheet
Dim oViews As DrawingViews
Dim oView As DrawingView
Dim oModelDoc As Document

For Each oSheet In oSheets
	oSheet.activate
	oViews = oSheet.DrawingViews
	For Each oView In oViews
		oModelDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument
		oModelDoc.Update
		'Update the sheet
		oView.Parent.Update
	Next
Next

 

 

EESignature

Message 10 of 13

roberto_infanti
Contributor
Contributor

Thanks!!!!!!!

0 Likes
Message 11 of 13

igorbenz
Explorer
Explorer
Hi Curtis, thank you very much for the help. May be I an not lucky but this rule do not updated all views, just some of them. Can you help me with update this rule please?
0 Likes
Message 12 of 13

igorbenz
Explorer
Explorer

It will be updated when I highlight views and push "Update" button in the left corner:

igorbenz_0-1703022817416.png

 

0 Likes
Message 13 of 13

igorbenz
Explorer
Explorer

Like this:

igorbenz_0-1703023398530.png

 

0 Likes