Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Create individual .idw for each Part in Assembly

Jorge.NogueiraWGZZM
Explorer

Create individual .idw for each Part in Assembly

Jorge.NogueiraWGZZM
Explorer
Explorer

i have this rule tha creates a idw from a part.

i whant to make a rule that runs on the Assembly to create individual .idw for each Part in Assembly.

 

 

 

 

oBaseView = oSheet.DrawingViews.AddBaseView(oPartDoc, oPoint1, scale1, kCurrentViewOrientation, kHiddenLineDrawingViewStyle)
 
'Bottom Right View
oView3 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint2, 32260)
' Dims only placed if Left Hand View NOT active
'oSheet.DrawingDimensions.GeneralDimensions.Retrieve(oView3)
 
'Top Left View
'oView4 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint3, 32260)
'oSheet.DrawingDimensions.GeneralDimensions.Retrieve(oView4)
 
    oView5 = oSheet.DrawingViews.AddBaseView(oPartDoc,oPoint5, scale1,kFlatBacksideViewOrientation, kHiddenLineDrawingViewStyle,,, oBaseViewOptions)
 
 
''Top Right Hand ISO View
oView6 = oSheet.DrawingViews.AddBaseView(oPartDoc, oPoint4, scale1, kIsoTopLeftViewOrientation, kHiddenLineDrawingViewStyle)
''*** NO Dims on this View ***
 
 
'Created by Ben Smeaton 16/05/2023, bensmeaton@gmail.com.
End Sub
 
Function New_Sheet (SheetName As Integer)
Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument
oSheet = oDoc.Sheets(1)
oSheet.Activate
 
Dim oCommandMgr As CommandManager 
oCommandMgr = ThisApplication.CommandManager 
 
' Get control definition for the line command. 
Dim oControlDef As ControlDefinition 
oControlDef = oCommandMgr.ControlDefinitions.Item("DrawingNewSheetCtxCmd")  
' Execute the command. 
Try
oControlDef.Execute
Dim oSheet2 As Sheet 
oSheet2 = ThisDoc.Document.ActiveSheet
oSheet2.Name ="Sheet:" & SheetName
Catch
End Try
End Function
 
Function get_size(oRefDoc As PartDocument, X_Pos_Max As Decimal, X_Pos_Min As Decimal, Y_Pos_Max As Decimal, Y_Pos_Min As Decimal)
Try
' Get the TransientBRep and TransientGeometry objects.
Dim transBRep As TransientBRep = ThisApplication.TransientBRep
Dim transGeom As TransientGeometry = ThisApplication.TransientGeometry
' Combine all bodies in Part into a single transient Surface Body.
Dim combinedBodies As SurfaceBody = Nothing
For Each surfBody As SurfaceBody In oRefDoc.ComponentDefinition.SurfaceBodies
If combinedBodies Is Nothing Then
combinedBodies = transBRep.Copy(surfBody)
Else
transBRep.DoBoolean(combinedBodies, surfBody, BooleanTypeEnum.kBooleanTypeUnion)
End If
Next
 
' Get the oriented mininum range box of all bodies in Part.
' NOTE: "OrientedMinimumRangeBox" was added in Inventor 2020.3/2021.
Dim minBox As OrientedBox = combinedBodies.OrientedMinimumRangeBox
 
' Get length of each side of mininum range box.
Dim dir1 As Double = minBox.DirectionOne.Length
Dim dir2 As Double = minBox.DirectionTwo.Length
Dim dir3 As Double = minBox.DirectionThree.Length
 
' Sort lengths from smallest to largest.
Dim lengths As New List(Of Double) From {dir1, dir2, dir3 }
lengths.Sort
 
Dim minLength As Double = lengths(0)
Dim midLength As Double = lengths(1)
Dim maxLength As Double = lengths(2)
scale1 = (((Min(X_Pos_Max - X_Pos_Min, Y_Pos_Max - Y_Pos_Min)) / 2) * 0.33) / maxLength
Return scale1
Catch
scale1 = 1 / 50
Return scale1
End Try
End Function
 
