Need help on Flat pattern export to dxf (VBA)

Need help on Flat pattern export to dxf (VBA)

Anonymous
Not applicable
4,059 Views
9 Replies
Message 1 of 10

Need help on Flat pattern export to dxf (VBA)

Anonymous
Not applicable

I am trying to develop a macro that exports all flat patterns for sheet metal components. I haven't been able to get the following code to work.  It give the error message "The document you are trying to save is not a drawing document" (please see snap shot of the error mesage).  could someone  please review the code to see what is wrong here.  thanks in advance.

Sub PublishDXF()
    Dim DXFAddIn As TranslatorAddIn
    Set DXFAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")
    Dim oDocument As PartDocument
    Set oDocument = ThisApplication.ActiveDocument
    Dim oContext As TranslationContext
    Set oContext = ThisApplication.TransientObjects.CreateTranslationContext
    oContext.Type = kFileBrowseIOMechanism
    Dim oOptions As NameValueMap
    Set oOptions = ThisApplication.TransientObjects.CreateNameValueMap
    Dim oDataMedium As DataMedium
    Set oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
    FullDXFfileNamePath = TargetFolder.Value & "\" & Left(oDocument.DisplayName, Len(oDocument.DisplayName) - 4) & ".dxf"
    ' Check whether the translator has 'SaveCopyAs' options
    If DXFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then

        Dim strIniFile As String
        strIniFile = "C:\vba test\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 = FullDXFfileNamePath
    'Publish document.
    'Call DXFAddIn.SaveCopyAs(oDocument, oContext, oDataMedium)
    Call DXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End Sub

 

0 Likes
4,060 Views
9 Replies
Replies (9)
Message 2 of 10

Anonymous
Not applicable

Are you intending to export the DXF from the flat pattern itself or a drawing of the flat pattern?

0 Likes
Message 3 of 10

Anonymous
Not applicable

I tried to export from the flat pattern itself. Look like right now this method is not support.  Is there any other way to do this without using the dataIO.  Thanks for the reply.

 

tvn

0 Likes
Message 4 of 10

Anonymous
Not applicable

The tanslator addin can only be used with a drawing document hence error if you try and use it from a part.

 

The following bit of code may get you started

 

 

' Get all of the referenced documents from an assembly
Dim oRefDocs As DocumentsEnumerator
Set oRefDocs = oAsmDoc.AllReferencedDocuments

' Iterate through the list of documents.
Dim oRefDoc As Document
Dim oSheetMetalCompDef As SheetMetalComponentDefinition
Dim oFlatPattern As FlatPattern

 

For Each oRefDoc In oRefDocs
    If oRefDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
         Set oFlatPattern = oRefDoc.ComponentDefinition.FlatPattern
                dxfFileName = dirPath & Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName) - 4) & ".dxf"
                Dim oDataIO As DataIO
                Set oDataIO = oRefDoc.ComponentDefinition.DataIO
                Dim sOut As String
                sOut = "FLAT PATTERN DXF?AcadVersion=R12&OuterProfileLayer=CUT&InteriorProfilesLayer=CUT&SplineTolerance Double 0.01 &InvisibleLayers=IV_TANGENT;IV_BEND"
                oDataIO.WriteDataToFile sOut, dxfFileName
    End If
Next

0 Likes
Message 5 of 10

Anonymous
Not applicable

Thanks for the quick reply.  I implement the code and it works.  but  now I want to change a IV_BEND layer color to "Yellow" when export to dxf.  Is it posible to change the color of the layer or the line type?  thanks

 

tvn

0 Likes
Message 6 of 10

Anonymous
Not applicable

Well, no but yes...

 

Two options exist if I remember -

 

1) DXF's are text files so use IV's VBA to read the DXF file line by line find the line that defines the IV_BEND layer colour and reset it to 'Yellow'.

or

2) Extend the IV VBA macro to open ACAD and load the DXF file then use a ACAD VBA macro to automatically change the IV_BEND layer to 'Yellow' and resave the file as a DXF.

 

Good luck.

0 Likes
Message 7 of 10

Anonymous
Not applicable

Thank you, look like for now that is the only two options.  I hope AutoDesk would add this option to IV 2012.

 

Thanks,

 

Tvn

0 Likes
Message 8 of 10

Rene-J
Collaborator
Collaborator

Hi 

it is possible to change color in 2011 see Api help.

 

have you try  this free addin

iFlatpatternExport Add-in

 http://www.mcadforums.com/forums/viewtopic.php?f=34&t=11249

 

René J

0 Likes
Message 9 of 10

Anonymous
Not applicable

Ah, don't have IV 2011  Smiley Sad

0 Likes
Message 10 of 10

Anonymous
Not applicable

What References are need in VB6?

0 Likes