Sub Main Errors

Sub Main Errors

randy.redekop
Participant Participant
1,168 Views
5 Replies
Message 1 of 6

Sub Main Errors

randy.redekop
Participant
Participant

Hello all, I'm having a error in the code I'm working on and I cant figure out what the issue is. I think its something easy but I'm very new to using ilogic. Ill attach a screenshot of the error and paste the code below. Any help is appreciated, Thank you

 

 

Sub Main
	Dim sheetNames As New List(Of String)
	sheetNames.Add("MAIN")
	
	Dim sheetSize As DrawingSheetSizeEnum = 9988
	Dim invDoc As DrawingDocument = ThisApplication.ActiveDocument
	Dim oSheet As Sheet = Nothing
	
	For index As Integer = 1 To oSheets.Count
		oSheet = invDoc.Sheets.Add(sheetSize, , sheetNames(index - 1))
		Next
		
		For Each oSheet In invDoc.Sheets
			IfoSheet.Name = "Sheet:1" Then
			oSheet.Delete
		End If
		Next
		For Each oSheet In invDoc.Sheets
			If oSheet.Name = oSheets(0) & ":1" Then
				oSheet.Activate
				
			End If
			Next
		End Sub



Sub Main
	
	
			
Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oSheet As Sheet = oDoc.ActiveSheet

DeleteView(oSheet)

Dim sheetCenterVertical As Double = ((oSheet.Height / 2) -1.5)
Dim baseViewHorizontal As Double = (oSheet.Width * .17)
Dim projViewHorizontal As Double = (oSheet.Width * .4)

Dim modelReference As Document = ThisApplication.Documents.Open(SharedVariable("C:\Users\rredekop\Documents\Inventor\New folder") & "\" & "WE" & ".ipt", False)
Dim oScale As Double = 1

Dim oPoint(2) As Point2d
oPoint(1) = ThisApplication.TransientGeometry.CreatePoint2d(baseViewHorizontal, sheetCenterVertical)

oPoint(2) = ThisApplication.TransientGeometry.CreatePoint2d(projViewHorizontal, sheetCenterVertical)

Dim viewOrientation(2) As ViewOrientationTypeEnum
viewOrientation(1) = 10764
viewOrientation(2) = 10759

Dim viewStyle(2) As DrawingViewStyleEnum
viewStyle(1) = 32258
viewStyle(2) = 32258

Dim oBaseView As DrawingView = Nothing
Dim oProjView As DrawingView = Nothing

For x = 1 To 2
	If i = 1 Then
		oBaseView = oSheet.DrawingViews.AddBaseView(modelReference, oPoint(x), oScale, viewOrientation(x), viewStyle(x))
		oBaseView.Name = "BaseView" & x
		SetViewScale(oSheet, oBaseView)
		
	ElseIf i = 2 Then
		oProjView = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint(x), viewStyle(x))
		oProjView.Name = "ProjView" & x
		
	End If
	Next
	
	
End Sub

	Function DeleteView(oSheet As Sheet)
		For Each view As DrawingView In oSheet.DrawingViews
			View.Delete()
			Next
		End Function
		
	Function SetViewScale(oSheet As Sheet, oView As DrawingView)
	Dim viewScale As Double = Nothing
	Dim trueViewHeight As Double = Nothing
	Dim viewName As String = oView.Name
	Dim viewHeight As Double = Nothing
	
	If Not viewName.Contains("ISO") Then
		
	viewHeight = (oSheet.Height * .6)
	
	Else
		viewHeight = (oSheet.Height * .45)
		
	End If
	
	trueViewHeight = oView.Height
	viewScale = (viewHeight / trueViewHeight)
	oView.Scale = viewScale
End Function


	

 

0 Likes
Accepted solutions (1)
1,169 Views
5 Replies
Replies (5)
Message 2 of 6

vpeuvion
Advocate
Advocate

Hello

Try this.

Sub Main ()
	Dim sheetNames As New List(Of String)
	sheetNames.Add("MAIN")
	
	Dim sheetSize As DrawingSheetSizeEnum = 9988
	Dim invDoc As DrawingDocument = ThisApplication.ActiveDocument
	Dim oSheet As Sheet = Nothing
	
	For index As Integer = 1 To oSheets.Count
		oSheet = invDoc.Sheets.Add(sheetSize, , sheetNames(index - 1))
		Next
		
		For Each oSheet In invDoc.Sheets
			If oSheet.Name = "Sheet:1" Then
			oSheet.Delete
		End If
		Next
		For Each oSheet In invDoc.Sheets
			If oSheet.Name = oSheets(0) & ":1" Then
				oSheet.Activate
				
			End If
			Next
		'End Sub