Function get_sizeassy(oRefDoc As AssemblyDocument, X_Pos_Max As Decimal, X_Pos_Min As Decimal, Y_Pos_Max As Decimal, Y_Pos_Min As Decimal)
Dim oADoc As AssemblyDocument = oRefDoc
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
Dim oBox As Box = oADef.RangeBox
Dim oMinP As Point = oBox.MinPoint
Dim oMaxP As Point = oBox.MaxPoint
Dim dX As Double = oMaxP.X - oMinP.X
Dim dY As Double = oMaxP.Y - oMinP.Y
Dim dZ As Double = oMaxP.Z - oMinP.Z
Dim lengths As New List(Of Double) From {dX, dY, dZ}
lengths.Sort
 
Dim minLength As Double = lengths(0)
Dim midLength As Double = lengths(1)
Dim maxLength As Double = lengths(2)
scale1 = (((Min(X_Pos_Max - X_Pos_Min, Y_Pos_Max - Y_Pos_Min)) / 2) * 0.33) / maxLength
Return scale1
 
End Function
 
Function view_label(oView As DrawingView)
oView.ShowLabel = True
oDescription = "<StyleOverride FontSize='0.35'><StyleOverride Underline='True'><Property Document='model' PropertySet='Design Tracking Properties' Property='Description' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='29'>DESCRIPTION</Property></StyleOverride></StyleOverride>"
oPartNumber = "<Br/><StyleOverride FontSize='0.35'><StyleOverride Underline='True'><Property Document='model' PropertySet='Design Tracking Properties' Property='Part Number' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='5'>PART NUMBER</Property></StyleOverride></StyleOverride>"
oStringScale = "<Br/><StyleOverride FontSize='0.35'>(Scale <DrawingViewScale/>)</StyleOverride>"
' oView.Label.FormattedText = oDescription & oPartNumber & oStringScale
End Function
 
 
 
 

 

 

 

 

0 Likes
Reply
516 Views
6 Replies
Replies (6)

FINET_Laurent
Advisor
Advisor

Hi @Jorge.NogueiraWGZZM,

 

Part of the begining of the code is missing. Please provide the full code so we can have a look.

 

Kind regards,

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

Jorge.NogueiraWGZZM
Explorer
Explorer
Sub Main()
	Dim oDrawingDoc As DrawingDocument
	Dim oSheets As Sheets
	Dim oView As DrawingView
	'capture the current active sheet
	Dim oCurrentNumber As Sheet

	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 TextSize_TB As Decimal
	Dim oScale As String
	Dim oPartsList1 As PartsList
	Dim View(0 To 5) As String
	

 

'GET SHEET METAL FLAT PATTERN EXTENTS LENGTH TO CALCULATE VIEW SCALES

'MessageBox.Show(iProperties.Value("Custom","FlatExtentsLength"), "Title")
'MessageBox.Show(iProperties.Value("Custom","FlatExtentsWidth"), "Title")
iProperties.Value("Custom", "Extents Length") = 1
iProperties.Value("Custom","Extents Width") = 1
extents_length = SheetMetal.FlatExtentsLength
extents_width = SheetMetal.FlatExtentsWidth
FLATPATTERNLENGTH = iProperties.Value("Custom","Extents Length")
FLATPATTERNWIDTH = iProperties.Value("Custom","Extents Width")

Dim sheetsize

