Using ilogic to check scales are the same on a sheet.

Using ilogic to check scales are the same on a sheet.

matthew.johnson200
Enthusiast Enthusiast
1,071 Views
8 Replies
Message 1 of 9

Using ilogic to check scales are the same on a sheet.

matthew.johnson200
Enthusiast
Enthusiast

As we use a laser cutter to produce our parts, its important that all the parts on each sheet are at the same scale. I have been trying to come up with a code which checks all the views against the first view and flags up an error message if there are any parts different. I had a code working fine, but it only checked all scales against the first part scale on the first sheet. As some of our drawings have multiple sheets, with different scales per sheet, i would like it to check each view against the view on the sheet it is on. e.g. sheet 1 should be all be at 1:1, sheet 2 should all be at 1:2. One problem is that the amount of sheets may vary, and also the names are not set, so i cant specify each sheet in the code specifically.

 

So far i have this, but it doesn't seem to work. 

 

Any help will be greatly appreciated.

 

Dim oDrawDoc As DrawingDocument = ThisDrawing.Document
Dim oSheet As Sheet
Dim oSheets As Sheets
Dim oView As DrawingView
Dim oViews As DrawingViews
Dim oScale As Double
Dim oFView As String

oSheets = oDrawDoc.Sheets
oViews = oSheet.DrawingViews
For Each oSheet In oSheets
oFView = oDrawDoc.oSheet.DrawingViews(1).Name 'adds the NAME of the first view in sheet to oFView
oScale = oSheet.View(oFView).Scale 'sets the SCALE of the first view to OScale
For Each oView In oViews
If (oView.Scale = oScale) = False Then
MessageBox.Show("Some drawing views are not the same scale", "Check Scales")
End If
Next
Next

 

0 Likes
Accepted solutions (1)
1,072 Views
8 Replies
Replies (8)
Message 2 of 9

Thomas_Savage
Advisor
Advisor

Hello @matthew.johnson200,

 

I have asked for this to be moved to Inventor Customization. This part of the forum is for iLogic.

 

You will get the help you need here.

 

Thomas.



Thomas Savage

Design Engineer


0 Likes
Message 3 of 9

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @matthew.johnson200

 

Welcome to the forums.

 

As mentioned the Inventor Customization forum is the best place for programming questions of this type in the future:
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120

 

Nonetheless, here is a quick example of your rule that might work for you though.

 

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

 

Dim oDrawDoc As DrawingDocument 
Dim oSheet As Sheet
Dim oCurrentSheet As Sheet
Dim oSheets As Sheets
Dim oView As DrawingView
Dim oViews As DrawingViews
Dim oScale As Double
Dim oFView As String

'get the current drawing
oDrawDoc = ThisDoc.Document
'get the active sheet
oCurrentSheet = oDrawDoc.ActiveSheet
'get the sheets collection
oSheets = oDrawDoc.Sheets
'look at each sheet
For Each oSheet In oSheets
	oFlag = True 'set flag to default value 
	oSheet.Activate 'activate the sheet
	oViews = oSheet.DrawingViews 'get the views collection
	oFView = oSheet.DrawingViews(1).Name 'adds the NAME of the first view in sheet to oFView
	oScale = ActiveSheet.View(oFView).Scale 'sets the SCALE of the first view to OScale
	'look at each view
	For Each oView In oViews
		'compare view scale to 1st view scale
		If oView.Scale <> oScale Then
			oFlag = False 'trip the flag
		End If
	Next
	'alert user if flag is tripped (indicating differing scales)
	If oFlag = False Then	
		MessageBox.Show("Some drawing views on " & _
		oSheet.Name & " are not the same scale", "Check Scales")
	End If
Next

'set original sheet as active
oCurrentSheet.Activate

EESignature

Message 4 of 9

mcgyvr
Consultant
Consultant

@Anonymous wrote:

the view on the sheet it is on. e.g. sheet 1 should be all be at 1:1, sheet 2 should all be at 1:2.

 


 

The code you posted and what Curtis posted (based off what you tried to do in your posted code) does not check to see if sheet 1 view scale is 1:1 and sheet 2 is 1:2,etc.. 

Isn't that really what you want instead of just checking to see if whatever the first view scale is matches what the rest of the views on that sheet are.. 

 

If sheet 1 first view scale is 1:2 it will not error out..

 

 

 



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
Message 5 of 9

matthew.johnson200
Enthusiast
Enthusiast

I may have confused things with my example. I want everything to be scaled off the first view, whatever scale that view might be. So the code works as intended.

0 Likes
Message 6 of 9

Curtis_Waguespack
Consultant
Consultant

Just in case someone needs all views on all sheets to be compared to the first view on the first sheet, here is an example for that.

 

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

 

 

