Export into "dxf" the flat pattern part since the drawing part (VBA)

Export into "dxf" the flat pattern part since the drawing part (VBA)

Anonymous
Not applicable
2,247 Views
8 Replies
Message 1 of 9

Export into "dxf" the flat pattern part since the drawing part (VBA)

Anonymous
Not applicable

Hi,

 

From the "Inventor 2015 API", I taken the code below :

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

From this, I want to generate a dxf file of flat pattern part, but since drawing.

With this informations "PartNumber (drawing)" & "text" & "RevisionNumber (drawing) & ".dxf"

 

Currently, I've a macro which export my drawing into ".dxf", and not only the flat pattern but all views.

 

What code allow to execute the code the since drawing file and not the part file.

 

Thanks by advance.

0 Likes
Accepted solutions (1)
2,248 Views
8 Replies
Replies (8)
Message 2 of 9

raith-mb
Advocate
Advocate

Hi,

 

you have to run the function from a IPT.

 

Public Sub WriteSheetMetalDXF()
    ' Get the active document.  This assumes it is a part document.

 

Roland

0 Likes
Message 3 of 9

Anonymous
Not applicable

I understand, but a solution must exist, no ? for this :

  1. To open the part since the drawing.
  2. Run the macro (dxf)
  3. Close the part and comeback to the drawing

For the filename with the part number, I tried this code, but it's doesn't work :

 

'Set Part Number
Dim oPartNumber As Property
Dim PartNumber As String
Set oPartNumber = oDocument.PropertySets.Item("Design Tracking Properties").Item("Part Number")

'Set the destination file name
oData.FileName = "C:\testfile" & PartNumber & ".dxf"

 I get "testfile.dxf" and not "testfile+part number.dxf"

 

Did I forgotten something ?

0 Likes
Message 4 of 9

adam.nagy
Autodesk Support
Autodesk Support

Hi,

 

There is a typo in the code, it should be: 

oData.FileName = "C:\testfile" & oPartNumber & ".dxf"

 

When you open a drawing the referenced document also gets opened in the background and you can access it as shown in this article through the ReferencedDocumentDescriptor:

http://adndevblog.typepad.com/manufacturing/2013/06/set-visibility-of-sketch-in-sub-assembly.html

 

Cheers,



Adam Nagy
Autodesk Platform Services
Message 5 of 9

Anonymous
Not applicable

I forgot one line

    'Set Part Number
    Dim oPartNumber As Property
    Dim PartNumber As String
    Set oPartNumber = oDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number")
        PartNumber = CStr(oPartNumber.Value)
    
    ' Create the DXF file.
    oDataIO.WriteDataToFile sOut, "C:\temp" & PartNumber & ".dxf"

 

Now, we must successfully open the part from the drawing.

I'm trying to find a solution with your link.

0 Likes
Message 6 of 9

Anonymous
Not applicable

I succeed !
Below, the full code for a DXF file of flat pattern from the drawing with like filename : Part number + revision (if it exists)

Public Sub WriteSheetMetalDXF()

    Dim dwg As DrawingDocument
    Set dwg = ThisApplication.ActiveDocument
    
    Dim baseView As DrawingView
    Set baseView = dwg.Sheets(1).DrawingViews(1)
    
    Dim mainPRT As PartDocument
    Set mainPRT = baseView.ReferencedDocumentDescriptor.ReferencedDocument
    
    ' Get the DataIO object.
    Dim oDataIO As DataIO
    Set oDataIO = mainPRT.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"

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

    'Set Part Number
    Dim oPartNumber As Property
    Dim PartNumber As String
    Set oPartNumber = oDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number")
        PartNumber = CStr(oPartNumber.Value)

    'Set Revision
    Dim oRevision As Property
    Dim Revision As String
    Set oRevision = oDoc.PropertySets.Item("Inventor Summary Information").Item("Revision Number")
        If oRevision.Value = "" Then
            oDataIO.WriteDataToFile sOut, "C:\" & PartNumber & ".dxf"
        Else
            Revision = "_" + CStr(oRevision.Value)
            oDataIO.WriteDataToFile sOut, "C:\" & PartNumber & Revision & ".dxf"
        End If
    