sheetsize = MaxOfMany(FLATPATTERNLENGTH, FLATPATTERNWIDTH)



	
	
	'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
	End If
	'Rotate Model to correct view
	Dim oCamera As Camera
	oCamera = ThisApplication.ActiveView.Camera
	oCamera.ViewOrientationType = 10764 'Front View
	oCamera.Apply
		
	'Define IDW Template File Location
	oDrawingDoc = ThisApplication.Documents.Add(kDrawingDocumentObject, "\\intranet\NPT\Templates Inventor Servidor\Standard -J.N..idw", True)
	oSheet = oDrawingDoc.Sheets.Item(1)

	   oSheet = oDrawingDoc.ActiveSheet
	   oViews = oSheet.DrawingViews
	   For Each oView In oViews    
	       If oView.ScaleFromBase = False Then
	           oView.ScaleString = oScale
	       End If
	   Next
	
	'Limits of Drawing Border in cm
	X_Pos_Min = 3'0.6
	X_Pos_Max = 15'35.46
	Y_Pos_Min = 1.5
	Y_Pos_Max = 20'27.58
	vert_off = 1
	TextSize_TB = 0.2
	
	'Define 2d views
	oPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(X_Pos_Min+((X_Pos_Max-X_Pos_Min)*0.25), Y_Pos_Min+((Y_Pos_Max-Y_Pos_Min)*0.25)+vert_off)			' Bottom Left
	oPoint2 = ThisApplication.TransientGeometry.CreatePoint2d(X_Pos_Min+((X_Pos_Max-X_Pos_Min)*0.75), Y_Pos_Min+((Y_Pos_Max-Y_Pos_Min)*0.25)+vert_off)	' Bottom Right
	oPoint3 = ThisApplication.TransientGeometry.CreatePoint2d(X_Pos_Min+((X_Pos_Max-X_Pos_Min)*0.25), Y_Pos_Min+((Y_Pos_Max-Y_Pos_Min)*0.75)+vert_off)		' Top Left
	oPoint4 = ThisApplication.TransientGeometry.CreatePoint2d(26#, 9#)
	oPoint5 = ThisApplication.TransientGeometry.CreatePoint2d(X_Pos_Min + ((X_Pos_Max - X_Pos_Min) * 0.75), Y_Pos_Min + ((Y_Pos_Max - Y_Pos_Min) * 0.75)+vert_off)' Top Right
	
	
	oPointTLBL = ThisApplication.TransientGeometry.CreatePoint2d(X_Pos_Min + ((X_Pos_Max - X_Pos_Min) * 0.125), Y_Pos_Min + ((Y_Pos_Max - Y_Pos_Min) * 0.625)+vert_off)'
	'oPointTLTL = ThisApplication.TransientGeometry.CreatePoint2d(X_Pos_Min + ((X_Pos_Max - X_Pos_Min) * 0.125), Y_Pos_Min + ((Y_Pos_Max - Y_Pos_Min) * 0.875)+vert_off)'
	oPointTLBR = ThisApplication.TransientGeometry.CreatePoint2d(X_Pos_Min + ((X_Pos_Max - X_Pos_Min) * 0.375), Y_Pos_Min + ((Y_Pos_Max - Y_Pos_Min) * 0.625) + vert_off)'
	oPointTLTR = ThisApplication.TransientGeometry.CreatePoint2d(X_Pos_Min + ((X_Pos_Max - X_Pos_Min) * 0.375), Y_Pos_Min + ((Y_Pos_Max - Y_Pos_Min) * 0.875)+vert_off)'
	
	oPointTRBL = ThisApplication.TransientGeometry.CreatePoint2d(X_Pos_Min + ((X_Pos_Max - X_Pos_Min) * 0.625), Y_Pos_Min + ((Y_Pos_Max - Y_Pos_Min) * 0.625)+vert_off)'
	'oPointTRTL = ThisApplication.TransientGeometry.CreatePoint2d(X_Pos_Min + ((X_Pos_Max - X_Pos_Min) * 0.625), Y_Pos_Min + ((Y_Pos_Max - Y_Pos_Min) * 0.875) + vert_off)'
	oPointTRBR = ThisApplication.TransientGeometry.CreatePoint2d(X_Pos_Min + ((X_Pos_Max - X_Pos_Min) * 0.875), Y_Pos_Min + ((Y_Pos_Max - Y_Pos_Min) * 0.625) + vert_off)'
	oPointTRTR = ThisApplication.TransientGeometry.CreatePoint2d(X_Pos_Min + ((X_Pos_Max - X_Pos_Min) * 0.875), Y_Pos_Min + ((Y_Pos_Max - Y_Pos_Min) * 0.875)+vert_off)'
	
	oPointBLBL = ThisApplication.TransientGeometry.CreatePoint2d(X_Pos_Min + ((X_Pos_Max - X_Pos_Min) * 0.125), Y_Pos_Min + ((Y_Pos_Max - Y_Pos_Min) * 0.125)+vert_off)'
	'oPointBLTL = ThisApplication.TransientGeometry.CreatePoint2d(X_Pos_Min + ((X_Pos_Max - X_Pos_Min) * 0.125), Y_Pos_Min + ((Y_Pos_Max - Y_Pos_Min) * 0.375)+vert_off)'
	oPointBLBR = ThisApplication.TransientGeometry.CreatePoint2d(X_Pos_Min + ((X_Pos_Max - X_Pos_Min) * 0.375), Y_Pos_Min + ((Y_Pos_Max - Y_Pos_Min) * 0.125) + vert_off)'
	oPointBLTR = ThisApplication.TransientGeometry.CreatePoint2d(X_Pos_Min + ((X_Pos_Max - X_Pos_Min) * 0.375), Y_Pos_Min + ((Y_Pos_Max - Y_Pos_Min) * 0.375)+vert_off)'
	
	oPointBRBL = ThisApplication.TransientGeometry.CreatePoint2d(X_Pos_Min + ((X_Pos_Max - X_Pos_Min) * 0.625), Y_Pos_Min + ((Y_Pos_Max - Y_Pos_Min) * 0.125)+vert_off)'
	'oPointBRTL = ThisApplication.TransientGeometry.CreatePoint2d(X_Pos_Min + ((X_Pos_Max - X_Pos_Min) * 0.625), Y_Pos_Min + ((Y_Pos_Max - Y_Pos_Min) * 0.375)+vert_off)'
	oPointBRBR = ThisApplication.TransientGeometry.CreatePoint2d(X_Pos_Min + ((X_Pos_Max - X_Pos_Min) * 0.875), Y_Pos_Min + ((Y_Pos_Max - Y_Pos_Min) * 0.125) + vert_off)'
	oPointBRTR = ThisApplication.TransientGeometry.CreatePoint2d(X_Pos_Min + ((X_Pos_Max - X_Pos_Min) * 0.875), Y_Pos_Min + ((Y_Pos_Max - Y_Pos_Min) * 0.375)+vert_off)'
	
	
	
	'-----------------------Flat Pattern View Section-------------------------------------------------------------------------
'This is the code which adds the sheetmetal flat pattern default view:

' Create a new NameValueMap object
Dim oBaseViewOptions As NameValueMap
oBaseViewOptions = ThisApplication.TransientObjects.CreateNameValueMap

'True = folded view
'False = flat pattern view
oBaseViewOptions.Add("SheetMetalFoldedModel", False)



	
	
	
	
	
	
	
	'Set Base View
	If oPartDoc.DocumentType = kPartDocumentObject Then
		scale1 = get_size(oPartDoc, X_Pos_Max, X_Pos_Min, Y_Pos_Max, Y_Pos_Min)*3
	ElseIf oPartDoc.DocumentType = kAssemblyDocumentObject Then
		scale1 = get_sizeassy(oPartDoc, X_Pos_Max, X_Pos_Min, Y_Pos_Max, Y_Pos_Min)*3
	Else
		scale1 = 1 / 50
	End If
	
	
	
	
'  kDefaultViewOrientation = 10753
'  kTopViewOrientation = 10754
'  kRightViewOrientation = 10755
'  kBackViewOrientation = 10756
'  kBottomViewOrientation = 10757
'  kLeftViewOrientation = 10758
'  kIsoTopRightViewOrientation = 10759
'  kIsoTopLeftViewOrientation = 10760
'  kIsoBottomRightViewOrientation = 10761
'  kIsoBottomLeftViewOrientation = 10762
'  kArbitraryViewOrientation = 10763
'  kFrontViewOrientation = 10764
'  kCurrentViewOrientation = 10765
'  kSavedCameraViewOrientation = 10766
'  kFlatPivotRightViewOrientation = 10767
'  kFlatPivotLeftViewOrientation = 10768
'  kFlatPivot180ViewOrientation = 10769
'  kFlatBacksideViewOrientation = 10770
'  kFlatBacksidePivotRightViewOrientation = 10771
'  kFlatBacksidePivotLeftViewOrientation = 10772
'  kFlatBacksidePivot180ViewOrientation = 10773
	
	
	
	
	
	oBaseView = oSheet.DrawingViews.AddBaseView(oPartDoc, oPoint1, scale1, kCurrentViewOrientation, kHiddenLineDrawingViewStyle)
	
	'Bottom Right View
	oView3 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint2, 32260)
	' Dims only placed if Left Hand View NOT active
	'oSheet.DrawingDimensions.GeneralDimensions.Retrieve(oView3)
	
	'Top Left View
	'oView4 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint3, 32260)
	'oSheet.DrawingDimensions.GeneralDimensions.Retrieve(oView4)
	
    oView5 = oSheet.DrawingViews.AddBaseView(oPartDoc,oPoint5, scale1,kFlatBacksideViewOrientation, kHiddenLineDrawingViewStyle,,, oBaseViewOptions)


	''Top Right Hand ISO View
	oView6 = oSheet.DrawingViews.AddBaseView(oPartDoc, oPoint4, scale1, kIsoTopLeftViewOrientation, kHiddenLineDrawingViewStyle)
	''*** NO Dims on this View ***

	