'Sub Main
	
	
			
Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oSheet As Sheet = oDoc.ActiveSheet

DeleteView(oSheet)

Dim sheetCenterVertical As Double = ((oSheet.Height / 2) -1.5)
Dim baseViewHorizontal As Double = (oSheet.Width * .17)
Dim projViewHorizontal As Double = (oSheet.Width * .4)

Dim modelReference As Document = ThisApplication.Documents.Open(SharedVariable("C:\Users\rredekop\Documents\Inventor\New folder") & "\" & "WE" & ".ipt", False)
Dim oScale As Double = 1

Dim oPoint(2) As Point2d
oPoint(1) = ThisApplication.TransientGeometry.CreatePoint2d(baseViewHorizontal, sheetCenterVertical)

oPoint(2) = ThisApplication.TransientGeometry.CreatePoint2d(projViewHorizontal, sheetCenterVertical)

Dim viewOrientation(2) As ViewOrientationTypeEnum
viewOrientation(1) = 10764
viewOrientation(2) = 10759

Dim viewStyle(2) As DrawingViewStyleEnum
viewStyle(1) = 32258
viewStyle(2) = 32258

Dim oBaseView As DrawingView = Nothing
Dim oProjView As DrawingView = Nothing

For x = 1 To 2
	If i = 1 Then
		oBaseView = oSheet.DrawingViews.AddBaseView(modelReference, oPoint(x), oScale, viewOrientation(x), viewStyle(x))
		oBaseView.Name = "BaseView" & x
		SetViewScale(oSheet, oBaseView)
		
	ElseIf i = 2 Then
		oProjView = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint(x), viewStyle(x))
		oProjView.Name = "ProjView" & x
		
	End If
	Next
	
	
End Sub

	Function DeleteView(oSheet As Sheet)
		For Each view As DrawingView In oSheet.DrawingViews
			View.Delete()
			Next
		End Function
		
	Function SetViewScale(oSheet As Sheet, oView As DrawingView)
	Dim viewScale As Double = Nothing
	Dim trueViewHeight As Double = Nothing
	Dim viewName As String = oView.Name
	Dim viewHeight As Double = Nothing
	
	If Not viewName.Contains("ISO") Then
		
	viewHeight = (oSheet.Height * .6)
	
	Else
		viewHeight = (oSheet.Height * .45)
		
	End If
	
	trueViewHeight = oView.Height
	viewScale = (viewHeight / trueViewHeight)
	oView.Scale = viewScale
End Function

 

Vincent. 

0 Likes
Message 3 of 6

randy.redekop
Participant
Participant

Thank you @vpeuvion. That seemed to have taken care of that but now i am getting a new error. Maybe you could help me with this one too? See screenshot.

0 Likes
Message 4 of 6

vpeuvion
Advocate
Advocate

Hi

oSheet is declared twice and oSheets is not declared.

Apparently this code is a junction of 2 different codes. He must be missing parts.

You can rename the second oSheet and declare oSheets. (Dim oSheets as ...)

I don't think copying pieces of code is the best way to go. The best is to understand what each code does and what needs and adapt it to the use you want to make of it.

Vincent.

2021-12-13_16-56-17.jpg

0 Likes
Message 5 of 6

WCrihfield
Mentor
Mentor

I also see that you are creating two sub routines as functions, but neither of them are set up to return anything.  Functions are for when you want to return something, and Sub's are for simply doing something without returning anything.  So, if I were you, I would change both of those to Sub instead of Function if you don't want them to return anything.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 6

WCrihfield
Mentor
Mentor
Accepted solution

Also, I see that you are using several Array objects within the code.  Array's are zero based, instead of 1 based, which means their first Item is Item(0), not Item(1).  And due to that an array created like 'Dim Objects(2) As Object' actually has 3 slots/items in it (0, 1, & 2).  To create an array of 2 objects, use 1 within the ().  Your code for them may still work though, because your array's are actually created larger than needed and are only using the last 2 out of 3 positions within it by their specific index numbers.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes