Consolidate flat pattern of multiple parts from an assembly

Consolidate flat pattern of multiple parts from an assembly

Anonymous
Not applicable
2,434 Views
21 Replies
Message 1 of 22

Consolidate flat pattern of multiple parts from an assembly

Anonymous
Not applicable

I have an assembly with 500 parts and around 200 parts are sheet metal.

 

1) The procedure i follow is create a drawing file for each part and place the flat pattern developed view in the drawing for each part.(Repeated 200 times)

2) Then I create a development.drw and copy paste this view from all the drawings one by one.( Repeat task 200 times open and copy)

3) Next I copy this drawing into autocad and do the nesting for laser cutting.

 

I want to get all the falt patterns from these parts in one place with their part numbers without doing the repetitive task.

Can anyone provide the best and the fastest solution for this? I am using Inventor 2011. I know it can be done using vba but i am unable to write a code. Please Help !

 

Thanks,

Sid

 

0 Likes
2,435 Views
21 Replies
Replies (21)
Message 2 of 22

Anonymous
Not applicable

Hello.

I have a similar problem!

What I try to do is place all the developed flat patterns onto onto a very large sheet at a 1:1 scale.

I can open  parts using this code (posted below) which I found on here.

I now have to manually place all the sheetmetal flat patterns onto the sheet - any code which could do this would be a real help.

Code to place the flat pattern of all open parts onto the same drawing.

The drawing can then be exported for nesting & laser cutting.

 

Assigns a sheet metal rule to the part & creates a flat patten

 

Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.ActiveDocument

'Change Document.SubType to Sheetmetal
oPartDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"
iProperties.Material = "Stainless Steel 304"
SheetMetal.SetActiveStyle("StSt-6mm 50mmV")

iProperties.PartColor = "Yellow"

Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument
''ThisDoc.Launch(ThisDoc.PathAndFileName(True))
Dim oCompDef As SheetMetalComponentDefinition
oCompDef = oDoc.ComponentDefinition
If oCompDef.HasFlatPattern = False Then
    oCompDef.Unfold
Else
   oCompDef.FlatPattern.Edit
End If
ThisDoc.Save

 

 

 

 

open assembly parts:

 

'Define the open document
Dim oDoc As Document
oDoc = ThisDoc.Document
'Look at all of the files referenced in the open document
Dim docFile As Document
For Each docFile In oDoc.AllReferencedDocuments
'open the indexed file'true opens the file normaly'false opens the file programatically without generating the graphics
ThisApplication.Documents.Open(docFile.FullFileName, True)
Next

 

I hope someone can expand on this.

 

Thanks

 

Andrew

 

0 Likes
Message 3 of 22

MechMachineMan
Advisor
Advisor

Here is an extensive program I used that did as you need (and seperated by thickness too!)

 

May need some extensive rework to exactly suit your needs and could likely also use some refactoring as this was earlier in my programming days.

 

Sub Main()
Dim oTextSave As String = "C:\Windows\Temp\iLogicBuffer.txt"
oWrite = System.IO.File.CreateText(oTextSave)
oWrite.Close

Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument

Dim oCompDef As AssemblyComponentDefinition
oCompDef = oDoc.ComponentDefinition
	
Dim oBOM As BOM
oBOM = oCompDef.BOM()

oBOM.PartsOnlyViewEnabled = True

Dim oBOMView As BOMView
oBOMView = oBOM.BOMViews.Item("Parts Only")

Dim oBOMRow As BOMRow
For Each oBOMRow In oBOMView.BOMRows
	If oBOMRow.BOMStructure = BOMStructureEnum.kInseparableBOMStructure Or oBOMRow.BOMStructure = BOMStructureEnum.kVariesBOMStructure 'Or oBOMRow.Merged = True
		MsgBox("Changes to BOM struture required")
		Exit Sub
		'oBOMRow.BOMStructure = kNormalBOMStructure
	End If
Next

'Create Dwg Document
'[
Dim oDwgDoc As DrawingDocument
'oDwgDoc = ThisApplication.Documents.Add(kDrawingDocumentObject,"X:\CAD Library\Templates\Inventor 2016\Dyna Approved\Dyna.idw", True)
oDwgDoc = ThisApplication.Documents.Add(kDrawingDocumentObject,"C:\Users\Rob\Desktop\PROFILE CREATION TEMPLATE.idw", True)

Dim oSheets As Sheets = oDwgDoc.Sheets

Dim oSheet As Sheet
oSheet = oDwgDoc.Sheets.Item(1)

Try
	oSheet.TitleBlock.Delete
	oSheet.RevisionTables.Item(1).Delete
Catch
End Try
'oSheet.Size = DrawingSheetSizeEnum.kCustomDrawingSheetSize
'oSheet.Height = 144 * 2.54
'oSheet.Width = 72 * 2.54
']

'Try
'	ThisApplication.SilentOperation = True
'	ThisApplication.ScreenUpdating = False
	oPlaceViews(oBOMView, oDwgDoc)
