Get the x and y co-ordinates for section line letters.

Hi,

I need x and y co-ordinates for section line letters.

Could any one help with this.

Thankyou.

I wrote some code a while back that will find the section line and labels given a section view. I've added a couple lines of code that report the label coordinates. The code below looks for section views in the part and reports on all the section labels.

The class code (all the code contained between "Public class..." and "End Class") can be left alone. The journal "Main" subroutine shows how to use the class code.

'NXJournaling.com
'November 30, 2015

'Journal to illustrate usage of class code to return section line labels given the section line or section view.
'Process all the section views in the part; report the section line, parent view, and labels.

Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF

Module process_section_views

Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()
Dim lw As ListingWindow = theSession.ListingWindow

Dim workPart As Part = theSession.Parts.Work

Sub Main()

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

lw.Open()

Const undoMarkName As String = "find section line labels"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

For Each temp As Drawings.DraftingView In workPart.DraftingViews

If TypeOf (temp) Is Drawings.SectionView Then

Dim myLabels As New NXJ_findSectionLineLabels(temp)

lw.WriteLine("view: " & temp.Name)
lw.WriteLine("parent view: " & myLabels.SectionViewParent.Name)
lw.WriteLine("section line tag: " & myLabels.SectionLine.Tag.ToString)

lw.WriteLine("label1 tag: " & myLabels.SectionLineLabel1.Tag)
lw.WriteLine("label1 value: " & EvaluateText(myLabels.SectionLineLabel1))
lw.WriteLine("label1 coordinates: " & myLabels.SectionLineLabel1.AnnotationOrigin.ToString)

myLabels.SectionLineLabel1.Highlight()
theSession.Parts.Display.DrawingSheets.CurrentDrawingSheet.View.UpdateDisplay()
MsgBox("label1 tag: " & myLabels.SectionLineLabel1.Tag)
myLabels.SectionLineLabel1.Unhighlight()
theSession.Parts.Display.DrawingSheets.CurrentDrawingSheet.View.UpdateDisplay()

lw.WriteLine("label2 tag: " & myLabels.SectionLineLabel2.Tag)
lw.WriteLine("label2 value: " & EvaluateText(myLabels.SectionLineLabel2))
lw.WriteLine("label2 coordinates: " & myLabels.SectionLineLabel2.AnnotationOrigin.ToString)

lw.WriteLine("")
End If

'lw.WriteLine("")
Next

lw.Close()

End Sub

Function EvaluateText(ByVal someNote As Annotations.Note) As String

Dim aT As Annotations.AssociativeText = theSession.Parts.Work.Annotations.CreateAssociativeText()
Dim cData As Annotations.ComponentData = theSession.Parts.Work.Annotations.CreateComponentData(someNote)

For Each tC As Annotations.TextComponent In cData.GetTextComponents
Return aT.GetEvaluatedText(someNote, tC.GetText(0))
Next

Return Nothing

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

Public Class NXJ_findSectionLineLabels

#Region "Private variables"
Private _theSession As Session = Session.GetSession
Private _theUfSession As UFSession = UFSession.GetUFSession()
Private lg As LogFile = _theSession.LogFile

'key = tag of note's smart object parent, value = note object
Private _annotationMap As New Dictionary(Of Tag, Annotations.Note)
Private _sectionLineSegmentCurveTags As New List(Of Tag)

#End Region

#Region "Properties"

Private _theSectionLine As Drawings.SectionLine = Nothing
Public ReadOnly Property SectionLine() As Drawings.SectionLine
Get
Return _theSectionLine
End Get
End Property

Private _theSectionLineStatus As UFDraw.SxlineStatus = Nothing
Public ReadOnly Property SectionLineStatus() As UFDraw.SxlineStatus
Get
Return _theSectionLineStatus
End Get
End Property

Private _theSectionView As Drawings.SectionView = Nothing
Public ReadOnly Property SectionView() As Drawings.SectionView
Get
Return _theSectionView
End Get
End Property

