Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

nx journal to create Index number at dimension with adjusted orientation

Status
Not open for further replies.

cschnei

Industrial
Aug 14, 2014
14
Hello,
I am trying to create an Index number to a selected dimension. For this I found a very helpful journal in this forum that I modified a bit. Now I need to adjust the text angle of the ID Symbol to match the diminsion's orientation. Dimensions do not have a lettering angle in the style dialog like notes. Therefore I wanted to use the TextOrienationAngle from the dimension.
But I allways get an error:
"Line 56: "GetDimensionPreferences" is not a member of "NXOpen.Annotations.Annotation"

Code:
'journal to Create Non- Associative Index Numbers at Dimensions or Notes

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.UI
Imports NXOpen.Annotations


Module NXJournal
Sub Main

'*************************************************************************
'change the following offset distances to get something that works for you
'offsets from dimension text
Const XOffsetDim as Double = 0
Const YOffsetDim as Double = 2
'offsets from notes
Const XOffsetNote as Double = -3
Const YOffsetNote as Double = 0
'*************************************************************************

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim lw As ListingWindow = theSession.ListingWindow
Dim noteDim As Annotation
Dim noteDimOrigin as Point3D = Nothing
Dim letterPref as LetteringPreferences = Nothing
Dim symbolPref as SymbolPreferences = Nothing
Dim dimpref as DimensionPreferences = Nothing
Dim noteNumber as Integer
Dim letterangle as String
Dim dimangle as String
Dim input as String
Dim theAnnotationManager as NXOpen.Annotations.AnnotationManager = workPart.Annotations

Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")

Do
	input = InputBox("Enter starting INDEX number: ", "Create Index Numbers at Dimensions or Notes", "")
Loop Until (isNumeric(input))
noteNumber = input

lw.Open()

While selectNoteDimension("Select Dimension or Note", noteDim) = Selection.Response.Ok
	noteDimOrigin = noteDim.AnnotationOrigin
	'lw.WriteLine("origin: " & noteDimOrigin.X & ", " & noteDimOrigin.Y)
	letterPref = noteDim.GetLetteringPreferences()
	letterangle = letterPref.Angle
	dimpref = noteDim.GetDimensionPreferences()
	dimangle = dimpref.TextOrienationAngle
	'symbolPref = NXOpen.Preferences.AnnotationPreferences.GetSymbolPreferences()
	symbolPref = theAnnotationManager.Preferences.GetSymbolPreferences()
	'lw.WriteLine("Alignment Position: " & letterPref.AlignmentPosition.ToString())
	'lw.WriteLine("ID Symbol size: " & symbolPref.IDSymbolSize)
	'lw.WriteLine("Annotation type: " & noteDim.GetType().ToString())

	
	Dim nullAnnotations_IdSymbol As Annotations.IdSymbol = Nothing
	Dim idSymbolBuilder1 As Annotations.IdSymbolBuilder
	
	idSymbolBuilder1 = workPart.Annotations.IdSymbols.CreateIdSymbolBuilder(nullAnnotations_IdSymbol)
	idSymbolBuilder1.Origin.Plane.PlaneMethod = Annotations.PlaneBuilder.PlaneMethodType.XyPlane
	idSymbolBuilder1.Type = Annotations.IdSymbolBuilder.SymbolTypes.Circle
	idSymbolBuilder1.UpperText = noteNumber
	'use the symbol size set in the part
	idSymbolBuilder1.Size = 4
	idSymbolBuilder1.Style.LetteringStyle.GeneralTextSize = 2.5
	idSymbolBuilder1.Style.LetteringStyle.Angle = dimangle
	
	Dim assocOrigin1 As Annotations.Annotation.AssociativeOriginData
	Dim nullPoint As Point = Nothing
	Dim nullView As View = Nothing
	With assocOrigin1
		.OriginType = Annotations.AssociativeOriginType.OffsetFromText
		.OffsetAnnotation = noteDim
		.OffsetAlignmentPosition = Annotations.AlignmentPosition.TopRight
		.AssociatedPoint = nullPoint
		.StackAlignmentPosition = Annotations.StackAlignmentPosition.Above
		.AlignedAnnotation = Nothing
		if noteDim.GetType().ToString() = "NXOpen.Annotations.Note" Then
			.XOffsetFactor = XOffsetNote
			.YOffsetFactor = YOffsetNote
		Else
			.XOffsetFactor = XOffsetDim
			.YOffsetFactor = YOffsetDim
		End if
	End With
	Dim point1 As Point3d = New Point3d(noteDimOrigin.X-4, noteDimOrigin.Y+6, 0.0)
	'idSymbolBuilder1.Origin.SetInferRelativeToGeometry(True)
	'idSymbolBuilder1.Origin.SetAssociativeOrigin(assocOrigin1)
	idSymbolBuilder1.Origin.Origin.SetValue(Nothing, nullView, point1)
	
	Dim QC_IDSymbol As IDSymbol
	QC_IDSymbol = idSymbolBuilder1.Commit()
	'change IDSymbol layer to match that of the dimension or note it is attached to
	QC_IDSymbol.Layer = 109
	idSymbolBuilder1.Destroy()
	
	noteNumber += 1
	
