Quantcast
Channel: NX Journaling - Journaling / NXOpen API
Viewing all articles
Browse latest Browse all 783

Auto label creation for Drafting Points

$
0
0

Hello All,

Below journal creates label for the visible drafting points as the same name as that of the point objects.

Label positioning is based on the cursor position selection.
Could someone help with the positioning of the point labels based on the WCS.

' NX 12.0.1.7' Journal created by Balaji_Sampath03 on Mon Jun 29 20:50:40 2020 India Standard Time 
'**************************************************************************************'This Macro creates the Point Label for all visible drafting points in the view'All the points are labeled based on the 3D point object names'This macro does not have any exception to catch any errors and is not tested extensively'Location of the point labels are selected by the cursor picking a position on the screen'*************************************************************************************** 
Option Strict Off
 
Imports System
Imports System.Collections.GenericImports NXOpen
Imports NXOpen.AnnotationsImports NXOpen.UIImports NXOpen.UFImports NXOpen.Utilities 
Module ViewDepEdit
 
Sub Main (ByVal args()AsString) 
Dim theSession As Session = Session.GetSession()Dim theUfSession As UFSession = UFSession.GetUFSession()Dim workPart As Part = theSession.Parts.WorkDim displayPart As Part = theSession.Parts.DisplayDim theDraftView As Drawings.DraftingViewDim ptsPoints AsNew List(Of Point)Dim ptsNames AsNew List(OfString)Dim ptsCount AsInteger="0"Dim tempName AsString=Nothing 
Dim lw As ListingWindow = theSession.ListingWindow 
Do Until SelDraftingView("select drafting view", theDraftView)= Selection.Response.Cancel 
''''''''''''''''''''''''''''''''''Get a location for Point label'''''''''''''''''''''''''''''''''Dim cursor As Point3d
Dim response As Selection.DialogResponse= SelectScreenPos(cursor)If response <> Selection.DialogResponse.PickThenReturnEndIf 
ForEach tempObj As DisplayableObject In theDraftView.AskVisibleObjectsIfTypeOf tempObj Is Point Then
		ptsPoints.Add(tempObj)
		tempName = tempObj.Name
		ptsNames.Add(tempName)
		tempObj.HighlightEndIfNext 
For i AsInteger=0to ptsPoints.Count-1
	ptsCount +=1 
	Dim markId1 As NXOpen.Session.UndoMarkId=Nothing
	markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start") 
	Dim nullNXOpen_Annotations_SimpleDraftingAid As NXOpen.Annotations.SimpleDraftingAid=NothingDim draftingNoteBuilder1 As NXOpen.Annotations.DraftingNoteBuilder=NothingDim leaderData1 As NXOpen.Annotations.LeaderData=NothingDim symbolscale1 AsDouble=NothingDim symbolaspectratio1 AsDouble=Nothing 
		Dim text1(0)AsString
		text1(0)= ptsNames.Item(i) 
	draftingNoteBuilder1 = workPart.Annotations.CreateDraftingNoteBuilder(nullNXOpen_Annotations_SimpleDraftingAid)
	draftingNoteBuilder1.Origin.SetInferRelativeToGeometry(True)
	draftingNoteBuilder1.Origin.Anchor= NXOpen.Annotations.OriginBuilder.AlignmentPosition.MidCenter
	draftingNoteBuilder1.Text.TextBlock.SetText(text1)
	draftingNoteBuilder1.TextAlignment= NXOpen.Annotations.DraftingNoteBuilder.TextAlign.Belowbottom
	draftingNoteBuilder1.Origin.Plane.PlaneMethod= NXOpen.Annotations.PlaneBuilder.PlaneMethodType.XyPlane
	draftingNoteBuilder1.Origin.SetInferRelativeToGeometry(True) 
	leaderData1 = workPart.Annotations.CreateLeaderData()
	leaderData1.StubSize=5.0
	leaderData1.Arrowhead= NXOpen.Annotations.LeaderData.ArrowheadType.FilledArrow
	leaderData1.VerticalAttachment= NXOpen.Annotations.LeaderVerticalAttachment.Center 
	draftingNoteBuilder1.Leader.Leaders.Append(leaderData1) 
	leaderData1.StubSide= NXOpen.Annotations.LeaderSide.Inferred
	leaderData1.StubSize=2 
	symbolscale1 = draftingNoteBuilder1.Text.TextBlock.SymbolScale
	symbolaspectratio1 = draftingNoteBuilder1.Text.TextBlock.SymbolAspectRatio 
	Dim baseView1 As NXOpen.Drawings.DraftingView= theDraftView
	Dim draftingPoint1 As NXOpen.Drawings.DraftingPoint= ptsPoints.Item(i) 
	Dim point1_1 As NXOpen.Point3d=New NXOpen.Point3d(0.0, 0.0, 0.0)
	point1_1 = ptsPoints(i).CoordinatesDim point2_1 As NXOpen.Point3d=New NXOpen.Point3d(0.0, 0.0, 0.0)
	point2_1 = ptsPoints(i).Coordinates 
	Dim nullNXOpen_View As NXOpen.View=Nothing
	leaderData1.Leader.SetValue(NXOpen.InferSnapType.SnapType.Exist, draftingPoint1, baseView1, point1_1, Nothing, nullNXOpen_View, point2_1) 
	'Jog position relocated or jog removed
	leaderData1.Jogs.Clear() 
	Dim assocOrigin1 As NXOpen.Annotations.Annotation.AssociativeOriginData=Nothing
	assocOrigin1.OriginType= NXOpen.Annotations.AssociativeOriginType.Drag
	assocOrigin1.View= nullNXOpen_View
	assocOrigin1.ViewOfGeometry= nullNXOpen_View
	Dim nullNXOpen_Point As NXOpen.Point=Nothing 
	assocOrigin1.PointOnGeometry= nullNXOpen_Point
	Dim nullNXOpen_Annotations_Annotation As NXOpen.Annotations.Annotation=Nothing 
	assocOrigin1.VertAnnotation= nullNXOpen_Annotations_Annotation
	assocOrigin1.HorizAnnotation= nullNXOpen_Annotations_Annotation
	assocOrigin1.AlignedAnnotation= nullNXOpen_Annotations_Annotation
	assocOrigin1.VertAlignmentPosition= NXOpen.Annotations.AlignmentPosition.TopLeft
	assocOrigin1.HorizAlignmentPosition= NXOpen.Annotations.AlignmentPosition.TopLeft
	assocOrigin1.DimensionLine=0
	assocOrigin1.AssociatedView= nullNXOpen_View
	assocOrigin1.AssociatedPoint= ptsPoints(i)
	assocOrigin1.OffsetAnnotation= nullNXOpen_Annotations_Annotation
	assocOrigin1.OffsetAlignmentPosition= NXOpen.Annotations.AlignmentPosition.TopLeft
	assocOrigin1.XOffsetFactor=0.0
	assocOrigin1.YOffsetFactor=0.0
	assocOrigin1.StackAlignmentPosition= NXOpen.Annotations.StackAlignmentPosition.Above 
	Dim label_ABS_Loc As NXOpen.Point3d=New NXOpen.Point3d(0.0, 0.0, 0.0)
	label_ABS_Loc = ptsPoints(i).Coordinates 