'	ThisApplication.ScreenUpdating = True
'	ThisApplication.SilentOperation = False
'Catch
'	ThisApplication.ScreenUpdating = True
'	ThisApplication.SilentOperation = False
'End Try

'Clean-up of sheets
'[
For Each oSheet In oSheets
	If oSheet.DrawingViews.Count = 0
		oSheet.Delete
	End If
Next

Dim oNView As DrawingView
For Each oSheet In oSheets
	oSheet.Activate
	
	Dim oMaxHeight As Double = 0
	Dim oMaxWidth As Double = 0
	Dim oSaveHeight As Double = 0
	Dim oNewLoc As Point2d
	
	For Each oNView In oSheet.DrawingViews
			If oNView.Height > oMaxHeight
				oMaxHeight = oNView.Height
			End If
		If Not oNView.Name Like "PLATE*"
			If oNView.Width > oMaxWidth
				oMaxWidth = oNView.Width
			End If
		Else		
			If oNView.Width > oPlateMaxWidth
				oPlateMaxWidth = oNView.Width
			End If
		End If
	Next
	oWidth = 0.8*oPlateMaxWidth
	oHeight = 0.7*oMaxHeight
	For Each oNView In oSheet.DrawingViews
		If oNView.Name Like "PLATE*"
			oNewLoc = ThisApplication.TransientGeometry.CreatePoint2d(oWidth, oHeight)
			oNView.Position = oNewLoc
			oHeight = oHeight + oMaxHeight
			oAddSketchedSymbol(oNView, oMaxWidth)
		End If
	Next
	
	oWidth = oWidth + .8*(oMaxWidth + oPlateMaxWidth)
	oHeight = .7*oMaxHeight
	For Each oNView In oSheet.DrawingViews
		If oNView.Name Like "FLAT*"
			oNewLoc = ThisApplication.TransientGeometry.CreatePoint2d(oWidth, oHeight)
			oNView.Position = oNewLoc
			oHeight = oHeight + oMaxHeight
			oAddSketchedSymbol(oNView, oMaxWidth)
		End If
	Next
	
	oWidth = oMaxWidth + oWidth
	oHeight = .7*oMaxHeight
	For Each oNView In oSheet.DrawingViews
		If oNView.Name Like "BENT*"
			oNewLoc = ThisApplication.TransientGeometry.CreatePoint2d(oWidth, oHeight)
			oNView.Position = oNewLoc
			oHeight = oHeight + oMaxHeight
		End If
	Next
	
Next
']
'ThisApplication.ScreenUpdating = True
Process.Start ("Notepad.exe",oTextSave)
End Sub

Sub oPlaceViews(oBOMView As BOMView, oDwgDoc As DrawingDocument)
Dim oTextSave As String = "C:\Windows\Temp\iLogicBuffer.txt"
oWrite = System.IO.File.AppendText(oTextSave)

Dim oTtlQty As Integer
Dim oUOM As UnitsOfMeasure
oUOM = ThisApplication.ActiveDocument.UnitsOfMeasure

Dim oCurrentHeight As Double
oCurrentHeight = 0

Dim oCurrentHeight2 As Double ' For Bent ****
oCurrentHeight2 = 0
Dim oFP As Boolean = False

'ThisApplication.ScreenUpdating = False
Dim i As Integer = 0
For Each oBOMRow In oBOMView.BOMRows
	oFP = False
	oTtlQty = oBOMRow.TotalQuantity
	oIQty = oBOMRow.ItemQuantity
	
'Get appropriate component definition
'[
	Dim oBOMItem As ComponentDefinition
	oBOMItem = oBOMRow.ComponentDefinitions.Item(1)
	If oBOMItem.Type = ObjectTypeEnum.kVirtualComponentDefinitionObject Or _
		Not oBOMItem.Document.PropertySets.Item("Design Tracking Properties").Item("Description").Value Like "PL*"
		Continue For
	End If
	Dim oBDoc As Document
	oBDoc = oBOMItem.Document
	
	Try
	oBDoc.PropertySets.Item("Inventor User Defined Properties").Item("TtlQty").Value = oTtlQty
	Catch
	oBDoc.PropertySets.Item("Inventor User Defined Properties").Add(oTtlQty, "TtlQty")
	End Try
	
	If oBOMItem.Type = ObjectTypeEnum.kSheetMetalComponentDefinitionObject
			If oBOMItem.HasFlatPattern = True
				oBOMItem = oBOMItem.FlatPattern
			Else
			Try
			oBOMItem.Document.Unfold
			oBOMItem = oBOMItem.FlatPattern
			Catch
				'MsgBox("Error In Generating Flat Pattern for " & oBOMItem.Document.FullFileName)
				oWrite.WriteLine("Error In Generating Flat Pattern for " & oBOMItem.Document.FullFileName)
			End Try	
		End If
		oFP = True
	End If
']

