Showing results for 
Search instead for 
Do you mean 
Reply
Solved! Go to solution

Journal/Macro: Export objects from layer to IGS

Hello,

 

Is there any solution of exporting objects from layers to different IGES files. Exported files should have its own CSys and name of layer category? So far I made macro that ask me to choose objects from layers, name it and choose CSyS and then export. In case I have 40 layers its very time-consuming.

 

Best regards,

Sebastian

9 REPLIES

Re: Journal/Macro: Export objects from layer to IGS

It is possible to create a NXOpen API journal or DLL to do this, see the DexManager namespace in the NXOpen API reference.

This namespace is the base for all translators.

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX11.0 EAP, NX12.0 EAP

How to Get the Most from Your Signature in the Community

Re: Journal/Macro: Export objects from layer to IGS

Thanks for reply, I have problem with localize CSyS on layer and get its coordinate to journal. Do you have any ideas?

 

regards,

Sebastian 

Re: Journal/Macro: Export objects from layer to IGS

You could use the method NXOpen.Part.Layers.GetAllObjectsOnLayer(n) and check what objects need to be exported to IGES.

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX11.0 EAP, NX12.0 EAP

How to Get the Most from Your Signature in the Community

Re: Journal/Macro: Export objects from layer to IGS

Thanks you very much, journal is exporting objects from "n" layer to IGES with specyfic CSyS as expected ! 

 

I have second problem with using declared variable for name of exported files: 


Dim layer as Double = 1
'User input for the layer
layer = NXInputBox.GetInputNumber("Select the number of layer to export to IGS:", "number", layer)

 

How do I link this variable in address like below?

 

igesCreator1.OutputFile = "C:\Desktop\(value of variable).igs"

 

 

Regards,

Sebastian

 

Re: Journal/Macro: Export objects from layer to IGS

[ Edited ]

The IO.Path.Combine method is good for this, it will add the necessary path separators.

 

Dim filepath As String = "C:\Desktop"
Dim filename As String = "somefile"
'code to set or change the filepath and/or filename values as desired
IgesCreator1.OutputFile = IO.Path.Combine(filepath, filename & ".igs")

 

 

The DIY method is simply to build a string value:

Dim filename as string = "somefile"

IgesCreator1.OutputFile = "C:\Desktop\" & filename & ".igs"

Re: Journal/Macro: Export objects from layer to IGS

My journal is done, thanks to you guys !!

 

Regards,

Sebastian

Re: Journal/Macro: Export objects from layer to IGS

Hello,

 

I want to update name of exported files with description of layer category.

 

So far I tried method below but without success.

 

'Get the layer category name with given category number(name) for example 10.
Dim categorydesc As Layer.Category
categorydesc = Layer.Category.Description(10)

 

igesCreator1.OutputFile = IO.Path.Combine(filepath, categorydesc & ".igs")

 

Best regards,

Sebastian

Solution
Solution
Accepted by topic author SebatianP
‎06-24-2016 05:53 AM

Re: Journal/Macro: Export objects from layer to IGS

I don't know of an API function to directly return the category(ies) that a given layer belongs to; you'll need to look through the layer categories to find the layer of interest. Below is some code that will return the first category found (if any) for a given layer (in this case, layer 10).

 

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module3

    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()

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

        lw.Open()

        Dim layerCat As String = GetLayerCategory(10)

        If IsNothing(layerCat) Then
            lw.WriteLine("layer does not belong to any category")
        Else
            lw.WriteLine("layer belongs to category: " & layerCat)
        End If


        lw.Close()

    End Sub

    Function GetLayerCategory(ByVal layerNum As Integer) As String

        'layerNum must be between 1 and 256 inclusive
        If layerNum < 1 OrElse layerNum > 256 Then
            Return Nothing
        End If

        For Each temp As Layer.Category In workPart.LayerCategories
            If temp.Name = "ALL" Then
                'skip the ALL category
                Continue For
            End If
            For Each categoryLayerNum As Integer In temp.GetMemberLayers
                If categoryLayerNum = layerNum Then
                    Return temp.Name
                End If
            Next
        Next

        'layer number not found in the existing categories
        Return Nothing

    End Function

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

    End Function

End Module

Re: Journal/Macro: Export objects from layer to IGS

It works like a charm!!

 

Thanks,

Sebastian