Dim oDrawDoc As DrawingDocument 
Dim oSheet As Sheet
Dim oCurrentSheet As Sheet
Dim oSheets As Sheets
Dim oView As DrawingView
Dim oViews As DrawingViews
Dim oScale As Double
Dim oFView As String

'get the current drawing
oDrawDoc = ThisDoc.Document
'get the sheets collection
oSheets = oDrawDoc.Sheets
'get the active sheet
oCurrentSheet = oDrawDoc.ActiveSheet
'get first view / first sheet scale
oScale = oCurrentSheet.DrawingViews(1).Scale

'look at each sheet
For Each oSheet In oSheets
	oFlag = True 'set flag to default value 
	oSheet.Activate 'activate the sheet
	oViews = oSheet.DrawingViews 'get the views collection
	'look at each view
	For Each oView In oViews
		'compare view scale to 1st view scale
		If oView.Scale <> oScale Then
			oFlag = False 'trip the flag
		End If
	Next
	'alert user if flag is tripped (indicating differing scales)
	If oFlag = False Then	
		MessageBox.Show("Some drawing views on " & _
		oSheet.Name & " are not the same scale " & _
		"as the first view on the first sheet", "Check Scales")
	End If
Next

'set original sheet as active
oCurrentSheet.Activate

EESignature

Message 7 of 9

matthew.johnson200
Enthusiast
Enthusiast

Thanks for the code, works a treat! 

The only thing i noticed was that if you try and save the drawing when it is a blank, it throws up an error, so i added an 'on error resume next', and that seems to solve the problem.

 

Dim oDrawDoc As DrawingDocument 
Dim oSheet As Sheet
Dim oCurrentSheet As Sheet
Dim oSheets As Sheets
Dim oView As DrawingView
Dim oViews As DrawingViews
Dim oScale As Double
Dim oFView As String

On Error Resume Next
'get the current drawing
oDrawDoc = ThisDoc.Document
'get the active sheet
oCurrentSheet = oDrawDoc.ActiveSheet
'get the sheets collection
oSheets = oDrawDoc.Sheets
'look at each sheet
For Each oSheet In oSheets
	oFlag = True 'set flag to default value 
	oSheet.Activate 'activate the sheet
	oViews = oSheet.DrawingViews 'get the views collection
	oFView = oSheet.DrawingViews(1).Name 'adds the NAME of the first view in sheet to oFView
	oScale = ActiveSheet.View(oFView).Scale 'sets the SCALE of the first view to OScale
	'look at each view
	For Each oView In oViews
		'compare view scale to 1st view scale
		If oView.Scale <> oScale Then
			oFlag = False 'trip the flag
		End If
	Next
	'alert user if flag is tripped (indicating differing scales)
	If oFlag = False Then	
		MessageBox.Show("Some drawing views on " & _
		oSheet.Name & " are not the same scale", "Check Scales")
	End If
Next

'set original sheet as active
oCurrentSheet.Activate

 

 

0 Likes
Message 8 of 9

Curtis_Waguespack
Consultant
Consultant

Hi @matthew.johnson200.

 

Glad that helped.

 

Just a quick aside, to note that the 'On Error Resume Next' line is often used (and abused) in the way that you've used it here. I do the same from time to time still, but did it much more in the past before I understood the problems it can create.

 

Long story short, using it just to by pass an error can hide errors that makes trouble shooting impossible. So just beware of that, and note that if a rule isn't working and has an 'On Error Resume Next' line you probably want to temporarily comment it out as you troubleshoot.  (you can google about this to get the long version of how to properly use this line to trap errors/ rather than by pass them).

 

Anyway, I still use the resume line from time to time in simple rules like this, but just beware that it can hide errors and make you think the rule is working when it is not.

 

For this specific case, note that you can count the views collection and exit out of the rule if it is less than 1.

 

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

 

 

 

Dim oDrawDoc As DrawingDocument 
Dim oSheet As Sheet
Dim oCurrentSheet As Sheet
Dim oSheets As Sheets
Dim oView As DrawingView
Dim oViews As DrawingViews
Dim oScale As Double
Dim oFView As String

'get the current drawing
oDrawDoc = ThisDoc.Document
'get the active sheet
oCurrentSheet = oDrawDoc.ActiveSheet
'get view count
oCount = oCurrentSheet.DrawingViews.Count
If oCOunt < 1 Then
	Return 'exit rule
End If

'.... rest of rule here

 

EESignature

Message 9 of 9

matthew.johnson200
Enthusiast
Enthusiast

Sorry to bother you again, but could you post the entire code as i'm unsure as to exactly where to that check for 0 views.

 

Thanks!

0 Likes