'Get Bounding Box/Orientation of FACE
'[	
	Dim oVO As ViewOrientationTypeEnum
	Dim oRt As Double
	oBOX = oBOMItem.RangeBox
	oXDif = oUOM.ConvertUnits(Abs(oBOX.MaxPoint.X - oBOX.MinPoint.X), "cm", "in")
	oYDif = oUOM.ConvertUnits(Abs(oBOX.MaxPoint.Y - oBOX.MinPoint.Y), "cm", "in")
	oZDif = oUOM.ConvertUnits(Abs(oBOX.MaxPoint.Z - oBOX.MinPoint.Z), "cm", "in")
	'MsgBox("TtlQty: " & oTtlQty & " IQty: " & oIQty & vbLf & _
	'	   "XDif: " & oXDif & vbLf & _
	'       "YDif: " & oYDif & vbLf & _
	'	   "ZDif: " & oZDif)
		   
	If (oXDif > oYDif And oYDif > oZDif)
		oLength = oXDif
		oWidth = oYDif
		oThickness = oZDif
		oFace = "XY"
		oVO = ViewOrientationTypeEnum.kFrontViewOrientation
		oRt = 0
	Else If oYDif > oZDif And oZDif > oXDif
		oLength = oYDif
		oWidth = oZDif
		oThickness = oXDif
		oFace = "YZ"
		oVO = ViewOrientationTypeEnum.kRightViewOrientation
		oRt = 90*(Math.PI/180)
	Else If oZDif > oXDif And oXDif > oYDif
		oLength = oZDif
		oWidth = oXDif
		oThickness = oDdif
		oFace = "ZX"
		oVO = ViewOrientationTypeEnum.kTopViewOrientation
		oRt = 90*(Math.PI/180)
	Else If oZDif > oYDif And oYDif > oXDif
		oLength = oZDif
		oWidth = oYDif
		oThickness = oXDif
		oFace = "ZY"
		oVO = ViewOrientationTypeEnum.kRightViewOrientation
		oRt = 0
	Else If oYDif > oXDif And oXDif > oZDif
		oLength = oYDif
		oWidth = oXDif
		oThickness = oZDif
		oFace = "YX"
		oVO = ViewOrientationTypeEnum.kFrontViewOrientation
		oRt = 90*(Math.PI/180)
	Else If oXDif > oZDif And oZDif > oYDif
		oLength = oXDif
		oWidth = oZDif
		oThickness = oYDif
		oFace = "XZ"
		oVO = ViewOrientationTypeEnum.kTopViewOrientation
		oRt = 0
	Else If oXDif = oYDif
		oLength = oXDif
		oWidth = oYDif
		oThickness = oZDif
		oFace = "XY"
		oVO = ViewOrientationTypeEnum.kFrontViewOrientation
		oRt = 0
	Else If oZDif = oYDif
		oLength = oZDif
		oWidth = oYDif
		oThickness = oXDif
		oFace = "ZY"
		oVO = ViewOrientationTypeEnum.kRightViewOrientation
		oRt = 0
	Else If oXDif = oZDif
		oLength = oXDif
		oWidth = oZDif
		oThickness = oYDif
		oFace = "XZ"
		oVO = ViewOrientationTypeEnum.kTopViewOrientation
		oRt = 0
	Else
		MsgBox("I am confused")
	End If
	
']
'MsgBox(oFace)

'Select Sheet
'[
	Dim oSheets As Sheets = oDwgDoc.Sheets
	
	Select Case Math.Round(oThickness, 4)
		Case 6
			oSheets.Item(1).Activate
		Case 5
			oSheets.Item(2).Activate
		Case 4.5
			oSheets.Item(3).Activate
		Case 4
			oSheets.Item(4).Activate
		Case 3.5
			oSheets.Item(5).Activate
		Case 3
			oSheets.Item(6).Activate
		Case 2.5
			oSheets.Item(7).Activate
		Case 2
			oSheets.Item(8).Activate
		Case 1.75
			oSheets.Item(9).Activate
		Case 1.5
			oSheets.Item(10).Activate
		Case 1.25
			oSheets.Item(11).Activate
		Case 1
			oSheets.Item(12).Activate
		Case .75
			oSheets.Item(13).Activate
		Case .625
			oSheets.Item(14).Activate
		Case .5
			oSheets.Item(15).Activate
		Case .375
			oSheets.Item(16).Activate
		Case .3125
			oSheets.Item(17).Activate
		Case .25
			oSheets.Item(18).Activate
		Case .1875
			oSheets.Item(19).Activate
		Case .1345, .1382, .1019, .1406 '10 gauge
			oSheets.Item(20).Activate
		Case .1046, .1084, .0808, .1094 ' 12 Ga
			oSheets.Item(21).Activate
		Case .0747, .0785, .0641, .0781 '14 Ga
			oSheets.Item(22).Activate
		Case .0598, .0635, .0508, .0625 '16 Ga
			oSheets.Item(23).Activate
		Case .0478, .0516, .0403, .0500 '18 Ga
			oSheets.Item(24).Activate
		Case Else 
			oSheets.Item(25).Activate
		End Select

