Hello,
I try to get the informations from a label. I need to get the object from the leader.
I use the following code:
Dim theobject as displayableobject
Dim theview as view
Dim thepoint as point3d
LeaderData.Leader.SetValue(theobject, theview, thepoint)
If the label is created with the function note from the user interface it works perfectly.
On my drawing there are a lot of labels created with a shipbuilding function.
The object I got from this label is a scalar.
It seems to be a special type of label created for shipbuilding purpose. The text is connected to an attribute of a body.
What I need is the body Is associated to the label leader.
Is there a possibility to get the body from a scalar?
I can´t convert it to face or edge because it is a smartobject.
View: exact before NX8.5
re: object from label
I do not have an NX shipbuilding license nor am I familiar with these types of labels. However, I would suggest using the .AskParents method to query the parents of the scalar. By recursively looking through the parent objects, you may find an object of the type you are looking for.
Below is some code that I wrote a while back while looking at the parents of point objects. It looks specifically for point objects, but you should be able to adapt the pertinent portion of the code for your needs.
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 theUI As UI = UI.GetUI()
Dim lw As ListingWindow = theSession.ListingWindow
Sub Main()
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "NXJ point parents")
lw.Open()
For Each tempPt As Point In theSession.Parts.Work.Points
lw.WriteLine("Point Tag: " & tempPt.Tag.ToString)
GetSmartParents(tempPt, 2)
lw.WriteLine("")
Next
lw.Close()
End Sub
Sub GetSmartParents(ByRef theSmartObject As NXObject, ByVal indent As Integer)
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)
lw.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)
lw.WriteLine(New String(" "c, indent) & "parent type: " & objParent.GetType.ToString)
lw.WriteLine(New String(" "c, indent) & "parent tag: " & objParent.Tag.ToString)
If TypeOf (objParent) Is Scalar Then
Dim theScalar As Scalar = objParent
lw.WriteLine(New String(" "c, indent) & "dimensionality: " & theScalar.Dimensionality.ToString)
lw.WriteLine(New String(" "c, indent) & "value: " & theScalar.Value.ToString)
End If
If TypeOf (objParent) Is Offset Then
Dim theOffset As Offset = objParent
lw.WriteLine(New String(" "c, indent) & "vector: " & theOffset.Vector.ToString)
End If
GetSmartParents(objParent, indent + 2)
Next
lw.WriteLine("")
End If
Catch ex As NXException
lw.WriteLine("error: " & ex.ErrorCode)
lw.WriteLine(" " & ex.Message)
End Try
End Sub
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
Hello,
Hello,
thanks a lot for the quick answer.
I just tested your method in the following way.
Dim oldnotebuilder As Annotations.DraftingNoteBuilder
oldnotebuilder = workpart.Annotations.CreateDraftingNoteBuilder(Label123)
If oldnotebuilder.Leader.Leaders.Length = 0 Then
lw.WriteLine("kein Leader gefunden")
End If
Dim tagobj As Annotations.LeaderData
tagobj = oldnotebuilder.Leader.Leaders.FindItem(0)
Dim oldleaderdata As Annotations.LeaderData = CType(tagobj, Annotations.LeaderData)
Dim theObject As DisplayableObject = Nothing
Dim theView As Drawings.DraftingView = Nothing
Dim thePoint As Point3d
oldleaderdata.Leader.GetValue(theObject, theView, thePoint)
If TypeOf (theObject) Is Face Then
lw.WriteLine("Face")
End If
If TypeOf (theObject) Is Edge Then
lw.WriteLine("Edge")
End If
If TypeOf (theObject) Is Scalar Then
lw.WriteLine("Scalar")
GetSmartParents(theObject, 2)
End If
The type of the object is scalar and triggers your method but theobject is not smartobject. in this case it returns false.
Sub GetSmartParents(ByRef theSmartObject As NXObject, ByVal indent As Integer)
Dim numParents As Integer
Dim theParentTags() As Tag = Nothing
Dim isSmart As Boolean = False
Try
theUfSession.So.IsSo(theSmartObject.Tag, isSmart)
lw.WriteLine(isSmart.ToString) 'is false
Is there another way to get the parents (body) from scalar??
Thanks Hagen
NX 9 and Team Center 10
re: scalar
Sorry, that was my best (and only) idea...
You might consider posting the question to the Siemens community customization/programming forum; there are some knowledgeable people there that may have the answer. Or, you can contact GTAC (the NX help desk); they have people that specialize in using the API - they may be able to help you.