Cancel
Showing results for 
Search instead for 
Did you mean: 

Get multiple leaders data and create new FCF using same

Siemens Phenom Siemens Phenom
Siemens Phenom

I've below code which copies everything from exisitng PMI FCF and create a new one at the same location.

I just now wants to handle the case where multiple leaders are to FCF. I could retrieve leader data but can't make it to apply to new one. Any help please.

 

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

    Dim theSession As Session = Nothing
    DIm theUfSession As UFSession = Nothing
    Sub Main()

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

        ' to avoid the circular references
        Dim fcfs As Annotations.Fcf() = workPart.Annotations.Fcfs.ToArray
        For Each myFCF As NXOpen.Annotations.Fcf In workPart.Annotations.fcfs.ToArray

            Dim nullNXOpen_Annotations_Fcf As NXOpen.Annotations.Fcf = Nothing

            Dim pmiFeatureControlFrameBuilder1 As NXOpen.Annotations.PmiFeatureControlFrameBuilder = Nothing
            pmiFeatureControlFrameBuilder1 = workPart.Annotations.CreatePmiFeatureControlFrameBuilder(nullNXOpen_Annotations_Fcf)

            Dim pmiFeatureControlFrameBuilder2 As NXOpen.Annotations.PmiFeatureControlFrameBuilder = Nothing
            pmiFeatureControlFrameBuilder2 = workPart.Annotations.CreatePmiFeatureControlFrameBuilder(myFCF)

            pmiFeatureControlFrameBuilder1.Origin.Plane.PlaneMethod = NXOpen.Annotations.PlaneBuilder.PlaneMethodType.ModelView
            ''' https://docs.plm.automation.siemens.com/data_services/resources/nx/10/nx_api/en_US/custom/nxopen_python_ref/NXOpen.Annotations.OriginBuilder.html#NXOpen.Annotations.OriginBuilder
            pmiFeatureControlFrameBuilder1.Origin.Anchor = pmiFeatureControlFrameBuilder2.Origin.Anchor

            pmiFeatureControlFrameBuilder1.Origin.OriginPoint = pmiFeatureControlFrameBuilder2.Origin.OriginPoint

            pmiFeatureControlFrameBuilder1.InheritFrom(myFCF)

            ''' Get and apply leader data https://community.plm.automation.siemens.com/t5/NX-Programming-Customization-Forum/Recreate-PMI-FCF-to-recreate-new-one/m-p/600135#M17667
            Dim draftingFeatureControlFrameBuilder As NXOpen.Annotations.DraftingFeatureControlFrameBuilder = workPart.Annotations.CreateDraftingFeatureControlFrameBuilder(myFCF)
            Dim leaderBuilder As NXOpen.Annotations.LeaderBuilder = draftingFeatureControlFrameBuilder.Leader
            Dim leaderDataList As NXOpen.Annotations.LeaderDataList = leaderBuilder.Leaders
            Dim leaderDatas As NXOpen.Annotations.LeaderData() = leaderDataList.GetContents()
            DispLeaderData(leaderDatas)
            
            Dim data As Annotations.LeaderData() = pmiFeatureControlFrameBuilder2.Leader.Leaders.GetContents()
            Dim leaderData1 As NXOpen.Annotations.LeaderData = Nothing
            leaderData1 = workPart.Annotations.CreateLeaderData()
            leaderData1 = data(0)
            pmiFeatureControlFrameBuilder1.Leader.Leaders.Append(leaderData1)
            '''Code to handle case when FCF is created with more than 1 leader (and more associations) and apply
            Dim fcf As NXOpen.Annotations.Fcf = CType((myFCF), NXOpen.Annotations.Fcf)
            Dim associatedObject As NXOpen.Annotations.AssociatedObject = fcf.GetAssociatedObject()
            Dim nXObject As NXObject() = associatedObject.GetObjects()
            Dim added1 As Boolean = Nothing
                For j As Integer = 0 To nXObject.Length - 1
                   ' theSession.ListingWindow.WriteFullline("Associative Object Tag : " & nXObject(j).Tag)
                    added1 = pmiFeatureControlFrameBuilder1.AssociatedObjects.Nxobjects.Add(nXObject(j))  
                Next


            draftingFeatureControlFrameBuilder.Destroy()
                  
            ''' https://docs.plm.automation.siemens.com/data_services/resources/nx/10/nx_api/en_US/custom/nxopen_python_ref/NXOpen.Annotations.AssociatedObjectsBuilder.html?highlight=nxopen.annotations#NXOpen.Annotations.AssociatedObjectsBuilder.Nxobjects

            pmiFeatureControlFrameBuilder1.Commit()
            pmiFeatureControlFrameBuilder1.Destroy()
            pmiFeatureControlFrameBuilder2.Destroy()

        Next
        lw.Close()

    End Sub