']

	Dim oViews As DrawingViews
	oViews = oDwgDoc.ActiveSheet.DrawingViews
	Dim oView As DrawingView
	Dim oViewLoc As Point2d
	Dim oBaseViewOptions As NameValueMap
	oBaseViewOptions = ThisApplication.TransientObjects.CreateNameValueMap
	oBaseViewOptions.Add("SheetMetalFoldedModel", False)
	
	If oFP = False
		oViewLoc = ThisApplication.TransientGeometry.CreatePoint2d(10*2.54, oCurrentHeight + .6*oWidth*2.54)
		oCurrentHeight = oCurrentHeight + oWidth*2.54
	
		oView = oViews.AddBaseView(oBOMItem.Document, oViewLoc, 1, oVO, DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle)
		oView.Rotation = oRt
		oView.Name = "PLATE" & i
		i=i+1
	Else
		oViewLoc = ThisApplication.TransientGeometry.CreatePoint2d(100*2.54, oCurrentHeight2 + .6*oWidth*2.54)
		oView = oViews.AddBaseView(oBOMItem.Document, oViewLoc, 1, ViewOrientationTypeEnum.kDefaultViewOrientation, DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle,,,oBaseViewOptions)
		oView.Rotation = oRt
		oView.Name = "FLAT" & i
		i=i+1
		
		oViewLoc = ThisApplication.TransientGeometry.CreatePoint2d(300*2.54, oCurrentHeight2 + .6*oWidth*2.54)
		oView = oViews.AddBaseView(oBOMItem.Document, oViewLoc, 1, oVO, DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle)
		oView.Rotation = oRt
		oView.Name = "BENT" & i
		i=i+1
		
		oCurrentHeight2 = oCurrentHeight2 + oWidth*2.54
	End If

Next 'BOMRow

oWrite.Flush 
oWrite.Close

End Sub

Sub oAddSketchedSymbol(oView As DrawingView, oMaxWidth As Double)

		Dim oCurve As DrawingCurve = oView.DrawingCurves.Item(1)
		Dim oPoint As Point2d = oCurve.MidPoint
		If oPoint Is Nothing
			oPoint = oCurve.CenterPoint
		End If
		
		Dim oSSD As SketchedSymbolDefinition = ThisApplication.ActiveDocument.SketchedSymbolDefinitions.Item("Part Label")
		
		Dim oLeaderPoints As ObjectCollection
		oLeaderPoints = ThisApplication.TransientObjects.CreateObjectCollection
		
		Dim oPlacementPoint As Point2d
		oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(oView.Position.X - (1.5*oMaxWidth), oView.Position.Y)
		oLeaderPoints.Add(oPlacementPoint)
		
		Dim oGeometryIntent As GeometryIntent
		oGeometryIntent = ThisApplication.ActiveDocument.ActiveSheet.CreateGeometryIntent(oCurve)
		oLeaderPoints.Add(oGeometryIntent)
		
		Dim oS1 As SketchedSymbol
	Try
		oS1 = ThisApplication.ActiveDocument.ActiveSheet.SketchedSymbols.AddWithLeader(oSSD,oLeaderPoints, 0, oMaxWidth/20, ,False,True)
		oS1.LeaderVisible = False
	Catch
	End Try

End Sub

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 4 of 22

matt_jlt
Collaborator
Collaborator

Hi,is there a requirement that each flat pattern needs to be on a drawing with titleblock?

Have you considered the option of exporting the flat patterns directly from the parts / assembly.

 

You can iterate through all of the parts and export them to DXF / DWG?

 

Regards, Matt.

0 Likes
Message 5 of 22

tolgay.hickiran
Advisor
Advisor
Hey we've been trying to use your code but unable to find a way to. It looks like VB Editor code inside inventor but it has lots of red lines once we copy paste it. Which environment were you using this on. We also tried using it on Visual Studio and failed to use it there too.

Some worthwhile ideas
Copy Design should rename ilogic Rules too!
Why Nastran In-CAD doesn't have an SDK?IMPLEMENTED!

Tolgay Hickiran
Founding Partner
SignatureSignature

website
emailskypelinkedinyoutubeemail

0 Likes
Message 6 of 22

MechMachineMan
Advisor
Advisor
Use it straight in a rule rather than through either of those environments.

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 7 of 22

tolgay.hickiran
Advisor
Advisor

Hello mmm, we've tried many different ways to use your code but its a no go. We probably failed hard here.


Some worthwhile ideas
Copy Design should rename ilogic Rules too!
Why Nastran In-CAD doesn't have an SDK?IMPLEMENTED!

Tolgay Hickiran
Founding Partner
SignatureSignature

website
emailskypelinkedinyoutubeemail

0 Likes
Message 8 of 22

