Hey I have just stumbled across this post but I am having trouble with code, can anybody help?
Imports Inventor.ViewOrientationTypeEnum
Imports Inventor.DrawingViewStyleEnum
Dim oPartDoc As Document
Dim oSheet As Sheet
Dim oTG As TransientGeometry
Dim oView1 As DrawingView
Dim oView2 As DrawingView
Dim oView3 As DrawingView
Dim oView4 As DrawingView
Dim oView5 As DrawingView
Dim oView6 As DrawingView
Dim oViews As DrawingViews
Dim oScale As String
'Ask to create drawing?
AskCreateDrawing=MsgBox("Would you like to Create a drawing for this MODEL?", vbYesNo,"Drawing Selection")
If AskCreateDrawing = vbYes Then
oPartDoc = ThisDoc.Document
'Rotate Model to correct view
Dim oCamera As Camera
oCamera = ThisApplication.ActiveView.Camera
oCamera.ViewOrientationType = 10764 'Front View
oCamera.Apply
'list of view enums:
' kTopViewOrientation = 10754
' kRightViewOrientation = 10755
' kBackViewOrientation = 10756
' kBottomViewOrientation = 10757
' kLeftViewOrientation = 10758
' kIsoTopRightViewOrientation = 10759
' kIsoTopLeftViewOrientation = 10760
' kIsoBottomRightViewOrientation = 10761
' kIsoBottomLeftViewOrientation = 10762
' kFrontViewOrientation = 10764
'Define IDW Template File Location
oDrawingDoc = ThisApplication.Documents.Add(kDrawingDocumentObject, "C:\Users\Public\Documents\Autodesk\Inventor 2015\Templates\Romec A3 Template.idw", True)
oSheet = oDrawingDoc.Sheets.Item(1)
'oScale = InputBox("Enter Desired Scale - AS A DECIMAL", "Set Drawing Scale", "1")
oScale = 1/3
oSheet = oDrawingDoc.ActiveSheet
oViews = oSheet.DrawingViews
For Each oView In oViews
If oView.ScaleFromBase = False Then
oView.ScaleString = oScale
End If
Next
'Centre of Drawing Border
X_Pos = 21
Y_Pos = 12
X_Pos_Left = X_Pos -14
X_Pos_Right = X_Pos +14
Y_Pos_Top = Y_Pos +12
Y_Pos_Bottom = Y_Pos -12
'Define 2d views
oPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(X_Pos, Y_Pos) ' Centre View
oPoint2 = ThisApplication.TransientGeometry.CreatePoint2d(X_Pos, Y_Pos_Bottom) ' Bottom View
oPoint3 = ThisApplication.TransientGeometry.CreatePoint2d(X_Pos_Right, Y_Pos) ' Right Hand View
oPoint4 = ThisApplication.TransientGeometry.CreatePoint2d(X_Pos, Y_Pos_Top) ' Top View
oPoint5 = ThisApplication.TransientGeometry.CreatePoint2d(X_Pos_Left, Y_Pos) ' Left Hand View
oPoint6 = ThisApplication.TransientGeometry.CreatePoint2d(X_Pos_Left, Y_Pos_Top)' Top Left Hand ISO View
'Drawing View Styles
'kHiddenLineDrawingViewStyle *** Hidden Line
'kHiddenLineRemovedDrawingViewStyle *** Hidden Line Removed (For ISO)
'Set Base View
oBaseView = oSheet.DrawingViews.AddBaseView(oPartDoc, oPoint1, oScale,kCurrentViewOrientation, kHiddenLineDrawingViewStyle)
'Dimension
oSheet.DrawingDimensions.GeneralDimensions.Retrieve(oBaseView)
'Set other Projected views
''Bottom View
'oView2 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint2, kHiddenLineDrawingViewStyle, ScaleFromBase)
'' Dims only placed if Top View NOT active
'oSheet.drawingdimensions.generaldimensions.retrieve(oView2)
'Right Hand View
oView3 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint3, kHiddenLineDrawingViewStyle, ScaleFromBase)
' Dims only placed if Left Hand View NOT active
oSheet.DrawingDimensions.GeneralDimensions.Retrieve(oView3)
'Top View
oView4 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint4, kHiddenLineDrawingViewStyle, ScaleFromBase)
oSheet.DrawingDimensions.GeneralDimensions.Retrieve(oView4)
''Left Hand View
'oView5 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint5, kHiddenLineDrawingViewStyle, ScaleFromBase)
'oSheet.drawingdimensions.generaldimensions.retrieve(oView5)
''Top Left Hand ISO View
'oView6 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint6, kHiddenLineRemovedDrawingViewStyle, ScaleFromBase)
''*** NO Dims on this View ***
'**** NEW CODE ****
'Activate The Drawing File
oDrawingDoc.Activate()
Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument
'MsgBox(oDoc.DisplayName)
'
'User request play in YY & YY axis
'Play in relation to the sheet size. It allows space for the Title Block and other notes if needed.
SheetPlayX = 0
SheetPlayY = 0
'
'User Fine Tune - In this you can fine tune some distances.
'Deviation X will move all views to right if positive or to left if negative.
'Deviation Y will move all views up if positive or down if negative. Normally used to move views up when there is a title block in the bottom.
deviation_X = 0
deviation_Y = 0
play_between_views = 0
'
'Define variables
Dim View(0 To 5) As String
Dim CenterX(0 To 5) As Single
Dim CenterY(0 To 5) As Single
Dim ViewHeight(0 To 5) As Single
Dim ViewWidth(0 To 5) As Single
Dim PlayX(0 To 3) As Single
Dim PlayY(0 To 3) As Single
ViewQtX = 0
ViewQtY = 0
'
'Determine the maximum available space in the sheet subtracting the play in x&Y and between views requested by the user.
'SheetWidth = oDoc.sheets.item(1).Width - SheetPlayX - play_between_views
'SheetHeight = oDoc.sheets.item(1).Height - SheetPlayY - play_between_views
SheetWidth = oDoc.ActiveSheet.Width - SheetPlayX - play_between_views
SheetHeight = oDoc.ActiveSheet.Height - SheetPlayY - play_between_views
'Define the name of each view.
'oDoc.sheets.item(1).DrawingViews.Item(1)= "VIEW1"
'oDrawingDoc.sheets.item(1).DrawingViews.Item(2)="VIEW2"
'oDrawingDoc.sheets.item(1).DrawingViews.Item(3)="VIEW3"
'oDrawingDoc.sheets.item(1).DrawingViews.Item("VIEW4")="VIEW4"
'oDrawingDoc.sheets.item(1).DrawingViews.Item("VIEW5")="VIEW5"
'Determines the current scale of the main view (VIEW 1). It only reads the main one because it assumes that all other views are in the same scale.
CurrentScale=oDoc.Sheets.Item(1).DrawingViews.Item(1).Scale
'CurrentScale=oDoc.ActiveSheet.View(View(1)).Scale
' Try to find the width and height of each view in scale 1:1. If not found instead of give an error, makes it equal to zero.
For i=1 To 5
Try
'ViewHeight(i)=oDoc.ActiveSheet.View(View(i)).Height*(1/CurrentScale)
ViewHeight(i)= oDoc.Sheets.Item(1).DrawingViews.Item(i).Height*(1/CurrentScale)
'ViewWidth(i)=oDoc.ActiveSheet.View(View(i)).Width*(1/CurrentScale)
ViewWidth(i)= oDoc.Sheets.Item(1).DrawingViews.Item(i).Width*(1/CurrentScale)
Catch
ViewHeight(i)=0
ViewWidth(i)=0
End Try
Next
'Determines the max width and height that all views occupy in scale 1:1
'MaxWidth = ViewWidth(5) + ViewWidth(1) + ViewWidth(3)
'MaxHeight = ViewHeight(4) + ViewHeight(1) + ViewHeight(2)
MaxWidth = ViewWidth(5) + ViewWidth(1) + ViewWidth(2)
MaxHeight = ViewHeight(4) + ViewHeight(1) + ViewHeight(3)
'MsgBox(MaxWidth)
'MsgBox(MaxHeight)
'Width maximum height/width and maximum sheet size determine what scale is needed to fit in the sheet.
ScaleX = SheetWidth / MaxWidth
ScaleY = SheetHeight / MaxHeight
'MsgBox(SheetWidth)
'MsgBox(SheetHeight)
FinalScale = Min(ScaleY,ScaleX)
MsgBox(FinalScale)
'Apply the final scale to the Main view rounded to the nearest .25
If FinalScale < 1 Then
FinalScale = FinalScale^-1
inc = .25
FinalScale = Round(Round(FinalScale,2) / inc) * inc
'oDoc.ActiveSheet.View(View(1)).ScaleString="1/"&FinalScale
oDoc.Sheets.Item(1).DrawingViews.Item(1).ScaleString="1/"&FinalScale
Else
inc = .25
FinalScale = Round(Round(FinalScale,2) / inc) * inc
'oDoc.ActiveSheet.View(View(1)).Scale=FinalScale
oDoc.Sheets.Item(1).DrawingViews.Item(1).ScaleString=FinalScale
End If
'
''Writes to an custom iPropertie the scale
'iProperties.Value("Custom", "Scale")=ActiveSheet.View(View(1)).ScaleString
'
''Reads the new height and width of each view.
For i=1 To 5
Try
ViewHeight(i)=oDoc.Sheets.Item(1).DrawingViews.Item(i).Height
ViewWidth(i)=oDoc.Sheets.Item(1).DrawingViews.Item(i).Width
Catch
ViewHeight(i)=0
ViewWidth(i)=0
End Try
Next
'
'Determine the new maximum width and height occupied by all views in the current scale.
'MaxWidth = ViewWidth(5) + ViewWidth(1) + ViewWidth(3)
'MaxHeight = ViewHeight(4) + ViewHeight(1) + ViewHeight(2)
MaxWidth = ViewWidth(5) + ViewWidth(1) + ViewWidth(2)
MaxHeight = ViewHeight(4) + ViewHeight(1) + ViewHeight(3)
'Determine how many rows and columns of views there are.
If ViewWidth(5)<>0 Then
NumberViewsX = NumberViewsX+1
End If
If ViewWidth(1)<>0 Then
NumberViewsX = NumberViewsX+1
End If
If ViewWidth(2)<>0 Then
NumberViewsX = NumberViewsX+1
End If
If ViewHeight(4)<>0 Then
NumberViewsY = NumberViewsY+1
End If
If ViewHeight(1)<>0 Then
NumberViewsY = NumberViewsY+1
End If
If ViewHeight(3)<>0 Then
NumberViewsY = NumberViewsY+1
End If
'Width the new views width and height determine the available space in the sheet and divides by the number of views + 1/
'to determine how much play can be left between views. To that play also adds the user requested play_between_views.
PlayX(0) = (oDoc.ActiveSheet.Width - MaxWidth) /(NumberViewsX+1)
PlayY(0) = (oDoc.ActiveSheet.Height - MaxHeight) /(NumberViewsY+1)
If ViewWidth(5)<>0 Then
PlayX(1) = PlayX(0) + play_between_views
End If
If ViewWidth(1)<>0 Then
PlayX(2) = PlayX(0) + play_between_views
End If
If ViewHeight(4)<>0 Then
PlayY(1)=PlayY(0) + play_between_views
End If
If ViewHeight(1)<>0 Then
PlayY(2)=PlayY(0) + play_between_views
End If
'Defines the all views position. By default they are centred and equally spaced, but if the user adds any X/Y/view play it will relocated accordingly.
CenterX(5)= PlayX(0) + deviation_X + ViewWidth(5)/2
CenterX(1)= CenterX(5) + ViewWidth(5)/2 + PlayX(1) + ViewWidth(1)/2
CenterX(2)= CenterX(1) + ViewWidth(1)/2 + PlayX(2) + ViewWidth(2)/2
CenterX(2)= CenterX(1)
CenterX(4)= CenterX(1)
CenterY(2)= PlayY(0) + deviation_Y + ViewHeight(4)/2
CenterY(1)= CenterY(2) + ViewHeight(4)/2 + PlayY(1) + ViewHeight(1)/2
CenterY(4)= CenterY(1) + ViewHeight(1)/2 + PlayY(2) + ViewHeight(3)/2
CenterY(5)=CenterY(1)
CenterY(3)=CenterY(1)
'Apply to all views the new location
For i=1 To 5
Try
'ActiveSheet.View(View(i)).SetCenter(CenterX(i),CenterY(i))
oDoc.Sheets.Item(1).DrawingViews.Item(i).SetCenter(CenterX(i),CenterY(i))
Catch
End Try
Next
'Update Inventor Drawing
InventorVb.DocumentUpdate()
End If
I am getting the error
Error in rule: gkp-Create Drawings, in document: 5000-672-50-00 - Baseframe Assy E.iam
The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.Documents.Add(DocumentTypeEnum DocumentType, String TemplateFileName, Boolean CreateVisible)
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)