Private _sectionLineLabel1 As Annotations.Note = Nothing
Public ReadOnly Property SectionLineLabel1() As Annotations.Note
Get
Return _sectionLineLabel1
End Get
End Property

Private _sectionLineLabel2 As Annotations.Note = Nothing
Public ReadOnly Property SectionLineLabel2() As Annotations.Note
Get
Return _sectionLineLabel2
End Get
End Property

Private _sectionViewParent As Drawings.DraftingView = Nothing
Public ReadOnly Property SectionViewParent() As Drawings.DraftingView
Get
Return _sectionViewParent
End Get
End Property

#End Region

#Region "Public methods"

Public Sub New(ByVal someSectionView As Drawings.SectionView)

_theSectionView = someSectionView
_theSectionLine = GetSectionLine(_theSectionView)

Me.GetSectionLineLabels()

End Sub

Public Sub New(ByVal someSectionLine As Drawings.SectionLine)

_theSectionLine = someSectionLine
_theSectionView = GetSectionView(someSectionLine)

Me.GetSectionLineLabels()

End Sub

#End Region

#Region "Private methods"

Private Sub GetSectionLineLabels()

Me.CreateAnnotationMap()
_sectionLineSegmentCurveTags = SectionLineSegmentCurveTags(_theSectionLine.Tag)

If Not _sectionLineSegmentCurveTags.Count = 2 Then
Exit Sub
End If

If _annotationMap.ContainsKey(_sectionLineSegmentCurveTags.Item(0)) Then
_sectionLineLabel2 = _annotationMap.Item(_sectionLineSegmentCurveTags.Item(0))
End If

If _annotationMap.ContainsKey(_sectionLineSegmentCurveTags.Item(1)) Then
_sectionLineLabel1 = _annotationMap.Item(_sectionLineSegmentCurveTags.Item(1))
End If

End Sub

Private Sub CreateAnnotationMap()

For Each temp As Annotations.Note In _theSession.Parts.Display.Notes

If temp.HasAssociativeOrigin Then
Dim pt As Point3d
Dim originData As Annotations.Annotation.AssociativeOriginData
originData = temp.GetAssociativeOrigin(pt)

lg.WriteLine(" note associativity type: " & originData.OriginType.ToString)

If originData.OriginType = Annotations.AssociativeOriginType.RelativeToGeometry Then
Dim geoPt As Point = originData.PointOnGeometry
Dim smartParent As TaggedObject
smartParent = GetSmartParent(geoPt, 0)

If Not IsNothing(smartParent) Then
_annotationMap.Add(smartParent.Tag, temp)
End If
End If
End If

Next

End Sub

Private Function GetSmartParent(ByRef theSmartObject As NXObject, ByVal indent As Integer) As TaggedObject

Dim numParents As Integer
Dim theParentTags() As Tag = Nothing
Dim isSmart As Boolean = False

Try
_theUfSession.So.IsSo(theSmartObject.Tag, isSmart)
If isSmart Then
_theUfSession.So.AskParents(theSmartObject.Tag, UFConstants.UF_SO_ASK_ALL_PARENTS, numParents, theParentTags)

lg.WriteLine(New String(" "c, indent) & "number of parents: " & numParents.ToString)
For Each tempTag As Tag In theParentTags
Dim objParent As TaggedObject = Utilities.NXObjectManager.Get(tempTag)

Return objParent

'lg.WriteLine(New String(" "c, indent) & "parent type: " & objParent.GetType.ToString)
'lg.WriteLine(New String(" "c, indent) & "parent tag: " & objParent.Tag.ToString)

Next

lg.WriteLine("")

End If

Return Nothing

Catch ex As NXException
lg.WriteLine("error: " & ex.ErrorCode)
lg.WriteLine(" " & ex.Message)
Return Nothing
End Try

End Function

Private Function GetSectionLine(ByVal sxView As Drawings.SectionView) As Drawings.SectionLine

Dim sectionLineTag As Tag = Tag.Null
_theUfSession.Draw.AskSxlineOfSxview(sxView.Tag, sectionLineTag)