Jef_E
Collaborator
Collaborator

@Anonymous_ice wrote:

Hello mmm, we've tried many different ways to use your code but its a no go. We probably failed hard here


I had a quick glance at the code, and I wonder did you edit this line??

 

oDwgDoc = ThisApplication.Documents.Add(kDrawingDocumentObject,"C:\Users\Rob\Desktop\PROFILE CREATION TEMPLATE.idw", True)

If not it will end bad 😄 for the rest it seems to be working for me? Don't know what it does, but it does not give any errors when running the rule.



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes
Message 9 of 22

Anonymous
Not applicable

Thanks for posting this - been busy! ( lots of time spent placing individual flat parts onto a dwg!)

I've put the code into a new rule & edited the template path - the rule runs, opens a text window, opens a drawing but it's blank - need to investigate - further - like the idea, hope I can use it!

Capture2.JPG

 

Capture3.JPG

0 Likes
Message 10 of 22

Anonymous
Not applicable

I assume you have flat patterns already created to ipts. Here is one code sample(VBA) that should do the trick. You can modify the code to your case. Copy the attached(zipped) ini-file to C:\

 

Public Sub CreateDXFDrawing()
'Create sheet for sheetmetal parts with flatpattern
'Get Inventor and Document
Dim oApp As Inventor.Application
Set oApp = ThisApplication

Dim oDoc As AssemblyDocument
Set oDoc = oApp.ActiveDocument

Dim oDrawing As DrawingDocument
Set oDrawing = oApp.Documents.Add(kDrawingDocumentObject)

'oApp.SilentOperation = True

Dim oDXFSheet As Sheet
Set oDXFSheet = oDrawing.Sheets.Add(DrawingSheetSizeEnum.kA0DrawingSheetSize, PageOrientationTypeEnum.kLandscapePageOrientation, "DXF")
'Set oDXFSheet = oDrawing.ActiveSheet
'DXFSheet.name = "DXF"

Dim oUserProps As PropertySet
Set oUserProps = oDoc.PropertySets.Item("User Defined Properties")

Dim oPoint As Point2d
Dim oTG As TransientGeometry
Set oTG = oApp.TransientGeometry
Set oPoint = oTG.CreatePoint2d(0, 0)

Dim oPartDoc As PartDocument
Dim blnHasFlat As Boolean

Dim oPartProps As PropertySets

Dim dblSheetWidth As Double
Dim dblSheetHeight As Double

Dim oOcc As ComponentOccurrence
Dim oBOMView As BOMView
Set oBOMView = oDoc.ComponentDefinition.BOM.BOMViews.Item("Parts Only")
'Set oBOMView = oDoc.ComponentDefinition.BOM.BOMViews.Item("Structured")

Dim oView As DrawingView

Dim oBOMRow As BOMRow
Dim i As Integer
i = 1

Dim dblViewOffset As Double
dblViewOffset = 5

For Each oBOMRow In oBOMView.BOMRows
'get ipt
If oBOMRow.ComponentDefinitions.Item(1).Type = ObjectTypeEnum.kSheetMetalComponentDefinitionObject Then
Set oPartDoc = oBOMRow.ComponentDefinitions.Item(1).Document
Set oPartProps = oPartDoc.PropertySets 'you can get iproperty values to textboxes also

If oPartDoc.ComponentDefinition.Type = ObjectTypeEnum.kSheetMetalComponentDefinitionObject Then 'if you have controlling custom property that tells if dxf-view should be created put it also to this line with "AND"
If oPartDoc.ComponentDefinition.HasFlatPattern = True Then
'create drawing view
Dim oBaseViewOptions As NameValueMap
Set oBaseViewOptions = oApp.TransientObjects.CreateNameValueMap
Call oBaseViewOptions.Add("SheetMetalFoldedModel", False)

Set oView = oDXFSheet.DrawingViews.AddBaseView(oPartDoc, oPoint, 1, ViewOrientationTypeEnum.kDefaultViewOrientation, DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle, , , oBaseViewOptions)
'move view to new position
Dim newPos As Point2d
If i > 1 Then
Set newPos = oTG.CreatePoint2d(oDXFSheet.DrawingViews.Item(i - 1).Position.X + oDXFSheet.DrawingViews.Item(i - 1).Width / 2 + oView.Width / 2 + dblViewOffset, oDXFSheet.DrawingViews.Item(i).Height / 2 + dblViewOffset / 2)
oView.Position = newPos
'dblSheetWidth = dblSheetWidth + oDXFSheet.DrawingViews.Item(i).Width + dblViewOffset
ElseIf i = 1 Then
Set newPos = oTG.CreatePoint2d(oDXFSheet.DrawingViews.Item(i).Width / 2 + dblViewOffset / 2, oDXFSheet.DrawingViews.Item(i).Height / 2 + dblViewOffset / 2)
oView.Position = newPos

End If

