Hi again,
So i checked out topics that you linked and i found code that creates a drawning from a part and places views exacly how i want them to be placed.
I had to change some numbers and path of the template but after some try and error i got the code working.
Code is from this topic: https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/automaticly-create-a-drawing-from-a-...
And i think its WCrihfield's code.
One thing is that i always got an error when trying long parts ( longer exacly than 1312 mm) when i was using measure instead of rangebox, but after i changed it to use rangebox then it started working properly.
Here is the code with changes:
Dim oPDoc As PartDocument = ThisApplication.ActiveDocument
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
If System.IO.File.Exists(ThisDoc.PathAndFileName(False) & ".idw") Then
oOverWrite = MsgBox("A Drawing for this model already exists." & vbNewLine &
"Do you want to over-write it?", vbYesNo + vbQuestion, "DRAWING EXISTS!")
If oOverWrite = vbNo Then
Return
End If
End If
'The following line sends a full file name to Inventor's Clipboard, this can be used to automatically
'fill in a dialog that would normally pop-up asking for what model you want to place into your drawing.
'ThisApplication.CommandManager.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent,oFileName)
Dim oTPath As String = "C:\Users\Public\Documents\Autodesk\Inventor 2022\Templates\pl-PL"
Dim oTName As String = "Standard.idw"
Dim oDDoc As DrawingDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, oTPath & "\" & oTName, True)
'oDDoc.SheetFormats.Item(1)
'Using Measure (instead of RangeBox)
'Dim oXDim As Long = Measure.ExtentsLength
'Dim oYDim As Long = Measure.ExtentsWidth
'Dim oZDim As Long = Measure.ExtentsHeight
''Using RangeBox for size
Dim oRangeBox As Box = oPDef.RangeBox
Dim oXDim As Long = (oRangeBox.MaxPoint.X - oRangeBox.MinPoint.X)
Dim oYDim As Long = (oRangeBox.MaxPoint.Y - oRangeBox.MinPoint.Y)
Dim oZDim As Long = (oRangeBox.MaxPoint.Z - oRangeBox.MinPoint.Z)
'MsgBox("RangeBox Size of Model = " & vbNewLine &
'oXDim & " along X Axis" & vbNewLine &
'oYDim & " along Y Axis" & vbNewLine &
'oZDim & " along Z Axis")
Dim oModelWidth As Long = MaxOfMany(oXDim, oYDim, oZDim)
Dim oModelHeight As Long = MinOfMany(oXDim, oYDim, oZDim)
'MsgBox("Longest Dim = " & oModelWidth & vbCrLf &
'"This will be used to calculate scale & view width in drawing.")
Dim oViewRotation As Double
Dim oViewOrientation As ViewOrientationTypeEnum
If oModelWidth = oXDim And oModelHeight = oYDim Then
oViewOrientation = ViewOrientationTypeEnum.kFrontViewOrientation
oViewRotation = 0
ElseIf oModelWidth = oXDim And oModelHeight = oZDim Then
oViewOrientation = ViewOrientationTypeEnum.kTopViewOrientation
oViewRotation = 0
ElseIf oModelWidth = oYDim And oModelHeight = oXDim Then
oViewOrientation = ViewOrientationTypeEnum.kFrontViewOrientation
oViewRotation = (PI/2)
ElseIf oModelWidth = oYDim And oModelHeight = oZDim Then
oViewOrientation = ViewOrientationTypeEnum.kRightViewOrientation
oViewRotation = (PI/2)
ElseIf oModelWidth = oZDim And oModelHeight = oXDim Then
oViewOrientation = ViewOrientationTypeEnum.kTopViewOrientation
oViewRotation = (PI/2)
ElseIf oModelWidth = oZDim And oModelHeight = oYDim Then
oViewOrientation = ViewOrientationTypeEnum.kRightViewOrientation
oViewRotation = 0
End If
'Get the size of the Active Sheet
Dim oSheetWidth As Double = oDDoc.ActiveSheet.Width
Dim oSheetHeight As Double = oDDoc.ActiveSheet.Height
'Get size of area within border available for views (used for scaling views)
Dim oSideBorderOffset As Double = 5
Dim oTopBottomBorderOffset As Double = 0.5
Dim oTitleBlockHeight As Double = 2.5
Dim oBorderWidth As Double = oSheetWidth-(oSideBorderOffset*2)
Dim oBorderHeight As Double = oSheetHeight - (oTopBottomBorderOffset * 2)
Dim oAreaAboveTitleBlock As Double = (oBorderHeight - oTopBottomBorderOffset) - oTitleBlockHeight
'Set view scale, based on model width
Dim oBViewScale As Double
If oModelWidth > (oBorderWidth/2) Then
oBViewScale = ((oBorderWidth/2) / oModelWidth)
ElseIf oModelWidth < (oBorderWidth/2) Then
oBViewScale = (oModelWidth / (oBorderWidth/2))
End If
inc = 1/32
oBViewScale = Round(Round(oBViewScale,5) / inc) * inc
'Try creating & placing each view at 1:1 scale, then scale to needed factor.
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oViews As DrawingViews = oDDoc.ActiveSheet.DrawingViews
Dim oFullScale As Double = 1
Dim oOriginPoint As Point2d = oTG.CreatePoint2d(0, 0)
Dim oBaseView As DrawingView = oViews.AddBaseView(oPDoc, oOriginPoint, oFullScale, _
oViewOrientation, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle)
'Locations of view centerpoint columns & rows
Dim o1stColumn As Double = oSideBorderOffset + (oBorderWidth / 4)
Dim o2ndColumn As Double = oSideBorderOffset + ((oBorderWidth / 4) * 3)
Dim o1stRow As Double = oTopBottomBorderOffset + oTitleBlockHeight + (oAreaAboveTitleBlock/4)
Dim o2ndRow As Double = oTopBottomBorderOffset + oTitleBlockHeight + ((oAreaAboveTitleBlock/4)*3)
'Base View center point location
Dim oBaseViewLocation As Point2d = oTG.CreatePoint2d(o1stColumn, o1stRow)
'Dim oBaseView As DrawingView = oViews.AddBaseView(oPDoc, oBaseViewLocation, oBViewScale, _
'oViewOrientation, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle)
oBaseView.Rotation = oViewRotation
oBaseView.Position = oBaseViewLocation
oBaseView.Scale = oBViewScale
oBaseView.ScaleString = RoundToFraction(oBViewScale,1/32,RoundingMethod.Round)
'oBaseView.Center = oBaseViewLocation
'oBaseView.RotateByAngle =
oBaseView.IncludeMeshBodies = True
oBaseView.IncludeSurfaceBodies = True
'oBaseView.Top
'oBaseView.Height
'oBaseView.Left
'oBaseView.Width
oBaseView.Name = "BASE VIEW"
InventorVb.DocumentUpdate()
'MsgBox("Center Of View Is At: " & oBaseView.Center.X & " , " & oBaseView.Center.Y)
'MsgBox("oBViewScale = " & oBaseView.ScaleString)
Dim oUpperViewInsPoint As Point2d = oTG.CreatePoint2d(o1stColumn, o2ndRow)
Dim oUpperView As DrawingView = oViews.AddProjectedView(oBaseView, oUpperViewInsPoint, _
DrawingViewStyleEnum.kFromBaseDrawingViewStyle)
oUpperView.Name = "UPPER VIEW"
oUpperView.IncludeMeshBodies = True
oUpperView.IncludeSurfaceBodies = True
Dim oRightViewInsPoint As Point2d = oTG.CreatePoint2d(o2ndColumn, o1stRow)
Dim oRightView As DrawingView = oViews.AddProjectedView(oBaseView, oRightViewInsPoint, _
DrawingViewStyleEnum.kFromBaseDrawingViewStyle)
oRightView.Name = "RIGHT VIEW"
oRightView.IncludeMeshBodies = True
oRightView.IncludeSurfaceBodies = True
'Dim oISOViewInsPoint As Point2d = oTG.CreatePoint2d(o2ndColumn, o2ndRow)
'Dim oISOView As DrawingView = oViews.AddProjectedView(oBaseView, oISOViewInsPoint, _
'DrawingViewStyleEnum.kShadedDrawingViewStyle)
'oISOView.Name = "ISO VIEW"
'oISOView.IncludeMeshBodies = True
'oISOView.IncludeSurfaceBodies = True
Could you give me any tips on how to make it so i can run the code in anassembly and it will execute this code for every part? So that i can just run the rule in an assembly and i will get a drawning file of each part that is in the assembly?
Opening each part and running the code by hand is gonna take a lot of time.
Is there an easy way to achive that?
I have a rule that makes .stp file of every part in an assembly so i tried to swap the code that makes .stp for the code that makes .idw but it didnt work, so i guess there is something more to it.