Das ist der Code, aus dem direkt aus dem ipt die Zeichnung erstellt wird.
Allerdings ohne Prüfung und ohne automatische Abwicklungserstellung.
-> $Templates <- muss noch mit dem Pfad der Templates ersetzt werden (mit "" vorne und hinten).
-> $Norm.idw <- muss noch mit dem Gewünschten Template für die Zeichnung ersetzt werden.
Sub Main
Dim oTargetDoc As Document = Nothing
If RuleArguments.Exists("TargetDocument") Then
oTargetDoc = RuleArguments.Value("TargetDocument")
Else
oTargetDoc = ThisDoc.Document
End If
If IsNothing(oTargetDoc) Then Exit Sub
If oTargetDoc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject And _
oTargetDoc.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then
Exit Sub
End If
'if oTargetDoc has not been saved yet, then accessing its FullFileName will throw Error
Dim oTargetDocFFN As String = ""
Try
oTargetDocFFN = oTargetDoc.FullFileName
Catch
Exit Sub
End Try
If oTargetDocFFN = "" Then Exit Sub 'making sure it was filled in
Dim oDrawingFullFileName As String = System.IO.Path.ChangeExtension(oTargetDocFFN, ".idw")
If System.IO.File.Exists(oDrawingFullFileName) Then
oOverWrite = MsgBox("A Drawing for this model already exists." & vbCrLf &
"Do you want to over-write it?", vbYesNo + vbQuestion, "DRAWING EXISTS!")
If oOverWrite = vbNo Then Exit Sub
End If
Dim oTPath As String = "$Templates"
Dim oTName As String = "$Norm.idw"
Dim oTFullFileName As String = System.IO.Path.Combine(oTPath, oTName)
Dim oDDoc As DrawingDocument = Nothing
If System.IO.File.Exists(oTFullFileName) Then
oDDoc = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, oTFullFileName, True)
Else
MsgBox("Template Drawing could not be found!", vbCritical, "")
Exit Sub
End If
'Using RangeBox to get model size
Dim oRangeBox As Box = oTargetDoc.ComponentDefinition.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)
Dim oModelWidth As Long = MaxOfMany(oXDim, oYDim, oZDim)
Dim oModelHeight As Long = MinOfMany(oXDim, oYDim, oZDim)
Dim oViewRotation As Double = 0.0
Dim oViewOrientation As ViewOrientationTypeEnum = Nothing
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 = 0.0
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
'oBViewScale = 1/2
'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(oTargetDoc, 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(oTargetDoc, 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"
'oDDoc.Update
'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
'Optionen zusammenstellen für die Ansicht der Abwicklung
Dim oBaseViewOptions As NameValueMap
oBaseViewOptions = ThisApplication.TransientObjects.CreateNameValueMap
Call oBaseViewOptions.Add("SheetMetalFoldedModel", False)
Dim oABWInsPoint As Point2d = oTG.CreatePoint2d(o1stColumn, o2ndRow)
Dim oABW As DrawingView = oViews.AddBaseView(oTargetDoc, _
oABWInsPoint, _
1.0, _
Inventor.ViewOrientationTypeEnum.kDefaultViewOrientation, _
Inventor.DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle, _
, _
, _
oBaseViewOptions)
oABW.Name = "Abwicklung"
oABW.IncludeMeshBodies = True
oABW.IncludeSurfaceBodies = True
oDDoc.SaveAs(oDrawingFullFileName, False)
End Sub