'create text boxes for part info
Dim strPartnum As String
Dim strMaterial As String
Dim strItemQTY As String
strPartnum = "Part Number: " & oBOMRow.ItemNumber 'normally balloon value
strMaterial = "Material: " & oPartDoc.ComponentDefinition.Material.name
strItemQTY = "Item Quantity:" & oBOMRow.ItemQuantity & "Pcs"


'Add info to sheet
Dim oText1 As Inventor.GeneralNote
Dim oText2 As Inventor.GeneralNote
Dim oText3 As Inventor.GeneralNote

Dim oTxtPoint1 As Point2d
Dim oTxtPoint2 As Point2d
Dim oTxtPoint3 As Point2d

Dim dblOffset As Double
dblOffset = 1

Set oTxtPoint1 = oTG.CreatePoint2d(oView.Position.X, (oView.Position.Y - oView.Height / 2 - dblOffset))
Set oText1 = oDXFSheet.DrawingNotes.GeneralNotes.AddFitted(oTxtPoint1, strPartnum)

Set oTxtPoint2 = oTG.CreatePoint2d(oTxtPoint1.X, (oTxtPoint1.Y - dblOffset))
Set oText2 = oDXFSheet.DrawingNotes.GeneralNotes.AddFitted(oTxtPoint2, strMaterial)

Set oTxtPoint3 = oTG.CreatePoint2d(oTxtPoint2.X, (oTxtPoint2.Y - dblOffset))
Set oText3 = oDXFSheet.DrawingNotes.GeneralNotes.AddFitted(oTxtPoint3, strItemQTY)

i = i + 1
End If
End If
End If
Next

'save dxf
' Get the DXF translator Add-In.
Dim DXFAddIn As TranslatorAddIn
Set DXFAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")

Dim oContext As TranslationContext
Set oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = kFileBrowseIOMechanism

' Create a NameValueMap object
Dim oOptions As NameValueMap
Set oOptions = ThisApplication.TransientObjects.CreateNameValueMap

' Create a DataMedium object
Dim oDataMedium As DataMedium
Set oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

' Check whether the translator has 'SaveCopyAs' options
If DXFAddIn.HasSaveCopyAsOptions(oDrawing, oContext, oOptions) Then
Dim strIniFile As String
strIniFile = "C:\DXF_test.ini"

' Create the name-value that specifies the ini file to use.
oOptions.Value("Export_Acad_IniFile") = strIniFile
End If

'Set the destination file name
oDataMedium.filename = "c:\tempdxfout.dxf"

'Publish document.
Call DXFAddIn.SaveCopyAs(oDrawing, oContext, oOptions, oDataMedium)

End Sub

Message 11 of 22

tolgay.hickiran
Advisor
Advisor
Hey Risto, i managed to start your code but it stops at the last line

Call DXFAddIn.SaveCopyAs(oDrawing, oContext, oOptions, oDataMedium)

Do you happen to know what might be the problem? Cheers

Some worthwhile ideas
Copy Design should rename ilogic Rules too!
Why Nastran In-CAD doesn't have an SDK?IMPLEMENTED!

Tolgay Hickiran
Founding Partner
SignatureSignature

website
emailskypelinkedinyoutubeemail

0 Likes
Message 12 of 22

Anonymous
Not applicable
Did you copy the dxftest.ini file to c:? That is dxf configuration file.
0 Likes
Message 13 of 22

tolgay.hickiran
Advisor
Advisor
Yes i did indeed, i will try using it tomorrow again

Some worthwhile ideas
Copy Design should rename ilogic Rules too!
Why Nastran In-CAD doesn't have an SDK?IMPLEMENTED!

Tolgay Hickiran
Founding Partner
SignatureSignature

website
emailskypelinkedinyoutubeemail

0 Likes
Message 14 of 22

tolgay.hickiran
Advisor
Advisor
Hey risto,

USE CUSTOMIZE=Yes
CUSTOMIZE FILE=C:\Vault\Templates\Inventor Design Data\DWG-DXF\FlatPattern.xml

I changed this bit to USE CUSTOMIZE=No and remove the row below it worked.
Do you know any way to get Flat Pattern of a part without opening it?

Some worthwhile ideas
Copy Design should rename ilogic Rules too!
Why Nastran In-CAD doesn't have an SDK?IMPLEMENTED!

Tolgay Hickiran
Founding Partner
SignatureSignature

website
emailskypelinkedinyoutubeemail

0 Likes
Message 15 of 22

Anonymous
Not applicable

OK, good that you figured it out. I uploaded wrong ini-file. I had one with CUSTOMIZE=NO.

 

You can make the flat pattern with snippet below. This will change the part to sheet metal if normal part and do unfold. Thickness must be correct in sheet metal defaults.

 

Dim oDoc As PartDocument
Set oDoc = oApp.ActiveDocument

'create flat pattern
'Change Document.SubType to Sheetmetal
'oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" 'use this if you need to convert normal parts to sheet metal
'Create Sheet Metal definition
Dim oSM As SheetMetalComponentDefinition
Set oSM = oDoc.ComponentDefinition