End While
lw.Close
theSession.SetUndoMarkName(markId1, "Label Dimensions")
theSession.SetUndoMarkVisibility(markId1, Nothing, Session.MarkVisibility.Visible)		

End Sub 'Main

'**************************************************
    Function selectNoteDimension(ByVal prompt As String, ByRef obj As Annotation)
	'Annotation class covers dimensions and notes
	'Annotation -> Dimension
	'Annotation -> DraftingAid -> SimpleDraftingAid -> NoteBase -> BaseNote -> Note
        Dim ui As UI = GetUI()
        Dim mask(1) As Selection.MaskTriple
        With mask(0)
            .Type = UFConstants.UF_dimension_type
            .Subtype = 0
            .SolidBodySubtype = 0
        End With
		With mask(1)
            .Type = UFConstants.UF_drafting_entity_type
            .Subtype = UFConstants.UF_draft_note_subtype
            .SolidBodySubtype = 0
        End With
		
        Dim cursor As Point3d = Nothing

        Dim resp As Selection.Response = _
        ui.SelectionManager.SelectObject(prompt, prompt, _
            Selection.SelectionScope.AnyInAssembly, _
            Selection.SelectionAction.ClearAndEnableSpecific, _
            False, False, mask, obj, cursor)

        If resp = Selection.Response.ObjectSelected Or _
           resp = Selection.Response.ObjectSelectedByName Then
            Return Selection.Response.Ok
        Else
            Return Selection.Response.Cancel
        End If
    End Function	'selectNoteDimension
'**************************************************

End Module

Can anyone help me on this problem?

Thanks
CSchnei
 
Replies continue below

Recommended for you

Not guaranteed to solve all your problems, but should get you past your current hurdle:

Code:
'journal to Create Non- Associative Index Numbers at Dimensions or Notes

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.UI
Imports NXOpen.Annotations


