Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Flat pattern from all sheet metal parts - Assembly to drawing

11 REPLIES 11
Reply
Message 1 of 12
CCarreiras
3145 Views, 11 Replies

Flat pattern from all sheet metal parts - Assembly to drawing

Hi!

 

How to produce drawings with Flat pattern from all sheet metal parts at once automatically?
The sheet metal parts are placed in one assembly, the goal is to get the flat pattern from all the parts without  open one by one.

 

Any ideas?

 

Thanks.

CCarreiras

EESignature

11 REPLIES 11
Message 2 of 12
waynehelley
in reply to: CCarreiras

Hi Carlos,

 

As we discussed, here is the code I created which writes a Flat Pattern DXF for every '.ipt' in a specified folder.  This may be a good starting point for somebody to adjust so that it runs for all parts in a specified assembly.

 

Just so you know... The snippet 'OuterProfileLayer=PROGP&InteriorProfilesLayer=PROGI' exists because we have set our lazer cutting software to cut these 2 layers and ignore any other layers (so that fold lines etc don't get cut).

 

Public Sub Batch_Write_Flat_Pattern()

If MsgBox("This Macro will write flat patterns so that they are live. Are you sure you want to do this?", vbOKCancel + vbExclamation, "Batch Write Flat Pattern") = vbCancel Then Exit Sub

Dim MyFile As String, Sep As String

' Sets up the variable "MyFile" to be each file in the directory
' This example looks for all the files that have an .ipt extension.
' This can be changed to whatever extension is needed. Also, this
' macro searches the current directory. This can be changed to any
' directory.

Dim Directory As Variant
Directory = InputBox("Please specify file location of the parts.", "Batch Write Flat Pattern", "C:\Batch Write Flat Pattern")

' Test for Windows or Macintosh platform. Make the directory request.
Sep = Application.PathSeparator


' Windows platform search syntax.
MyFile = Dir(Directory & Sep & "*.ipt")

 

' Starts the loop, which will continue until there are no more files
' found.

Do While MyFile <> ""

' Displays a message box with the name of the file. This can be
' changed to any procedure that would be needed to run on every
' file in the directory such as opening each file.



'opens file:
ThisApplication.SilentOperation = True
Set oInv = ThisApplication.Documents.Open(Directory & Sep & MyFile)

'Set oDoc = ThisApplication.ActiveDocument

Dim partDoc As PartDocument
'Dim partRef As ReferencedFileDescriptor
Set partDoc = ThisApplication.ActiveDocument

Dim oPropSet As PropertySet
Dim oProp As Inventor.Property

Dim invPartNoProperty As Property

Set invPartNoProperty = partDoc. _
PropertySets.Item("Design Tracking Properties").Item("Part Number")


PartNumber = invPartNoProperty.Value

' Get the DataIO object.
Dim oDataIO As DataIO
Set oDataIO = partDoc.ComponentDefinition.DataIO

' Create the DXF file.
'oDataIO.WriteDataToFile "FLAT PATTERN DXF?AcadVersion=2007&OuterProfileLayer=PROGP&InteriorProfilesLayer=PROGI", "c:\TEMP\" & PartNumber & ".dxf"
't = MsgBox("Flat pattern DXF was written to C:\TEMP\" & PartNumber & ".dxf", vbOKOnly, "Write Flat Pattern")


Set partDoc = Nothing
Set oPropSet = Nothing
Set oProp = Nothing
Set invPartNoProperty = Nothing


oInv.Close False
ThisApplication.SilentOperation = False



MyFile = Dir()
Loop

t = MsgBox("Flat pattern DXFs were written to C:\TEMP\" & PartNumber & ".dxf and to Vault.", vbOKOnly, "Batch Write Flat Pattern")
'Set t = Nothing

End Sub

 

Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
Message 3 of 12
CCarreiras
in reply to: waynehelley

Hi!

 

We can use this code directly in iLogic Rule.

 

I tried, but it gives me errors.

 

0.png

CCarreiras

EESignature

Message 4 of 12
waynehelley
in reply to: CCarreiras

The code is in VBA so you will have to run it through the VBA edittor. Do you know how to do this??

 

I'm not sure if it would be possible to convert the code to iLogic due to the limitations of iLogic.

Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
Message 5 of 12
CCarreiras
in reply to: waynehelley

Hi!

 

I never tried with VB, only with iLogic.

 

Can you give me some lights? or some docs?

 

Thank you.

CCarreiras

EESignature

Message 6 of 12
waynehelley
in reply to: CCarreiras

I'm not sure what you mean by lights!  You should be able to see 'VBA Editor' if you select Tools on the ribbon toolbar.

 

The interface may be a bit daunting at first but if you go to File -> New Project, you should be able to figure it out!  This might help... 

 

http://download.autodesk.com/us/community/mfg/Part_1.pdf

 

I find it quite useful to use VBA over iLogic for things like this, especially since you can create your own User Command buttons for the macros you create Smiley Happy

 

Capture.PNG

 

 

Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
Message 7 of 12
rjay75
in reply to: CCarreiras

Hello, Carlos, here is Wayne's code modified to run as an iLogic rule.

 

Sub Main()
	If MsgBox("This Macro will write flat patterns so that they are live. Are you sure you want to do this?", vbOKCancel + vbExclamation, "Batch Write Flat Pattern") = vbCancel Then Exit Sub
	Dim MyFiles As String()
	' Sets up the variable "MyFile" to be each file in the directory
	' This example looks for all the files that have an .ipt extension.
	' This can be changed to whatever extension is needed. Also, this
	' macro searches the current directory. This can be changed to any
	' directory.
	Dim Directory As String
	Directory = InputBox("Please specify file location of the parts.", "Batch Write Flat Pattern", "C:\Batch Write Flat Pattern")
	
	'search for files.
	MyFiles = System.IO.Directory.GetFiles(Directory, "*.ipt")
	
	' Starts the Loop, which will Continue Until there are no more files
	' found.
	For Each MyFile As String In MyFiles
		' Displays a message box with the name of the file. This can be
		' changed to any procedure that would be needed to run on every
		' file in the directory such as opening each file.
		'opens file:
		ThisApplication.SilentOperation = True
		Dim partDoc As Document = ThisApplication.Documents.Open(MyFile, False)
		
		'Test to make sure we opened a sheet metal part
		If(partDoc.DocumentSubType.DocumentSubTypeID.Equals("{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}")) Then
			Dim oPropSet As PropertySet
			Dim oProp As Inventor.Property
			Dim invPartNoProperty As Inventor.Property = partDoc. _
			PropertySets.Item("Design Tracking Properties").Item("Part Number")				
			PartNumber = invPartNoProperty.Value
			' Get the DataIO object.
			Dim oDataIO As DataIO = partDoc.ComponentDefinition.DataIO
			' Create the DXF file.
			oDataIO.WriteDataToFile("FLAT PATTERN DXF?AcadVersion=2007&OuterProfileLayer=PROGP&InteriorProfilesLayer=PROGI", "c:\TEMP\" & PartNumber & ".dxf")
			oPropSet = Nothing
			oProp = Nothing
			invPartNoProperty = Nothing
		End If
		
		partDoc.Close(False)
		partDoc = Nothing
		ThisApplication.SilentOperation = False
	Next
	
	MsgBox("Flat pattern DXFs were written to C:\TEMP\" & PartNumber & ".dxf and to Vault.", vbOKOnly, "Batch Write Flat Pattern")
End Sub 

 

Message 8 of 12
waynehelley
in reply to: rjay75

Thanks Rodney.  I wasn't sure if that would be possible.  It gives me an error though. Does it run okay for you two?

Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
Message 9 of 12
Anonymous
in reply to: waynehelley

Hi waynehelley,

 

I tried running your code on vba editor.

Firstly, I feel the command line SEP = Application.PathSeperator needs to be modified to SEP = "Application.PathSeperator" as it shows an error.

Secondly, it should ask for a specific assembly right. but it doesn't ask for any.

 

Could you please help me out ? i am using Inventor 2011.

 

Thanks,

Sid

Message 10 of 12
waynehelley
in reply to: Anonymous

Hi Sid,

 

That code is for creating flat patterns of all parts in a specified folder.  I posted it as I though it would be a good starting point for somebody to modifiy into code which creates flat patterns of all parts within an assembly.

Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
Message 11 of 12
Anonymous
in reply to: waynehelley

Hi

Thank you for these code. Its great.
I am so noob..... but.

I need to save the dxf file with the project name. How I can added the project name in the save path ("c:\TEMP\"& Project &"" & PartNumber & ".dxf")?

 



Message 12 of 12
w.landkoer
in reply to: waynehelley

Hi,

 

Am I correct if I say that this actually doens't create Flat Patterns? 

It probably creates them temporary and then exports them to DXF, which is okay of course.

That part works :o)

 

But I don't see aan Flat Pattern which would be visible in the Brower.

Is there a way to add that to the code?

 

I need this for my Parts List, where it puts the Extents of a Flat Pattern.

 

Thank you,

 

Wesley Landkoer

Inventor 2016

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report