'Created by Ben Smeaton 16/05/2023, bensmeaton@gmail.com.
End Sub

Function New_Sheet (SheetName As Integer)
	Dim oDoc As DrawingDocument
	oDoc = ThisApplication.ActiveDocument
	oSheet = oDoc.Sheets(1)
	oSheet.Activate
	
	Dim oCommandMgr As CommandManager 
	oCommandMgr = ThisApplication.CommandManager 
	
	' Get control definition for the line command. 
	Dim oControlDef As ControlDefinition 
	 oControlDef = oCommandMgr.ControlDefinitions.Item("DrawingNewSheetCtxCmd")  
	' Execute the command. 
	Try
	oControlDef.Execute
	Dim oSheet2 As Sheet 
	oSheet2 = ThisDoc.Document.ActiveSheet
	oSheet2.Name ="Sheet:" & SheetName
	Catch
	End Try
End Function

Function get_size(oRefDoc As PartDocument, X_Pos_Max As Decimal, X_Pos_Min As Decimal, Y_Pos_Max As Decimal, Y_Pos_Min As Decimal)
	Try
		' Get the TransientBRep and TransientGeometry objects.
		Dim transBRep As TransientBRep = ThisApplication.TransientBRep
		Dim transGeom As TransientGeometry = ThisApplication.TransientGeometry
		' Combine all bodies in Part into a single transient Surface Body.
		Dim combinedBodies As SurfaceBody = Nothing
		For Each surfBody As SurfaceBody In oRefDoc.ComponentDefinition.SurfaceBodies
			If combinedBodies Is Nothing Then
				combinedBodies = transBRep.Copy(surfBody)
			Else
				transBRep.DoBoolean(combinedBodies, surfBody, BooleanTypeEnum.kBooleanTypeUnion)
			End If
		Next
		
		' Get the oriented mininum range box of all bodies in Part.
		' NOTE: "OrientedMinimumRangeBox" was added in Inventor 2020.3/2021.
		Dim minBox As OrientedBox = combinedBodies.OrientedMinimumRangeBox
		
		' Get length of each side of mininum range box.
		Dim dir1 As Double = minBox.DirectionOne.Length
		Dim dir2 As Double = minBox.DirectionTwo.Length
		Dim dir3 As Double = minBox.DirectionThree.Length
	
		' Sort lengths from smallest to largest.
		Dim lengths As New List(Of Double) From {dir1, dir2, dir3 }
		lengths.Sort
		
		Dim minLength As Double = lengths(0)
		Dim midLength As Double = lengths(1)
		Dim maxLength As Double = lengths(2)
		scale1 = (((Min(X_Pos_Max - X_Pos_Min, Y_Pos_Max - Y_Pos_Min)) / 2) * 0.33) / maxLength
		Return scale1
	Catch
		scale1 = 1 / 50
		Return scale1
	End Try
