Modifying View Justification

Modifying View Justification

tobias
Collaborator Collaborator
372 Views
4 Replies
Message 1 of 5

Modifying View Justification

tobias
Collaborator
Collaborator

Hi,

 

I have a rule for modifying the View Justification on all open drawings.

 

Sub main
	Dim oInvApp As Inventor.Application = ThisApplication
	For i As Integer = 1 To oInvApp.Documents.Count
		Dim oDoc As Document = oInvApp.Documents(i)
		If System.IO.Path.GetExtension(oDoc.FullFileName) <> ".idw" Then Continue For
		For Each oSheet In oDoc.Sheets
			For Each oView In oSheet.DrawingViews
				oView.ViewJustification = kCenteredViewJustification
			Next
		Next
	Next i
End Sub

 

But I get the following error message:

 

tobias_0-1696578022587.png

 

It worked on a couple of drawings but not onanother set of drawings. 

The difference between those sets is: the first set of drawings had no details or cross section.

 

Does anyone know what is missing ? 

 

 

 

 

Tobias
The Netherlands
Inventor Pro 2026, Vault Pro 2026, AutoCad Electrical 2026.

If a response answers your question, please use ACCEPT SOLUTION to assist other users later.
0 Likes
Accepted solutions (1)
373 Views
4 Replies
Replies (4)
Message 2 of 5

tobias
Collaborator
Collaborator

To add to the error:

 

The rule is giving an error if there are (projected) views which are depended of the base view.

Therefore the View Justification is greyed out and the rule cannot change the View Justification.

 

So I need a line which telles the rule to skipp the greyed out View Justification.

 

 

 

Tobias
The Netherlands
Inventor Pro 2026, Vault Pro 2026, AutoCad Electrical 2026.

If a response answers your question, please use ACCEPT SOLUTION to assist other users later.
0 Likes
Message 3 of 5

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

You can use the Try - Catch operator. This operator will free you from potential errors.

 

Sub main
	Dim oInvApp As Inventor.Application = ThisApplication
	For i As Integer = 1 To oInvApp.Documents.Count
		Dim oDoc As Document = oInvApp.Documents(i)
		If System.IO.Path.GetExtension(oDoc.FullFileName) <> ".idw" Then Continue For
		For Each oSheet In oDoc.Sheets
			For Each oView In oSheet.DrawingViews
				Try : oView.ViewJustification = kCenteredViewJustification : Catch : End Try
			Next
		Next
	Next i
End Sub

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

Message 4 of 5

tobias
Collaborator
Collaborator

The error is gone but Inventor doesn't like it so much:

 

tobias_0-1696591783923.png

 

3 times I tried.

(Also empty Temp folder, restart PC)

Tobias
The Netherlands
Inventor Pro 2026, Vault Pro 2026, AutoCad Electrical 2026.

If a response answers your question, please use ACCEPT SOLUTION to assist other users later.
0 Likes
Message 5 of 5

tobias
Collaborator
Collaborator

I tested the rule on a set of drawings and only one drawing caused Inventor to crash.

Tested on another set without issues.

 

Rule works perfect. Thanks a lot!

 

Tobias
The Netherlands
Inventor Pro 2026, Vault Pro 2026, AutoCad Electrical 2026.

If a response answers your question, please use ACCEPT SOLUTION to assist other users later.