iLogic auto create scaled drawing from a model

iLogic auto create scaled drawing from a model

Anonymous
Not applicable
7,505 Views
10 Replies
Message 1 of 11

iLogic auto create scaled drawing from a model

Anonymous
Not applicable

I have a model which is either a single part or an assembly.

I want to create a drawing and auto scale the views to fit the sheet.

Add dimensions

Save drawing into a seperate folder from the model, but within the same project location

 

Any help would be appreciated, I have limited knowledge of iLogic and none of VBA

 

Thanks

Mal

0 Likes
Accepted solutions (1)
7,506 Views
10 Replies
Replies (10)
Message 2 of 11

Anonymous
Not applicable

Is the layout always the same for each drawing? i.e. elevation, plan, side elevation, isometric

 

This post has a nice iLogic rule that scales and positions drawing views:

https://forums.autodesk.com/t5/inventor-forum/automatic-scale-and-view-position/td-p/5784680

 

As for creating the drawing, it really depends on how much you want to do with it. This post shows how you can use iLogic to create fully dimensioned drawings of every part in an assembly:

https://forums.autodesk.com/t5/inventor-customization/ilogic-coding-to-create-automated-drawing/td-p...

 

I would recommend starting with a rule that you can run from a part/assembly which:

  1. Creates a new drawing document
  2. Places the required views of the part/assembly
  3. Scales and positions the views
  4. Saves the document to specified destination

I have attached a code that I use as an external rule for creating a drawing from a part/assembly file. I have purposely not placed the base view however, but instead execute the Drawing Base View command, for the user to then define the position, scale etc. You could edit this though to pre-define these options and have it automated.

 

Have a play around with this code, let me know how you get on and we can develop it further to suit your needs.

0 Likes
Message 3 of 11

Anonymous
Not applicable
I do have some code which creates the drawing. Puts the views onto the screen into the required positions. I've also included a message box to manually set the scale (although this has to be added as a decimal) But I would like the scale to be decided on the size of the parts and the views shown. I must admit that all I've done is adapt others' code that I've found on various sites around the web. - Using Inventor 2016 & Vault Basic 2016
0 Likes
Message 4 of 11

Anonymous
Not applicable

The first link should have what you need in it, as long as the layout is the same each time.

0 Likes
Message 5 of 11

Anonymous
Not applicable

Thanks for the information.

I've previously tried both of the links you suggested.

The first will only run in an already created drawing.

The second will run, but then errors out.

 

I've tried adapting sections from both of those but get an error

 

I've tried the code you attached, which works fine until I put the base view down then again error's out.

 

Find attached my code, if you can see where I'm going wrong.

 

Thanks

 

 

Message 6 of 11

Anonymous
Not applicable

Sorry here's the latest code. - Auto Cad Drawing 4

 

0 Likes
Message 7 of 11

Anonymous
Not applicable

Can you send an example part file so I get a better idea of what the results will be.

0 Likes
Message 8 of 11

Anonymous
Not applicable
Accepted solution

I modified the code so that the drawing scale section of code works from the part/assembly file. I'm not sure what layout you want or how many views you will have so you'll need to play about with this part of the code to suit your needs:

 

MaxWidth = ViewWidth(5) + ViewWidth(1) + ViewWidth(2)
MaxHeight = ViewHeight(4) + ViewHeight(1) + ViewHeight(3)

 

Another option could be to place the original drawing scale rule in your drawing template, then at the end of this rule ( the one that creates the drawing), use the Run other rule command to call the scale rule that's in the drawing.

Message 9 of 11

GKPByDesign
Advocate
Advocate

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)

 

0 Likes
Message 10 of 11

Bharath_Kumaar
Explorer
Explorer

hi i try to use code. but it gave me error. I couldnt figure out where should i modify

 

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)

0 Likes
Message 11 of 11

philippe.huybrechts9GYX5
Observer
Observer

i get the same error on the code:

De parameter is onjuist. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

 

On wich line(s) does this come from in the code?

 

0 Likes