Dim theSectionLine As Drawings.SectionLine
theSectionLine = Utilities.NXObjectManager.Get(sectionLineTag)

Return theSectionLine

End Function

Private Function GetSectionView(ByVal sxLine As Drawings.SectionLine) As Drawings.SectionView

For Each temp As Drawings.DraftingView In _theSession.Parts.Display.DraftingViews
If TypeOf (temp) Is Drawings.SectionView Then
Dim tempLine As Drawings.SectionLine
tempLine = GetSectionLine(temp)
If tempLine.Tag = sxLine.Tag Then
Return temp
End If
End If
Next

Return Nothing

End Function

Private Function SectionLineSegmentCurveTags(ByVal sectionLineTag As Tag) As List(Of Tag)

Dim sectionLineType As UFDraw.SxlineType
_theUfSession.Draw.AskSxlineType(sectionLineTag, sectionLineType)

Dim stepDir(2) As Double
Dim arrowDir(2) As Double
Dim parentViewTag As Tag = Tag.Null
Dim numSxViews As Integer
Dim sxViewTags() As Tag = Nothing
Dim numSegments As Integer
Dim segmentTags() As Tag = Nothing
Dim status As UFDraw.SxlineStatus
Dim rotationPtObj As UFDrf.Object = Nothing
Dim numLeg1Segments As Integer
Dim cutPlaneLeg As UFDraw.SxlineLeg

Dim returnTags As New List(Of Tag)

Select Case sectionLineType
Case Is = UFDraw.SxlineType.SimpleSxline
_theUfSession.Draw.AskSimpleSxline(sectionLineTag, stepDir, arrowDir, parentViewTag, numSxViews, sxViewTags, numSegments, segmentTags, _theSectionLineStatus)

Case Is = UFDraw.SxlineType.SteppedSxline
_theUfSession.Draw.AskSteppedSxline(sectionLineTag, stepDir, arrowDir, parentViewTag, numSxViews, sxViewTags, numSegments, segmentTags, _theSectionLineStatus)

Case Is = UFDraw.SxlineType.RevolvedSxline
_theUfSession.Draw.AskRevolvedSxline(sectionLineTag, stepDir, arrowDir, parentViewTag, rotationPtObj, numSxViews, sxViewTags, numSegments, numLeg1Segments, cutPlaneLeg, segmentTags, _theSectionLineStatus)

Case Is = UFDraw.SxlineType.HalfSxline
_theUfSession.Draw.AskHalfSxline(sectionLineTag, stepDir, arrowDir, parentViewTag, numSxViews, sxViewTags, numSegments, segmentTags, _theSectionLineStatus)

Case Is = UFDraw.SxlineType.UnfoldedSxline
_theUfSession.Draw.AskUnfoldedSxline(sectionLineTag, stepDir, arrowDir, parentViewTag, numSxViews, sxViewTags, numSegments, segmentTags, _theSectionLineStatus)

Case Is = UFDraw.SxlineType.FoldedSxline
Return Nothing

Case Is = UFDraw.SxlineType.Breakline
'the view with the break is the section view itself
Return Nothing

End Select

'find the parent view
If Not parentViewTag = Tag.Null Then
_sectionViewParent = Utilities.NXObjectManager.Get(parentViewTag)
End If

'get the underlying curve tag from the segment
For Each temp As Tag In segmentTags
Dim segInfo As UFDraw.SxsegInfo
Dim curveTag As Tag = Tag.Null
Dim obj() As UFDrf.Object = Nothing
_theUfSession.Draw.AskSxlineSxseg(temp, segInfo, curveTag, obj)

If segInfo.sxseg_type = UFDraw.SxsegType.SxsegArrow Then
'labels are associated to the arrow segments
returnTags.Add(curveTag)
End If
Next

Return returnTags

End Function

#End Region

End Class