End Function

Function get_sizeassy(oRefDoc As AssemblyDocument, X_Pos_Max As Decimal, X_Pos_Min As Decimal, Y_Pos_Max As Decimal, Y_Pos_Min As Decimal)
	Dim oADoc As AssemblyDocument = oRefDoc
	Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
	Dim oBox As Box = oADef.RangeBox
	Dim oMinP As Point = oBox.MinPoint
	Dim oMaxP As Point = oBox.MaxPoint
	Dim dX As Double = oMaxP.X - oMinP.X
	Dim dY As Double = oMaxP.Y - oMinP.Y
	Dim dZ As Double = oMaxP.Z - oMinP.Z
	Dim lengths As New List(Of Double) From {dX, dY, dZ}
	lengths.Sort
	
	Dim minLength As Double = lengths(0)
	Dim midLength As Double = lengths(1)
	Dim maxLength As Double = lengths(2)
	scale1 = (((Min(X_Pos_Max - X_Pos_Min, Y_Pos_Max - Y_Pos_Min)) / 2) * 0.33) / maxLength
	Return scale1
	
End Function

Function view_label(oView As DrawingView)
	oView.ShowLabel = True
	oDescription = "<StyleOverride FontSize='0.35'><StyleOverride Underline='True'><Property Document='model' PropertySet='Design Tracking Properties' Property='Description' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='29'>DESCRIPTION</Property></StyleOverride></StyleOverride>"
	oPartNumber = "<Br/><StyleOverride FontSize='0.35'><StyleOverride Underline='True'><Property Document='model' PropertySet='Design Tracking Properties' Property='Part Number' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='5'>PART NUMBER</Property></StyleOverride></StyleOverride>"
	oStringScale = "<Br/><StyleOverride FontSize='0.35'>(Scale <DrawingViewScale/>)</StyleOverride>"
	' oView.Label.FormattedText = oDescription & oPartNumber & oStringScale