End Sub
Message 7 of 9

Anonymous
Not applicable

Hello,

 

I would like to evolve the macro by using an ini file to customize the name of the layers and colors.
I found this code, but I don't know how to fit it.

 

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

        Dim strIniFile As String
        strIniFile = "C:\tempDXFOut.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(oDocument, oContext, oOptions, oDataMedium)
End Sub

Thank you in advance for your help.

0 Likes
Message 8 of 9

Anonymous
Not applicable
Accepted solution

Finally, I managed to rename and customize the colors without using an.ini file

Here's the code:

Public Sub PublishDXF()

    'Get the part from drawing
    Dim dwg As DrawingDocument
    Set dwg = ThisApplication.ActiveDocument

    Dim baseView As DrawingView
    Set baseView = dwg.Sheets(1).DrawingViews(1)

    Dim mainPRT As PartDocument
    Set mainPRT = baseView.ReferencedDocumentDescriptor.ReferencedDocument

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

    ' Build the string that defines the format of the DXF file.
    Dim sOut As String

    sOut = "FLAT PATTERN DXF?&AcadVersion=2004"
    sOut = sOut & "&OuterProfileLayer=DECOUPE_EXTERNE"
    sOut = sOut & "&InteriorProfilesLayer=DECOUPE_INTERNE"
    sOut = sOut & "&FeatureProfilesLayer=GRAVURE"
    sOut = sOut & "&FeatureProfilesUpLayerColor=255;0;0"
    sOut = sOut & "&FeatureProfilesDownLayerColor=255;0;0"
    sOut = sOut & "&UnconsumedSketchesLayer=GRAVURE_ESQUISSE"
    sOut = sOut & "&UnconsumedSketchesLayerColor=255;0;0"
    sOut = sOut & "&BendLayer=LIGNE_PLIAGE"
    sOut = sOut & "&BendUpLayerColor=0;255;0"
    sOut = sOut & "&BendUpLayerLineType=37644"
    sOut = sOut & "&BendDownLayerColor=0;255;0"
    sOut = sOut & "&BendDownLayerLineType=37644"
    sOut = sOut & "&ToolCenterLayer=CENTRE_OUTILS"
    sOut = sOut & "&ToolCenterUpLayerColor=255;0;255"
    sOut = sOut & "&ToolCenterDownLayerColor=255;0;255"
    sOut = sOut & "&ArcCentersLayer=CENTRE"
    sOut = sOut & "&ArcCentersLayerColor=255;0;255"
    sOut = sOut & "&InvisibleLayers=IV_TANGENT;IV_ALTREP_FRONT;IV_ALTREP_BACK;IV_ROLL_TANGENT;IV_ROLL"
    sOut = sOut & "&SplineTolerance=0,001"

    'Set a reference to the active document (the document to be published).
    Dim oDoc As Document
    Set oDoc = ThisApplication.ActiveDocument
    
    'Set destination and filename with part number and revision
    Dim oPartNumber As Property
    Dim PartNumber As String
    Set oPartNumber = oDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number")
    PartNumber = CStr(oPartNumber.Value)
    
    Dim oRevision As Property
    Dim Revision As String
    Set oRevision = oDoc.PropertySets.Item("Inventor Summary Information").Item("Revision Number")
    
    Dim oRevisionValue As String
    oRevisionValue = CStr(oRevision.Value)
    
    If oRevision.Value = "" Then
    Revision = CStr(oRevision.Value)
    Else
    Revision = "_" & CStr(oRevision.Value)
    End If
    oDataIO.WriteDataToFile sOut, "C:\TEMP\" & PartNumber & Revision & ".dxf"
End Sub
Message 9 of 9

jacsoa
Participant
Participant

Hi,

 

I would like to change the "Mark Surface (front)" layer color, but the "&MarkSurfaceUpLayerColor=255;255;0" doesn't work. I tried with a lot of names (MarkSurfaceFront, MarkFaceUp....), but couldn't find the right one.
Could you help me what is the proper name of the mark feature layer? 

0 Likes