Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations Ron247 on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Export FLAT Pattern with a name equal to an attribut

Status
Not open for further replies.

PSI-CAD

Computer
Feb 13, 2009
997
Hi,

The below steps of the attached journal work well:

- Check for flat pattern => OK

- Check for existing attribut "DXF" => OK

I have 2 questions

1°) How to change the below line to export the flat pattern included in the part without giving the name ?

Dim flatPattern1 As NXOpen.Features.FlatPattern = CType(workPart.Features.FindObject("FLAT_PATTERN(13)"), NXOpen.Features.FlatPattern)

2°) How to create a dxf file with the name of the DXF attribut ?

Thanks in advance

Regards
Didier Psaltopoulos
 
Replies continue below

Recommended for you

Hi Cowski,

I forgot to say that I prefer using file export dxf (with only included flat pattern) because export flat pattern doesn't respect original layers. (another thread)

Thanks in advance

Regards
Didier Psaltopoulos
 
Hi Cowski,

Thanks a lot. This code could be OK but the original layers are not respected. Have a look at the given example

Regards
Didier Psaltopoulos
 
Hi Cowski,

No, I need to export a dxf of the modeling flat pattern entities

I am not obliged to have a sheet and in the given example, I have no sheet.

In fact I tried during a NX session

1°)
Export Flat Pattern
==> the result in AUTOCAD is not good regarding to the layers (entities

2°)
Display Flat Pattern View
File Export DXF then I select the Flat Pattern entities
The result in AUTOCAD is OK (entities remain in layer 250 and 251 for some part)

I would like the same action (2°)) with a journal.

Thanks in advance

Regards
Didier Psaltopoulos
 
What is "DXF_Attribut", is it the desired output file's full path (such as "C:\output\somefile.dxf"), or does it hold the folder path that you want to export to (such as "C:\output\), or is it something else entirely?

You'll want to modify the code below to verify and make use of the "DXF_Attribut" variable; but I think the rest of the code does what you want.

Code:
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF

Module Module2

    Dim theSession As Session = Session.GetSession()
    Dim theUfSession As UFSession = UFSession.GetUFSession()
    Dim workPart As Part = theSession.Parts.Work
    Dim lw As ListingWindow = theSession.ListingWindow


    Sub Main()

        ' Vérification de l'existence d'un flat pattern

        lw.Open()
        Dim dxfFile As String = workPart.FullPath.Replace(".prt", ".dxf")



        Dim myFlatPattern As Features.FlatPattern = GetFlatPattern()
        If IsNothing(myFlatPattern) Then
            lw.WriteLine("Fin du programme car la part ne contient pas de Flat Pattern")
            Exit Sub
        End If

        Dim DXF_Attribut As String = ""

        'retrieve DXF attribute
        Try
            DXF_Attribut = workPart.GetStringUserAttribute("DXF", -1)
        Catch ex As Exception
            While DXF_Attribut = ""
                DXF_Attribut = InputBox("Enter DXF Attribut", "DXF_Attribut", "")
            End While
            workPart.SetUserAttribute("DXF", -1, DXF_Attribut, Update.Option.Now)
        End Try

        'code to verify DXF_Attribut is a valid folder/file path, create folder if needed

        'export flat pattern to dxf
        'lw.WriteLine("exporting dxf to: " & dxfFile)
        ExportDxf(myFlatPattern, dxfFile)

        lw.Close()

    End Sub

    Function GetFlatPattern() As Features.FlatPattern

        If IsNothing(theSession.Parts.Work) Then
            'active part required
            Return Nothing
        End If

        For Each myFeature As Features.Feature In workPart.Features
            If TypeOf (myFeature) Is Features.FlatPattern Then
                Return myFeature
            End If
        Next

        'if we make it here, no flat pattern was found
        Return Nothing

    End Function

    Sub ExportDxf(ByVal theFlatPattern As Features.FlatPattern, ByVal outputFile As String)


        Dim myFlatPatternBuilder As Features.SheetMetal.FlatPatternBuilder = workPart.Features.SheetmetalManager.CreateFlatPatternBuilder(theFlatPattern)
        Dim flatPatternViewName As String = myFlatPatternBuilder.FlatPatternViewName
        'lw.WriteLine("flat pattern view name: " & flatPatternViewName)
        myFlatPatternBuilder.Destroy()

        Dim dxfdwgCreator1 As DxfdwgCreator
        dxfdwgCreator1 = theSession.DexManager.CreateDxfdwgCreator()

        With dxfdwgCreator1
            .ExportData = DxfdwgCreator.ExportDataOption.Modeling
            .ViewEditMode = True
            .InputFile = workPart.FullPath
            .OutputFile = outputFile
            .ObjectTypes.Curves = True
            .ObjectTypes.Annotations = True
            .ObjectTypes.Structures = True
            .AutoCADRevision = DxfdwgCreator.AutoCADRevisionOptions.R2010
            .FlattenAssembly = False
            .WidthFactorMode = DxfdwgCreator.WidthfactorMethodOptions.AutomaticCalculation
            .LayerMask = "*"
            .ViewList = flatPatternViewName

        End With

        Dim nXObject2 As NXObject
        nXObject2 = dxfdwgCreator1.Commit()

        dxfdwgCreator1.Destroy()


    End Sub

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

    End Function

End Module

www.nxjournaling.com
 
Thanks a lot cowski,

I succeed by adding the following lines:

'code to verify DXF_Attribut is a valid folder/file path, create folder if needed

Dim dxfFile As String = "c:\temp\" + DXF_Attribut + ".dxf"

The result is perfect

Now, I have just to go through all part in assembly.


Regards
Didier Psaltopoulos
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor