Submitted by DavideNX990 on Mon, 10/19/2015 - 03:17
Forums:
Hello,
this is my first topic on this forum and for this forgive me if is not 100% accurate.
My problem is that I have the selection block NXOpen.BlockStyler.CurveCollector in my NX Block Styler Form and I want to catch the Tag of the original selected object.
My final target is to have the name of the object selected with my block Styler Form (like "Line (230)") that is the same of that in feature tree and if I have the Tag of the original object I can do it easily.
What I have to do in my program is use the correct value of the string MyLineName to insert in the istruction:
workpart.Features.FindObject(MyLineName)
to manage the part in the feature tree.
Thank you.
re: feature of curve
I don't currently have access to a blockstyler license, but what I think you are asking is: "given a curve object, how do I find the curve feature?".
The journal below allows you to select a line; it will then report the feature that created the line (if any). It uses the .AskObjectFeat method to get the tag of the line's owning feature. If the tag is null, it is an unassociative line (it is not owned by any feature); otherwise, the NXObject manager is used to get the feature given the feature tag.
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Module Module1
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()
If IsNothing(theSession.Parts.BaseWork) Then
'active part required
Return
End If
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Dim myLine As Line
If SelectLine("Select a line", myLine) = Selection.Response.Cancel Then
Return
End If
Dim theFeatureTag As Tag = Tag.Null
theUfSession.Modl.AskObjectFeat(myLine.Tag, theFeatureTag)
Dim theFeature As Features.Feature = Nothing
If theFeatureTag = Tag.Null Then
lw.WriteLine("unassociative line picked")
Else
theFeature = Utilities.NXObjectManager.Get(theFeatureTag)
lw.WriteLine("line feature: " & theFeature.GetFeatureName)
End If
lw.Close()
End Sub
Function SelectLine(ByVal prompt As String, ByRef selLine As Line) As Selection.Response
Dim selObj As TaggedObject
Dim theUI As UI = UI.GetUI
Dim title As String = "Select a Line"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim cursor As Point3d
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim selectionMask_array(0) As Selection.MaskTriple
With selectionMask_array(0)
.Type = UFConstants.UF_line_type
.Subtype = UFConstants.UF_all_subtype
End With
Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt, _
title, scope, selAction, _
includeFeatures, keepHighlighted, selectionMask_array, _
selobj, cursor)
If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
selLine = selObj
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
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
The code above is for illustration and for the sake of brevity is limited to line objects. However, the same principle can be applied to other curve types.
It Works!!!
Thank you very much, for lines it works very well!
I post the part of the code to link the Lines selected with NXOpen.BlockStyler.CurveCollector Block to the already exists in the features tree (for the people who have the Block Styler license):
---------------------------------------------------------------------------------------------------------------------------------
(In the reference add the line:
Imports NXOpen.UF
)
(At the beginning of the class add the line:
Public theUFSession As UFSession = UFSession.GetUFSession()
)
(In the apply_cb function or in the update_cb add the code:
Dim edgeSelectProps As PropertyList = super_section0.GetProperties()
Dim edges() As TaggedObject = edgeSelectProps.GetTaggedObjectVector("SelectedObjects")
edgeSelectProps.Dispose()
edgeSelectProps = Nothing
For i = 0 To edges.Length - 1
If (edges(i).GetType.Name = "Line") Then
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Dim theFeatureTag As Tag = Tag.Null
theUFSession.Modl.AskObjectFeat(edges(i).Tag, theFeatureTag)
Dim theFeature As Features.Feature = Nothing
If theFeatureTag = Tag.Null Then
lw.WriteLine("unassociative line picked")
Else
theFeature = Utilities.NXObjectManager.Get(theFeatureTag)
lw.WriteLine("line feature: " & theFeature.GetFeatureName)
End If
lw.Close()
End If
Next
)
PS
The name of my NXOpen.BlockStyler.CurveCollector was super_section0, in the previous code it must be substitute with the correct selection block name.