''' https://solutions.industrysoftware.automation.siemens.com/view.php?sort=desc&q=NXOpen.Annotations.LeaderBuilder&file_type=text&i=nx_api6055&k=0&o=0
    Sub DispLeaderData(ByVal leaderDatas As NXOpen.Annotations.LeaderData())
        If leaderDatas Is Nothing Then Return
        If leaderDatas.Length = 0 Then Return

            For Each leaderData As NXOpen.Annotations.LeaderData In leaderDatas
                Dim type, subType As Integer
                Dim displayableObject As DisplayableObject = Nothing
                Dim view As View = Nothing
                Dim point3d As Point3d
                leaderData.Leader.GetValue(displayableObject, view, point3d)

                If displayableObject IsNot Nothing Then
                    theUfSession.Obj.AskTypeAndSubtype(displayableObject.Tag, type, subType)
                    theSession.ListingWindow.WriteFullline("Leader Associated to Object Type : " & type & " SubType : " & subType)
                    theSession.ListingWindow.WriteFullline(vbTab & "Tag    : " & displayableObject.Tag.ToString())
                    theSession.ListingWindow.WriteFullline(vbTab & "Origin : X" & point3d.X.ToString() & " Y" + point3d.Y.ToString() & " Z" + point3d.Z.ToString())
                    If view IsNot Nothing Then theSession.ListingWindow.WriteFullline(vbTab & "View   : " & view.Name)
                End If
            Next
    End Sub 
            
    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        'Unloads the image when the NX session terminates
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

    End Function
End Module

Regards,
Samadhan

GTAC | NX Help: NX1102 | NX1202 | NX1847
Please mark post as an "Accepted Solution", if it answers your question/is more helpful!
3 REPLIES 3

Re: Get multiple leaders data and create new FCF using same

PLM World Member Legend PLM World Member Legend
PLM World Member Legend

Hi @SamadhanGaikwad 

 

I have updated the source below to support the multiple leader options and also the associated objects to the new FcF

    Sub Main()

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

        ' to avoid the circular references
        Dim fcfs As Annotations.Fcf() = workPart.Annotations.Fcfs.ToArray
        For Each myFCF As NXOpen.Annotations.Fcf In workPart.Annotations.fcfs.ToArray

            Dim nullNXOpen_Annotations_Fcf As NXOpen.Annotations.Fcf = Nothing

            Dim pmiFeatureControlFrameBuilder1 As NXOpen.Annotations.PmiFeatureControlFrameBuilder = Nothing
            pmiFeatureControlFrameBuilder1 = workPart.Annotations.CreatePmiFeatureControlFrameBuilder(nullNXOpen_Annotations_Fcf)

            Dim pmiFeatureControlFrameBuilder2 As NXOpen.Annotations.PmiFeatureControlFrameBuilder = Nothing
            pmiFeatureControlFrameBuilder2 = workPart.Annotations.CreatePmiFeatureControlFrameBuilder(myFCF)

            pmiFeatureControlFrameBuilder1.Origin.Plane.PlaneMethod = NXOpen.Annotations.PlaneBuilder.PlaneMethodType.ModelView
            ''' https://docs.plm.automation.siemens.com/data_services/resources/nx/10/nx_api/en_US/custom/nxopen_python_ref/NXOpen.Annotations.OriginBuilder.html#NXOpen.Annotations.OriginBuilder
            pmiFeatureControlFrameBuilder1.Origin.Anchor = pmiFeatureControlFrameBuilder2.Origin.Anchor

            pmiFeatureControlFrameBuilder1.Origin.OriginPoint = pmiFeatureControlFrameBuilder2.Origin.OriginPoint

            pmiFeatureControlFrameBuilder1.InheritFrom(myFCF)

            ''' Get and apply leader data https://community.plm.automation.siemens.com/t5/NX-Programming-Customization-Forum/Recreate-PMI-FCF-to-recreate-new-one/m-p/600135#M17667
            ''Dim draftingFeatureControlFrameBuilder As NXOpen.Annotations.DraftingFeatureControlFrameBuilder = workPart.Annotations.CreateDraftingFeatureControlFrameBuilder(myFCF)
            ''Dim leaderBuilder As NXOpen.Annotations.LeaderBuilder = draftingFeatureControlFrameBuilder.Leader
            ''Dim leaderDataList As NXOpen.Annotations.LeaderDataList = leaderBuilder.Leaders
            ''Dim leaderDatas As NXOpen.Annotations.LeaderData() = leaderDataList.GetContents()
            ''DispLeaderData(leaderDatas)
            
			
			' to get and assign the leader data in new fcf (newly added)
            Dim leaderdata As Annotations.LeaderData() = pmiFeatureControlFrameBuilder2.Leader.Leaders.GetContents()			
			DispLeaderData(leaderdata)
			
            For Each data As Annotations.LeaderData In leaderdata
                Dim leaderData1 As NXOpen.Annotations.LeaderData = Nothing
                leaderData1 = workPart.Annotations.CreateLeaderData()
                leaderData1 = data
                pmiFeatureControlFrameBuilder1.Leader.Leaders.Append(leaderData1)
            Next

            ' to get and assign the associated objects in new fcf (newly added)
            Dim objs As NXObject() = pmiFeatureControlFrameBuilder2.AssociatedObjects.Nxobjects.GetArray()
            pmiFeatureControlFrameBuilder1.AssociatedObjects.Nxobjects.Add(objs)
			
			' commented
            'Dim data As Annotations.LeaderData() = pmiFeatureControlFrameBuilder2.Leader.Leaders.GetContents()
            'Dim leaderData1 As NXOpen.Annotations.LeaderData = Nothing
            'leaderData1 = workPart.Annotations.CreateLeaderData()
            'leaderData1 = data(0)
            'pmiFeatureControlFrameBuilder1.Leader.Leaders.Append(leaderData1)
			
			' commented
            '''Code to handle case when FCF is created with more than 1 leader (and more associations) and apply
            ''Dim fcf As NXOpen.Annotations.Fcf = CType((myFCF), NXOpen.Annotations.Fcf)
            ''Dim associatedObject As NXOpen.Annotations.AssociatedObject = fcf.GetAssociatedObject()
            ''Dim nXObject As NXObject() = associatedObject.GetObjects()
            ''Dim added1 As Boolean = Nothing
                ''For j As Integer = 0 To nXObject.Length - 1
                   ' theSession.ListingWindow.WriteFullline("Associative Object Tag : " & nXObject(j).Tag)
                    ''added1 = pmiFeatureControlFrameBuilder1.AssociatedObjects.Nxobjects.Add(nXObject(j))  
                ''Next

			' commented
            ''draftingFeatureControlFrameBuilder.Destroy()
                  
            ''' https://docs.plm.automation.siemens.com/data_services/resources/nx/10/nx_api/en_US/custom/nxopen_python_ref/NXOpen.Annotations.AssociatedObjectsBuilder.html?highlight=nxopen.annotations#NXOpen.Annotations.AssociatedObjectsBuilder.Nxobjects

            pmiFeatureControlFrameBuilder1.Commit()
            pmiFeatureControlFrameBuilder1.Destroy()
            pmiFeatureControlFrameBuilder2.Destroy()

        Next
        lw.Close()

    End Sub

Replace the above main sub in the code you have posted. I have commented some of the lines not required.

Re: Get multiple leaders data and create new FCF using same

Siemens Phenom Siemens Phenom
Siemens Phenom

Hi @Manikandan_R ,

 

Thank you! Now I got it how to get leader and associated objects. Below is the final running code.

 

 

Option Strict Off
Imports System
Imports NXOpen

Module Module1

    Dim theSession As Session = Nothing
    Sub Main()
 
        theSession = Session.GetSession()
        Dim workPart As Part = theSession.Parts.Work
        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()

        ' to avoid the circular references
        Dim fcfs As Annotations.Fcf() = workPart.Annotations.Fcfs.ToArray
        For Each myFCF As NXOpen.Annotations.Fcf In workPart.Annotations.fcfs.ToArray

            Dim nullNXOpen_Annotations_Fcf As NXOpen.Annotations.Fcf = Nothing

            Dim pmiFeatureControlFrameBuilder1 As NXOpen.Annotations.PmiFeatureControlFrameBuilder = Nothing
            pmiFeatureControlFrameBuilder1 = workPart.Annotations.CreatePmiFeatureControlFrameBuilder(nullNXOpen_Annotations_Fcf)

            Dim pmiFeatureControlFrameBuilder2 As NXOpen.Annotations.PmiFeatureControlFrameBuilder = Nothing
            pmiFeatureControlFrameBuilder2 = workPart.Annotations.CreatePmiFeatureControlFrameBuilder(myFCF)

            pmiFeatureControlFrameBuilder1.Origin.Plane.PlaneMethod = NXOpen.Annotations.PlaneBuilder.PlaneMethodType.ModelView
            ''' https://docs.plm.automation.siemens.com/data_services/resources/nx/10/nx_api/en_US/custom/nxopen_python_ref/NXOpen.Annotations.OriginBuilder.html#NXOpen.Annotations.OriginBuilder
            pmiFeatureControlFrameBuilder1.Origin.Anchor = pmiFeatureControlFrameBuilder2.Origin.Anchor

            pmiFeatureControlFrameBuilder1.Origin.OriginPoint = pmiFeatureControlFrameBuilder2.Origin.OriginPoint

            pmiFeatureControlFrameBuilder1.InheritFrom(myFCF)

			' to get and assign the leader data in new fcf
            Dim leaderdata As Annotations.LeaderData() = pmiFeatureControlFrameBuilder2.Leader.Leaders.GetContents()			
			
            For Each data As Annotations.LeaderData In leaderdata
                Dim leaderData1 As NXOpen.Annotations.LeaderData = Nothing
                leaderData1 = workPart.Annotations.CreateLeaderData()
                leaderData1 = data
                pmiFeatureControlFrameBuilder1.Leader.Leaders.Append(leaderData1)
            Next

            ' to get and assign the associated objects in new fcf
            Dim objs As NXObject() = pmiFeatureControlFrameBuilder2.AssociatedObjects.Nxobjects.GetArray()
            pmiFeatureControlFrameBuilder1.AssociatedObjects.Nxobjects.Add(objs)            

            pmiFeatureControlFrameBuilder1.Commit()
            pmiFeatureControlFrameBuilder1.Destroy()
            pmiFeatureControlFrameBuilder2.Destroy()

        Next
        lw.Close()

    End Sub
            
    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        'Unloads the image when the NX session terminates
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

    End Function
End Module

 

 

Regards,
Samadhan

GTAC | NX Help: NX1102 | NX1202 | NX1847
Please mark post as an "Accepted Solution", if it answers your question/is more helpful!

Re: Get multiple leaders data and create new FCF using same

Siemens Phenom Siemens Phenom
Siemens Phenom

Hi @Manikandan_R ,

 

In above code, the plane method is hard coded so I tried passing information of plane method from existing FCF to new one but still some PMI FCFs are not created with correct orientation. Can we improve the code? Can we also make it work for User Defined Plane method?

Regards,
Samadhan

GTAC | NX Help: NX1102 | NX1202 | NX1847
Please mark post as an "Accepted Solution", if it answers your question/is more helpful!