'oSM.UseSheetMetalStyleThickness = False
'oSM.Thickness.Expression="??" 'you can set thickness here if ipt is converted from normal part to sheet metal. I think you have the correct thickness in parameters or iproperties. You can put here parameter name if you have parameter for thickness in model.

Call oSM.Unfold

0 Likes
Message 16 of 22

tolgay.hickiran
Advisor
Advisor
See this is the thing Risto,

This routine requires the part to be opened in inventor, what i'm asking is just by opening the assembly can we get a flat pattern of a part. There are couple of apps on autodesk exchange that can do this work.

Some worthwhile ideas
Copy Design should rename ilogic Rules too!
Why Nastran In-CAD doesn't have an SDK?IMPLEMENTED!

Tolgay Hickiran
Founding Partner
SignatureSignature

website
emailskypelinkedinyoutubeemail

0 Likes
Message 17 of 22

Anonymous
Not applicable

I just gave you the way you can do it for ipt. You can make a loop that iterates through all components in assembly(iam) and does that routine for each component. You can also make a macro that creates flat patterns for selected components for example, just need to now how you wan't it to work.

 

Is your plan to use this together with flat pattern dxf export? If it is, you can add that snippet inside the flat pattern export macro. Here is flat pattern creation added to dxf export code. So this will make flat pattern for sheet metal parts that has no flat pattern before creating the view. Is this what you need?

 

'Create sheet for sheetmetal parts with flatpattern
'Get Inventor and Document
Dim oApp As Inventor.Application
Set oApp = ThisApplication

Dim oDoc As AssemblyDocument
Set oDoc = oApp.ActiveDocument

Dim oDrawing As DrawingDocument
Set oDrawing = oApp.Documents.Add(kDrawingDocumentObject)

'oApp.SilentOperation = True

Dim oDXFSheet As Sheet
Set oDXFSheet = oDrawing.Sheets.Add(DrawingSheetSizeEnum.kA0DrawingSheetSize, PageOrientationTypeEnum.kLandscapePageOrientation, "DXF")
'Set oDXFSheet = oDrawing.ActiveSheet
'DXFSheet.name = "DXF"

Dim oUserProps As PropertySet
Set oUserProps = oDoc.PropertySets.Item("User Defined Properties")

Dim oPoint As Point2d
Dim oTG As TransientGeometry
Set oTG = oApp.TransientGeometry
Set oPoint = oTG.CreatePoint2d(0, 0)

Dim oPartDoc As PartDocument
Dim blnHasFlat As Boolean

Dim oPartProps As PropertySets

Dim dblSheetWidth As Double
Dim dblSheetHeight As Double

Dim oOcc As ComponentOccurrence
Dim oBOMView As BOMView
Set oBOMView = oDoc.ComponentDefinition.BOM.BOMViews.Item("Parts Only")
'Set oBOMView = oDoc.ComponentDefinition.BOM.BOMViews.Item("Structured")

Dim oView As DrawingView

Dim oBOMRow As BOMRow
Dim i As Integer
i = 1

Dim dblViewOffset As Double
dblViewOffset = 5

For Each oBOMRow In oBOMView.BOMRows
'get ipt
If oBOMRow.ComponentDefinitions.Item(1).Type = ObjectTypeEnum.kSheetMetalComponentDefinitionObject Then
Set oPartDoc = oBOMRow.ComponentDefinitions.Item(1).Document
Set oPartProps = oPartDoc.PropertySets 'you can get iproperty values to textboxes also

If oPartDoc.ComponentDefinition.Type = ObjectTypeEnum.kSheetMetalComponentDefinitionObject Then 'if you have controlling custom property that tells if dxf-view should be created put it also to this line with "AND"

If oPartDoc.ComponentDefinition.HasFlatPattern = False Then
'create flat pattern
Dim oSM As SheetMetalComponentDefinition
Set oSM = oPartDoc.ComponentDefinition

Call oSM.Unfold

End If

If oPartDoc.ComponentDefinition.HasFlatPattern = True Then
'create drawing view
Dim oBaseViewOptions As NameValueMap
Set oBaseViewOptions = oApp.TransientObjects.CreateNameValueMap
Call oBaseViewOptions.Add("SheetMetalFoldedModel", False)

Set oView = oDXFSheet.DrawingViews.AddBaseView(oPartDoc, oPoint, 1, ViewOrientationTypeEnum.kDefaultViewOrientation, DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle, , , oBaseViewOptions)
'move view to new position
Dim newPos As Point2d
If i > 1 Then
Set newPos = oTG.CreatePoint2d(oDXFSheet.DrawingViews.Item(i - 1).Position.X + oDXFSheet.DrawingViews.Item(i - 1).Width / 2 + oView.Width / 2 + dblViewOffset, oDXFSheet.DrawingViews.Item(i).Height / 2 + dblViewOffset / 2)
oView.Position = newPos
'dblSheetWidth = dblSheetWidth + oDXFSheet.DrawingViews.Item(i).Width + dblViewOffset
ElseIf i = 1 Then
Set newPos = oTG.CreatePoint2d(oDXFSheet.DrawingViews.Item(i).Width / 2 + dblViewOffset / 2, oDXFSheet.DrawingViews.Item(i).Height / 2 + dblViewOffset / 2)
oView.Position = newPos