Module Module18
    Sub Main()

        '*************************************************************************
        'change the following offset distances to get something that works for you
        'offsets from dimension text
        Const XOffsetDim As Double = 0
        Const YOffsetDim As Double = 2
        'offsets from notes
        Const XOffsetNote As Double = -3
        Const YOffsetNote As Double = 0
        '*************************************************************************

        Dim theSession As Session = Session.GetSession()
        Dim workPart As Part = theSession.Parts.Work
        Dim displayPart As Part = theSession.Parts.Display
        Dim lw As ListingWindow = theSession.ListingWindow
        Dim noteDim As Annotation
        Dim noteDimOrigin As Point3d = Nothing
        Dim letterPref As LetteringPreferences = Nothing
        Dim symbolPref As SymbolPreferences = Nothing
        Dim dimpref As DimensionPreferences = Nothing
        Dim noteNumber As Integer
        Dim letterangle As [highlight #FCE94F]Double[/highlight]
        Dim dimangle As [highlight #FCE94F]Double[/highlight]
        Dim input As String
        Dim theAnnotationManager As NXOpen.Annotations.AnnotationManager = workPart.Annotations
        [highlight #FCE94F]Dim idTextAngle As Double[/highlight]

        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")

        Do
            input = InputBox("Enter starting INDEX number: ", "Create Index Numbers at Dimensions or Notes", "")
        Loop Until (IsNumeric(input))
        noteNumber = input

        lw.Open()

        While selectNoteDimension("Select Dimension or Note", noteDim) = Selection.Response.Ok

[highlight #FCE94F]            If TypeOf (noteDim) Is Annotations.Note Then
                'code for notes
                'lw.WriteLine("note: " & noteDim.GetType.ToString)
                letterPref = noteDim.GetLetteringPreferences()
                letterangle = letterPref.Angle
                idTextAngle = letterangle

            Else
                'code for dims
                'lw.WriteLine("dim: " & noteDim.GetType.ToString)
                Dim theDim As Dimension = noteDim
                dimpref = theDim.GetDimensionPreferences()
                dimangle = dimpref.TextOrienationAngle
                idTextAngle = dimangle

            End If[/highlight]

            noteDimOrigin = noteDim.AnnotationOrigin
            'lw.WriteLine("origin: " & noteDimOrigin.X & ", " & noteDimOrigin.Y)
            'symbolPref = NXOpen.Preferences.AnnotationPreferences.GetSymbolPreferences()
            symbolPref = theAnnotationManager.Preferences.GetSymbolPreferences()
            'lw.WriteLine("Alignment Position: " & letterPref.AlignmentPosition.ToString())
            'lw.WriteLine("ID Symbol size: " & symbolPref.IDSymbolSize)
            'lw.WriteLine("Annotation type: " & noteDim.GetType().ToString())


            Dim nullAnnotations_IdSymbol As Annotations.IdSymbol = Nothing
            Dim idSymbolBuilder1 As Annotations.IdSymbolBuilder

            idSymbolBuilder1 = workPart.Annotations.IdSymbols.CreateIdSymbolBuilder(nullAnnotations_IdSymbol)
            idSymbolBuilder1.Origin.Plane.PlaneMethod = Annotations.PlaneBuilder.PlaneMethodType.XyPlane
            idSymbolBuilder1.Type = Annotations.IdSymbolBuilder.SymbolTypes.Circle
            idSymbolBuilder1.UpperText = noteNumber
            'use the symbol size set in the part
            idSymbolBuilder1.Size = 4
            idSymbolBuilder1.Style.LetteringStyle.GeneralTextSize = 2.5
            idSymbolBuilder1.Style.LetteringStyle.Angle = [highlight #FCE94F]idTextAngle[/highlight]

            Dim assocOrigin1 As Annotations.Annotation.AssociativeOriginData
            Dim nullPoint As Point = Nothing
            Dim nullView As View = Nothing
            With assocOrigin1
                .OriginType = Annotations.AssociativeOriginType.OffsetFromText
                .OffsetAnnotation = noteDim
                .OffsetAlignmentPosition = Annotations.AlignmentPosition.TopRight
                .AssociatedPoint = nullPoint
                .StackAlignmentPosition = Annotations.StackAlignmentPosition.Above
                .AlignedAnnotation = Nothing
                If noteDim.GetType().ToString() = "NXOpen.Annotations.Note" Then
                    .XOffsetFactor = XOffsetNote
                    .YOffsetFactor = YOffsetNote
                Else
                    .XOffsetFactor = XOffsetDim
                    .YOffsetFactor = YOffsetDim
                End If
            End With
            Dim point1 As Point3d = New Point3d(noteDimOrigin.X - 4, noteDimOrigin.Y + 6, 0.0)
            'idSymbolBuilder1.Origin.SetInferRelativeToGeometry(True)
            'idSymbolBuilder1.Origin.SetAssociativeOrigin(assocOrigin1)
            idSymbolBuilder1.Origin.Origin.SetValue(Nothing, nullView, point1)

            Dim QC_IDSymbol As IdSymbol
            QC_IDSymbol = idSymbolBuilder1.Commit()
            'change IDSymbol layer to match that of the dimension or note it is attached to
            QC_IDSymbol.Layer = 109
            idSymbolBuilder1.Destroy()

            noteNumber += 1

        End While
        lw.Close()
        theSession.SetUndoMarkName(markId1, "Label Dimensions")
        theSession.SetUndoMarkVisibility(markId1, Nothing, Session.MarkVisibility.Visible)

    End Sub 'Main

    '**************************************************
    Function selectNoteDimension(ByVal prompt As String, ByRef obj As Annotation)
        'Annotation class covers dimensions and notes
        'Annotation -> Dimension
        'Annotation -> DraftingAid -> SimpleDraftingAid -> NoteBase -> BaseNote -> Note
        Dim ui As UI = GetUI()
        Dim mask(1) As Selection.MaskTriple
        With mask(0)
            .Type = UFConstants.UF_dimension_type
            .Subtype = 0
            .SolidBodySubtype = 0
        End With
        With mask(1)
            .Type = UFConstants.UF_drafting_entity_type
            .Subtype = UFConstants.UF_draft_note_subtype
            .SolidBodySubtype = 0
        End With

        Dim cursor As Point3d = Nothing

        Dim resp As Selection.Response = _
        ui.SelectionManager.SelectObject(prompt, prompt, _
            Selection.SelectionScope.AnyInAssembly, _
            Selection.SelectionAction.ClearAndEnableSpecific, _
            False, False, mask, obj, cursor)

        If resp = Selection.Response.ObjectSelected Or _
           resp = Selection.Response.ObjectSelectedByName Then
            Return Selection.Response.Ok
        Else
            Return Selection.Response.Cancel
        End If
    End Function    'selectNoteDimension
    '**************************************************

End Module

www.nxjournaling.com
 
That's exactly what I need, thanks a lot.
cschnei
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor