It is currently Thu May 23, 2013 1:16 am

All times are UTC





Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: VBA Flat pattern export
PostPosted: Sun Feb 17, 2008 8:34 pm 
Offline
MCAD Lurker

Joined: 29 May 2007
Posts: 11
I am trying to develop a macro that exports all flat patterns for sheet metal components within a given assembly/folder etc. I haven't been able to find any examples of saving flat patterns from a vba macro.

The following code loops thru an active documents children and can determine if the part is of sheet metal subtype. It creates a flat pattern if one doesn't exist. (probably error prone). My stumbling block comes when I am trying to save the flat pattern as a dxf file.

Public Sub ExportFlatPatterns()
'this macro loops thry all children of the active document
'It checks to see if the child is a sheetmetal part type
'Then It creates a flat pattern if one does not exist.
'It saves the flat pattern to a specified file path.

' Get the active document
Dim invDoc As Document
Set invDoc = ThisApplication.ActiveDocument

'loop thru all the active document's children
Dim RefDoc As PartDocument
For Each RefDoc In invDoc.AllReferencedDocuments

'Determine if the RefDoc is a sheet metal part
If RefDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
Debug.Print "Sheet metal part: " & RefDoc.DisplayName
Dim RefSheetMetal As SheetMetalComponentDefinition
Set RefSheetMetal = RefDoc.ComponentDefinition

Debug.Print "Flat Pattern Found: " & RefSheetMetal.HasFlatPattern
If RefSheetMetal.HasFlatPattern = False Then
RefSheetMetal.Unfold
Debug.Print "Flat Pattern Created: "; RefSheetMetal.HasFlatPattern
'##########This is where I need some help##########################################################################
' export the flat pattern to a specified directory


End If
End If
Next

End Sub

_________________
Ed W. Cler
CIAMSUG President
Engineering Manager
Paul's Machine & Welding


Share on FacebookShare on TwitterShare on DiggShare on DeliciousShare on TumblrShare on Google+
Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 18, 2008 10:55 am 
Offline
MCAD Addict

Joined: 02 Mar 2005
Posts: 764
I thought I once sent you some code on this matter??

(Yes, e-mail dated 7th August 2007)


Last edited by PeterCharles on Mon Feb 18, 2008 8:05 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 18, 2008 11:14 am 
Offline
Content Manager

Joined: 20 Feb 2004
Posts: 698
Country: Netherlands
State: Non US/CAN Resident
CAD System: Wildfire-ProE
There are multiple examples in the Programming Helpfile of Inventor:

Inventor-->Help-->Programming Help
Contents-->Samples

A) Translator Addin - Export to DXF

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

    'Set a reference to the active document (the document to be published).
    Dim oDocument As Document
    Set oDocument = ThisApplication.ActiveDocument

    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(oDataMedium, oContext, oOptions) Then

        Dim strIniFile As String
        strIniFile = "C:\temp\DXFOut.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:\temp\dxfout.dxf"

    'Publish document.
    Call DXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End Sub


B) Export Sheet Metal to DXF using the DataIO object

Code:
Public Sub WriteSheetMetalDXF()
    ' Get the active document. This assumes it is a part document.
    Dim oDoc As PartDocument
    Set oDoc = ThisApplication.ActiveDocument

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

    ' Build the string that defines the format of the DXF file.
    Dim sOut As String
    sOut = "FLAT PATTERN DXF?AcadVersion=R12&OuterProfileLayer=Outer"

    ' Create the DXF file.
    oDataIO.WriteDataToFile sOut, "c:\temp\flat2.dxf"
End Sub


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 18, 2008 5:07 pm 
Offline
MCAD Lurker

Joined: 29 May 2007
Posts: 11
Teun ,
I found that the code for the dataIO method had some errors in it.
In order for me to get it going, I had to change the oDoc dim statement from "As PartDocument" to "As Document". I also changed AcadVersion=R12 to AcadVersion=2000. Thanks for the help.

Code:

Public Sub WriteSheetMetalDXF()
    ' Get the active document. This assumes it is a part document.
    Dim oDoc As Document
    Set oDoc = ThisApplication.ActiveDocument

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

    ' Build the string that defines the format of the DXF file.
    Dim sOut As String
    sOut = "FLAT PATTERN DXF?AcadVersion=2000&OuterProfileLayer=Outer"

    ' Create the DXF file.
    oDataIO.WriteDataToFile sOut, "c:\temp\flat2.dxf"
End Sub


Is there a guide for better using the help system? It looks like all the information is there, I just don't know how to find it.

Thanks for the help.

_________________
Ed W. Cler
CIAMSUG President
Engineering Manager
Paul's Machine & Welding


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 19, 2008 8:16 am 
Offline
Content Manager

Joined: 20 Feb 2004
Posts: 698
Country: Netherlands
State: Non US/CAN Resident
CAD System: Wildfire-ProE
Quote:
I found that the code for the dataIO method had some errors in it.


Errors? Strange...the code supplied works fine, no modifications are necessary (at least, in my case). I copied the code directly from the sample in the Programming Help File.

Quote:
Is there a guide for better using the help system? It looks like all the information is there, I just don't know how to find it


A better guide? Not realy I am afraid :( . The ammount of samples is limited (compared to AutoCAD examples). Just read and test the examples, modify them and see what happens. It's mostly trial and error :).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 20, 2008 3:58 pm 
Offline
MCAD Lurker

Joined: 29 May 2007
Posts: 11
Thanks Teun.

_________________
Ed W. Cler
CIAMSUG President
Engineering Manager
Paul's Machine & Welding


Top
 Profile  
 
PostPosted: Tue Jan 05, 2010 9:00 am 
Offline
MCAD Contributer

Joined: 13 Apr 2005
Posts: 58
I know this thread is old. But I will try anyway

I use the code "EWCLER" posted. But I would like to remove all bend lines ect. How do I define witch layers to export?


Top
 Profile  
 
PostPosted: Thu Jan 19, 2012 8:46 am 
Offline
MCAD Lurker

Joined: 26 Nov 2007
Posts: 1
OK still knowing this is old.
Try with
sOut = "FLAT PATTERN DXF?AcadVersion=R12&OuterProfileLayer=Outer&InvisibleLayers=IV_Tangent;IV_Bend;IV_Bend_Down;IV_Bend_Up"
Br Browsem


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
POWERED_BY