End If

'create text boxes for part info
Dim strPartnum As String
Dim strMaterial As String
Dim strItemQTY As String
strPartnum = "Part Number: " & oBOMRow.ItemNumber 'normally balloon value
strMaterial = "Material: " & oPartDoc.ComponentDefinition.Material.name
strItemQTY = "Item Quantity:" & oBOMRow.ItemQuantity & "Pcs"


'Add info to sheet
Dim oText1 As Inventor.GeneralNote
Dim oText2 As Inventor.GeneralNote
Dim oText3 As Inventor.GeneralNote

Dim oTxtPoint1 As Point2d
Dim oTxtPoint2 As Point2d
Dim oTxtPoint3 As Point2d

Dim dblOffset As Double
dblOffset = 1

Set oTxtPoint1 = oTG.CreatePoint2d(oView.Position.X, (oView.Position.Y - oView.Height / 2 - dblOffset))
Set oText1 = oDXFSheet.DrawingNotes.GeneralNotes.AddFitted(oTxtPoint1, strPartnum)

Set oTxtPoint2 = oTG.CreatePoint2d(oTxtPoint1.X, (oTxtPoint1.Y - dblOffset))
Set oText2 = oDXFSheet.DrawingNotes.GeneralNotes.AddFitted(oTxtPoint2, strMaterial)

Set oTxtPoint3 = oTG.CreatePoint2d(oTxtPoint2.X, (oTxtPoint2.Y - dblOffset))
Set oText3 = oDXFSheet.DrawingNotes.GeneralNotes.AddFitted(oTxtPoint3, strItemQTY)

i = i + 1
End If
End If
End If
Next

'save dxf
' Get the DXF translator Add-In.
Dim DXFAddIn As TranslatorAddIn
Set DXFAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")

Dim oContext As TranslationContext
Set oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = kFileBrowseIOMechanism

' Create a NameValueMap object
Dim oOptions As NameValueMap
Set oOptions = ThisApplication.TransientObjects.CreateNameValueMap

' Create a DataMedium object
Dim oDataMedium As DataMedium
Set oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

' Check whether the translator has 'SaveCopyAs' options
If DXFAddIn.HasSaveCopyAsOptions(oDrawing, oContext, oOptions) Then
Dim strIniFile As String
strIniFile = "C:\DXF_test.ini"

' Create the name-value that specifies the ini file to use.
oOptions.Value("Export_Acad_IniFile") = strIniFile
End If

'Set the destination file name
oDataMedium.filename = "c:\tempdxfout.dxf"

'Publish document.
Call DXFAddIn.SaveCopyAs(oDrawing, oContext, oOptions, oDataMedium)

 

0 Likes
Message 18 of 22

tolgay.hickiran
Advisor
Advisor
RAS

What we are trying to do is to create flat patterns without opening parts one by one, we have a similar code structure like you posted and it does open the parts one by one and gets their flat pattern.

There is one particular program Dxf exporter on autodesk exchange which doesn't rely on opening parts inside an assembly one by one, thus it takes a really small time to create dxfs while having no flat patterns of the parts at the begining.

We are trying to achieve, getting these dxf files in say "10" seconds. (for around 200-300 unique parts that is). You could check the app on exchange, it is free for 30 days and you'll get what i mean.

Some worthwhile ideas
Copy Design should rename ilogic Rules too!
Why Nastran In-CAD doesn't have an SDK?IMPLEMENTED!

Tolgay Hickiran
Founding Partner
SignatureSignature

website
emailskypelinkedinyoutubeemail

0 Likes
Message 19 of 22

Anonymous
Not applicable

That code I pasted last does that in same time when exporting the dxf. It creates flat pattern if not exist.

Actually it does the same tricks than the dxf exporter(I tried that) except my code put all parts to same file, it can be exported also to each part to own sheet. File must be opened(at least in back round) to create flat patterns, but I think you mean you don't wan't open them one by one manually. 

 

Btw. Why don't you buy that app because it seems to work quite nice.

0 Likes
Message 20 of 22

tolgay.hickiran
Advisor
Advisor
If we had a rush i'd say we buy it but we don't. The challange here is to make an app as good as that one, we are working on that 🙂

Some worthwhile ideas
Copy Design should rename ilogic Rules too!
Why Nastran In-CAD doesn't have an SDK?IMPLEMENTED!

Tolgay Hickiran
Founding Partner
SignatureSignature

website
emailskypelinkedinyoutubeemail

0 Likes