End Function








0 Likes

Andrii_Humeniuk
Advisor
Advisor

Hi @Jorge.NogueiraWGZZM . I modified your code, I removed all the rudimentary parts of the code and made it more logical. This code can be run both in the part and in the assembly.

 

 

Sub Main()
	Dim oInvApp As Inventor.Application = ThisApplication
	Dim oDoc As Document = oInvApp.ActiveDocument
	Dim oTG As TransientGeometry = oInvApp.TransientGeometry
	If TypeOf oDoc Is PartDocument Then
		Call CreateDrawing(oInvApp, oTG, oDoc)
	ElseIf TypeOf oDoc Is AssemblyDocument Then
		Dim oAsmDoc As AssemblyDocument = oDoc
		Dim oOccs As ComponentOccurrences = oAsmDoc.ComponentDefinition.Occurrences
		For Each oRefDoc As Document In oAsmDoc.AllReferencedDocuments
			If Not TypeOf oRefDoc Is PartDocument Or _
				oOccs.AllReferencedOccurrences(oRefDoc).Count = 0 Then Continue For
			Dim oPartDoc As PartDocument = oRefDoc
			Call CreateDrawing(oInvApp, oTG, oRefDoc)
		Next
	End If
End Sub

Private Sub CreateDrawing(ByVal oInvApp As Inventor.Application,
							ByVal oTG As TransientGeometry,
							ByVal oDoc As PartDocument)
	If Not oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then Return
	If MsgBox("Would you like to Create a drawing for " & oDoc.DisplayName & "?",
				vbYesNo, "Drawing Selection") = vbNo Then Return
	
	Dim sTemplates As String = "\\Comp59\Work SP\Templates\ru-RU\КТВ_Креслення(ДСТУ).dwg"
	Dim oDDoc As DrawingDocument = oInvApp.Documents.Add(kDrawingDocumentObject, sTemplates, True)
	Dim oSheet As Sheet = oDDoc.ActiveSheet
	Dim oViews As DrawingViews = oSheet.DrawingViews

	Dim oBaseView, oView3, oView5, oView6 As DrawingView
	
	'Limits of Drawing Border in cm
	Dim X_Pos_Min As Double = 3'0.6
	Dim X_Pos_Max As Double = 15'35.46
	Dim Y_Pos_Min As Double = 1.5
	Dim Y_Pos_Max As Double = 20'27.58
	Dim vert_off As Integer = 1
	
	'Define 2d views
	Dim oPoint1, oPoint2, oPoint4, oPoint5 As Point2d
	oPoint1 = oTG.CreatePoint2d(X_Pos_Min+((X_Pos_Max-X_Pos_Min)*0.25), Y_Pos_Min+((Y_Pos_Max-Y_Pos_Min)*0.25)+vert_off)	' Bottom Left
	oPoint2 = oTG.CreatePoint2d(X_Pos_Min+((X_Pos_Max-X_Pos_Min)*0.75), Y_Pos_Min+((Y_Pos_Max-Y_Pos_Min)*0.25)+vert_off)	' Bottom Right
	oPoint4 = oTG.CreatePoint2d(26#, 9#)
	oPoint5 = oTG.CreatePoint2d(X_Pos_Min + ((X_Pos_Max - X_Pos_Min) * 0.75), Y_Pos_Min + ((Y_Pos_Max - Y_Pos_Min) * 0.75)+vert_off)' Top Right	
	
	Dim oNameMap As NameValueMap = oInvApp.TransientObjects.CreateNameValueMap	
	oNameMap.Add("SheetMetalFoldedModel", False)

	Dim scale1 As Double = get_size(oDoc, X_Pos_Max, X_Pos_Min, Y_Pos_Max, Y_Pos_Min)*3
	oBaseView = oViews.AddBaseView(oDoc, oPoint1, scale1, kCurrentViewOrientation, kHiddenLineDrawingViewStyle)	
	oView3 = oViews.AddProjectedView(oBaseView, oPoint2, 32260)	
    oView5 = oViews.AddBaseView(oDoc, oPoint5, scale1, kFlatBacksideViewOrientation, kHiddenLineDrawingViewStyle,,, oNameMap)
	oView6 = oViews.AddBaseView(oDoc, oPoint4, scale1, kIsoTopLeftViewOrientation, kHiddenLineDrawingViewStyle)
End Sub

Private Function get_size(ByVal oRefDoc As PartDocument,
							ByVal X_Pos_Max As Double,
							ByVal X_Pos_Min As Double,
							ByVal Y_Pos_Max As Double,
							ByVal Y_Pos_Min As Double) As Double
	Try
		' Get the TransientBRep and TransientGeometry objects.
		Dim transBRep As TransientBRep = ThisApplication.TransientBRep
		' Combine all bodies in Part into a single transient Surface Body.
		Dim combinedBodies As SurfaceBody = Nothing
		For Each surfBody As SurfaceBody In oRefDoc.ComponentDefinition.SurfaceBodies
			If combinedBodies Is Nothing Then
				combinedBodies = transBRep.Copy(surfBody)
			Else
				transBRep.DoBoolean(combinedBodies, surfBody, BooleanTypeEnum.kBooleanTypeUnion)
			End If
		Next
		
		' Get the oriented mininum range box of all bodies in Part.
		' NOTE: "OrientedMinimumRangeBox" was added in Inventor 2020.3/2021.
		Dim minBox As OrientedBox = combinedBodies.OrientedMinimumRangeBox
		
		' Get length of each side of mininum range box.
		Dim dir1 As Double = minBox.DirectionOne.Length
		Dim dir2 As Double = minBox.DirectionTwo.Length
		Dim dir3 As Double = minBox.DirectionThree.Length
	
		' Sort lengths from smallest to largest.
		Dim lengths As New List(Of Double) From {dir1, dir2, dir3 }
		lengths.Sort
		
		Dim minLength As Double = lengths(0)
		Dim midLength As Double = lengths(1)
		Dim maxLength As Double = lengths(2)
		scale1 = (((Min(X_Pos_Max - X_Pos_Min, Y_Pos_Max - Y_Pos_Min)) / 2) * 0.33) / maxLength
		Return scale1
	Catch
		scale1 = 1 / 50
		Return scale1
	End Try
End Function

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes

Jorge.NogueiraWGZZM
Explorer
Explorer
it does not work on the assembly

and it shows this message on the part

Error on line 51 in rule: Rule11, in document: PART_B.ipt

Object reference not set to an instance of an object.
0 Likes

Andrii_Humeniuk
Advisor
Advisor

Change line 29:

 

Dim oViews As DrawingViews = oSheet.DrawingViews

 

I updated the code in the previous post.

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

Jorge.NogueiraWGZZM
Explorer
Explorer
almost there
the problem is that you have to create the flatpatern before
one of the VIEWs is the flatpatern
0 Likes