public static void Notes()
{

Session thesession = Session.GetSession();
UFSession theUfSession = UFSession.GetUFSession();
Part workPart = thesession.Parts.Work;

ListingWindow lw = thesession.ListingWindow;
lw.Open();

Tag sectionLineTag = Tag.Null;
UFDraw.SxlineType sectionLineType;
theUfSession.Draw.AskSxlineType(sectionLineTag, out sectionLineType);

double[] stepDir = new double[3];
double[] arrowDir = new double[3];
Tag parentViewTag = Tag.Null;
int numSxViews=5;
Tag[] sxViewTags = new Tag[3];
int numSegments=2;
Tag[] segmentTags = new Tag[3];
UFDraw.SxlineStatus status;
//UFDrf.Object rotationPtObj = null/* TODO Change to default(_) if this is not a reference type */;
int numLeg1Segments;
UFDraw.SxlineLeg cutPlaneLeg;

Tag sectionline = ;
theUfSession.Draw.AskSimpleSxline(sectionLineTag, stepDir, arrowDir, out parentViewTag, out numSxViews, out sxViewTags, out numSegments, out segmentTags, out status);

NXOpen.Annotations.Note sectionline_xc = (NXOpen.Annotations.Note)NXOpen.Utilities.NXObjectManager.Get(sectionline);

string xc_viewlabel = sectionline_xc.AnnotationOrigin.X.ToString();

lw.WriteLine(xc_viewlabel);
}

Hi I tried using the above code. Listing window does not appear. Could you please help me.

Thank you.

In the code above, the string "xc_viewlabel" is probably null or empty because "sectionLineTag" and "parentViewTag" are null.

Hi Is there any other simpler method. Thank you.

Hi,

I tried with below code. Same the listing window does not appear.
Could you please let me know where is the mistake. Thank you very much for your support.

NXOpen.View[] views1 = new NXOpen.View[1];

foreach (NXOpen.View sxView in workPart.Views)
{
views1[0] = sxView;

Tag sectionLineTag = default(Tag);

theUfSession.Draw.AskSxlineOfSxview(sxView.Tag, out sectionLineTag);

theUfSession.Draw.AskSxlineOfSxview(sxView.Tag, out sectionLineTag);

NXOpen.Drawings.SectionLine theSectionLine;
theSectionLine = (NXOpen.Drawings.SectionLine)NXOpen.Utilities.NXObjectManager.Get(sectionLineTag);

NXOpen.Annotations.Note sectag = (NXOpen.Annotations.Note)NXOpen.Utilities.NXObjectManager.Get(sectionLineTag);

//return theSectionLine;

string x_c = sectag.AnnotationOrigin.X.ToString();

lw.WriteLine(x_c);
}

I'm surprised that you don't get an error when your code attempts to convert a section line object to an annotation. I've given you working code to get the section line letters, I'm not sure what your question is...

Hi,

Thank you for your response. I really appreciate for your time.I tried below code and it worked. Thank you vmuch.

public static void CreateAnnotationMap()
{
Session thesession = Session.GetSession();
UFSession theUfSession = UFSession.GetUFSession();
Part workPart = thesession.Parts.Work;

ListingWindow lw = thesession.ListingWindow;
lw.Open();

foreach (NXOpen.Annotations.Note temp in thesession.Parts.Display.Notes)
{
if (temp.HasAssociativeOrigin)
{
Point3d pt;
NXOpen.Annotations.Annotation.AssociativeOriginData originData;
originData = temp.GetAssociativeOrigin(out pt);

if (originData.OriginType == NXOpen.Annotations.AssociativeOriginType.RelativeToGeometry)
{
string x_c = temp.AnnotationOrigin.X.ToString();
string y_c = temp.AnnotationOrigin.Y.ToString();
lw.WriteLine(" note associativity type: " + originData.OriginType + x_c +","+y_c);

//NXObject geoPt = originData.PointOnGeometry;
//TaggedObject smartParent;
//smartParent = GetSmartParent(ref geoPt, 0);

//if ((smartParent) != null)
// _annotationMap.Add(smartParent.Tag, temp);
}
}
}
}