'*******************'Convert ABS to WCS'******************* 
	'Dim label_WCS_Loc As NXOpen.Point3d = Nothing'Dim pt1(2), pt2(2) As Double 
	'pt1(0) = ptsPoints(i).Coordinates.X'pt1(1) = ptsPoints(i).Coordinates.Y'pt1(2) = ptsPoints(i).Coordinates.Z 
	'theUfSession.Csys.MapPoint(UFConstants.UF_CSYS_ROOT_COORDS, pt1, _'			UFConstants.UF_CSYS_ROOT_WCS_COORDS, pt2) 
	'label_WCS_Loc.X = pt2(0)'label_WCS_Loc.Y = pt2(1)'label_WCS_Loc.Z = pt2(2) 
'*****************************************'Select Label position upon Cursor picking'***************************************** 
	draftingNoteBuilder1.Origin.Origin.SetValue(Nothing, nullNXOpen_View, cursor)'draftingNoteBuilder1.Origin.Origin.SetValue(Nothing, nullNXOpen_View, label_ABS_Loc) 
	draftingNoteBuilder1.Origin.SetInferRelativeToGeometry(True)
	leaderData1.StubSide= NXOpen.Annotations.LeaderSide.Right 
	Dim nXObject1 As NXOpen.NXObject=Nothing 
	nXObject1 = draftingNoteBuilder1.Commit()
	draftingNoteBuilder1.Destroy() 
	theSession.DeleteUndoMark(markId1, "Auto Label Points") 
Next 
ptsPoints.Clear()
ptsNames.Clear() 
Loop 
'********************'Clear Selection List'******************** 
'Dim markIdPartClean As NXOpen.Session.UndoMarkId = Nothing'markIdPartClean = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Part Cleanup") 
Dim partCleanup As NXOpen.PartCleanup=Nothing
partCleanup = theSession.NewPartCleanup()
partCleanup.TurnOffHighlighting=True
partCleanup.DoCleanup()
partCleanup.Dispose()'theSession.DeleteUndoMark(markIdPartClean, Nothing) 
EndSub 
Function SelDraftingView(ByVal prompt AsString, ByRef selView As Drawings.DraftingView)As Selection.Response 
	Dim theUI As UI = UI.GetUIDim title AsString="Select a drafting view"Dim includeFeatures AsBoolean=FalseDim keepHighlighted AsBoolean=FalseDim selAction As Selection.SelectionAction= Selection.SelectionAction.ClearAndEnableSpecificDim cursor As Point3d
        Dim scope As Selection.SelectionScope= Selection.SelectionScope.WorkPartDim selectionMask_array(0)As Selection.MaskTripleDim selObj As TaggedObject
 
        With selectionMask_array(0).Type= UFConstants.UF_view_type.Subtype= UFConstants.UF_all_subtypeEndWith 
        Dim resp As Selection.Response= theUI.SelectionManager.SelectTaggedObject(prompt, _
         title, scope, selAction, _
         includeFeatures, keepHighlighted, selectionMask_array, _
         selObj, cursor)If resp = Selection.Response.ObjectSelectedOrElse resp = Selection.Response.ObjectSelectedByNameThen
            selView =CType(selObj, Drawings.DraftingView)Return Selection.Response.OkElseReturn Selection.Response.CancelEndIf 
EndFunction 
PublicFunction SelectScreenPos(ByRef pos As Point3d)As Selection.DialogResponseDim theUI As UI = UI.GetUI()Dim view As NXOpen.View=NothingDim letteringPrefs As LetteringPreferences =NothingDim userSymPrefs As UserSymbolPreferences =NothingReturn theUI.SelectionManager.SelectScreenPosition("Select location for tabnote", view, pos)EndFunction 
PublicFunction GetUnloadOption(ByVal dummy AsString)AsInteger 
        'Unloads the image when the NX session terminates'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination 
        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately 
        'Unloads the image explicitly, via an unload dialog'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly 
EndFunction 
EndModule

Viewing all articles
Browse latest Browse all 783

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>