Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

journal to add component attribute to note automatically 1

Status
Not open for further replies.

multicaduser

Industrial
Jan 29, 2013
261
I recorded a journal to try to automate adding linked attribute from a component to a note in drafting. The attribute names are the same among all components and currently we are selecting the components interactively one at a time. The problem is I cannot find anything in the journal that will do this with a live attribute. Now I already do this by grabbing the value from the component in it's current state but this is plain text and doesn't update when the attribute in the component is updated.

I've recorded a short video showing the interactive steps to clarify the process. Does anyone know if it is possible to link a component attribute to a note through a journal?

NX 1899 Windows 10
 
 https://files.engineering.com/getfile.aspx?folder=b5e6088e-83f0-4156-955b-bac2f2d5f0ca&file=attribute_to_note.avi
Replies continue below

Recommended for you

thread561-457883
The code that I posed in the thread above might help. It asks you to select a component (in the drafting view) then creates a note with the value of a certain attribute (the note text is linked to the attribute value).

www.nxjournaling.com
 
Thanks cowski, that was a great help, it gave me a direction to keep looking. The link below was where it lead, and combined with other programs was what was needed. I'll post the code after more testing and cleanup, right now it's pretty messy with a lot of unneeded code.


NX 1899 Windows 10
 
This is the code, not expecting any points for style but I'm no programmer LOL. There are more elegant ways of cycling through lists, etc., and feedback is always helpful.

Code:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
 
Module Module1
 
    Dim theSession As Session = Session.GetSession()
    Dim theUfSession As UFSession = UFSession.GetUFSession()
    Dim theUISession As UI = UI.GetUI()
 
    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()
 
        Const undoMarkName As String = "NXJ journal"
        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

        Dim theComponent As Assemblies.Component

        Dim attTitle As String = "description"
 
        Do Until SelectComponent("select a component", theComponent) = Selection.Response.Cancel
            'does material attribute exist?
            If theComponent.HasUserAttribute(attTitle, NXObject.AttributeType.String, 0) Then
                AddComponentInfo(theComponent)
            Else
                lw.WriteLine("component, " & theComponent.DisplayName & ", does not have the attribute: " & attTitle)
            End If
        Loop
 
        lw.Close()
 
    End Sub


    Function SelectComponent(ByVal prompt As String, ByRef selObj As TaggedObject) As Selection.Response
 
        Dim theUI As UI = UI.GetUI
        Dim title As String = "Select a component"
        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.AnyInAssembly
        Dim selectionMask_array(0) As Selection.MaskTriple
 
        With selectionMask_array(0)
            .Type = UFConstants.UF_component_type
            .Subtype = UFConstants.UF_all_subtype
        End With
 
        theUfSession.Ui.SetCursorView(0)
 
        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
            Return Selection.Response.Ok
        Else
            Return Selection.Response.Cancel
        End If

    End Function


    Sub AddComponentInfo(ByVal tempComp As Assemblies.Component)                       
        'get associative text for attribute
        Dim associativeText1 As Annotations.AssociativeText
        associativeText1 = workPart.Annotations.CreateAssociativeText()
 
        Dim text1(4) As String
        text1(0) = associativeText1.GetObjectAttributeText(tempComp, "description")
        text1(1) = associativeText1.GetObjectAttributeText(tempComp, "size")
        text1(2) = associativeText1.GetObjectAttributeText(tempComp, "vendor")
        text1(2) = text1(2) + ": "+associativeText1.GetObjectAttributeText(tempComp, "part_num")

        'get point screen position
        Dim myView As NXOpen.View = Nothing
        Dim myCursor As Point3d
        'ask the user to select a new origin for this UDO 
        Dim myResponse As Selection.DialogResponse = theUISession.SelectionManager.SelectScreenPosition("Select Note Origin", myView, myCursor)

        Dim nullNXOpen_Annotations_SimpleDraftingAid As NXOpen.Annotations.SimpleDraftingAid = Nothing
        Dim pmiNoteBuilder1 As NXOpen.Annotations.PmiNoteBuilder = Nothing
        pmiNoteBuilder1 = workPart.Annotations.CreatePmiNoteBuilder(nullNXOpen_Annotations_SimpleDraftingAid)
        pmiNoteBuilder1.Origin.Anchor = NXOpen.Annotations.OriginBuilder.AlignmentPosition.MidCenter
        pmiNoteBuilder1.Text.TextBlock.SetText(text1)
        pmiNoteBuilder1.Style.LetteringStyle.GeneralTextSize = (.125)
        pmiNoteBuilder1.Origin.Plane.PlaneMethod = NXOpen.Annotations.PlaneBuilder.PlaneMethodType.ModelView

        Dim assocOrigin1 As NXOpen.Annotations.Annotation.AssociativeOriginData = Nothing
        assocOrigin1.OriginType = NXOpen.Annotations.AssociativeOriginType.Drag
        Dim nullNXOpen_View As NXOpen.View = nullNXOpen_View
        pmiNoteBuilder1.Origin.Origin.SetValue(Nothing, nullNXOpen_View, myCursor)
        Dim nXObject1 As NXOpen.NXObject = pmiNoteBuilder1.Commit()

        pmiNoteBuilder1.Destroy()
        associativeText1.Dispose()

    End Sub


End Module

NX 1899 Windows 10
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor