I have a .dll that I wanted to call from a vb as a Catch, in case there is an exception happens in my program. Mainly wanted to know the syntax of calling a .dll from a .vb if possible.
Calling a .dll from .vb
SetUserAttribute doesn't create it
Hello
I have a user attribute that is synced with Teamcenter. If I try to set it via script it doesn't create it, even tho the documentation says it should:
workPart.SetUserAttribute("MD_DIMENSION", -1, "123", Update.Option.Now)
But if I set it via TeamCenter I'm able to update it via this function.
Am I missing something? How can I set this attribute even if it wasn't set before?
how to convert .vb to .dll without visual studio
Hi
I have recorded a journal (.VB) file now i want to convert to .dll, without visual studio, Is there any convertor or tool avalable,
Thanks in Advance
Truncated Dimensions
Hi folks,
I'm new in journaling.
I'm looking for a journal example for changing color of truncated dimensions (which are added manually) on drawing. It should automatically change truncated dim. color for color green so user can verify if modelling was done properly (in some cases it really helps).
As I said I have poor experience in IT stuff, so at the beginning I would like to recall to the proper parameter of one dimension eg. I have vertical dimension which equals 1 and I just would like to know if this parameter is equal/or not 1.
My "code":
dim count as integer = 0
For Each VerticalDim As Annotations.VerticalDimension In workpart.dimensions
if VerticalDim.Value ...
count += 1
end if
next
Guide.InfoWriteLine("its sth")
I will be very grateful for any help
Endless "Work in Progress" Box
I have some code that displays a form which retrieves an expression value from NX and displays it in a textbox on the form if the textbox value is changed by the user the expression value is updated to the new value. I am using this method on a bunch of expressions but the problem I am running into is when i change the value and apply it using an "Apply" Button on my form I get a message box for "Work in Progress" that never closes even after the value has updated.
Dim Exp As NXOpen.Expression = CType(workPart.Expressions.FindObject("OS_OD"), NXOpen.Expression) 'get expression
Dim ob1 As TextBox = TextBox1 'get string from textbox
Dim Val As String = MainMenu.OSA 'get expession value
If IsNumeric(Trim(ob1.Text)) = True And ob1.Text <> Exp.Value Then 'check if text box is a number and different from current value
workPart.Expressions.Edit(Exp, ob1.Text) 'expression = to TB text
Else
MsgBox("Please Enter a valid numerical value selected field", vbOK) 'error found in TB string
ob1.Select()
End If
Datum Zone Of First Instance of Each Datum
Hi
below is code which is available in this site for getting zone of drafting datum,
suppose The output will be like
Datum : A
Sheet number : 3
Zone: A10
Datum : A
Sheet number : 2
Zone: A1
Datum : A
Sheet number : 1
Zone: B12
etc
How to get zone for only first occurance of each datum
Datum : A
Sheet number : 1
Zone: B12
Datum : B
Sheet number : 2
Zone: C5
Datum : C
Sheet number : 1
Zone: D7
etc
Can you please help me in getting zone of first occurnce of each datum, Thanks in Advance,
Below is cide :
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Module Module5
Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession
Sub Main()
If IsNothing(theSession.Parts.Work) Then
'active part required
Return
End If
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
For Each temp As NXObject In theSession.Parts.Work.Gdts
'lw.WriteLine(" type: "& temp.GetType.ToString)
If TypeOf (temp) Is Annotations.DraftingDatum Then
Dim myDraftingDatum As Annotations.DraftingDatum = temp
Dim myDraftingDatumZone As New NXJSheetZoneInfo
myDraftingDatumZone = ReportAnnotationSheetZone(AskDrawingSheet(myDraftingDatum), myDraftingDatum)
lw.WriteLine("Datum: "& myDraftingDatum.Label)
lw.WriteLine("Sheet number: "& myDraftingDatumZone.Sheet)
lw.WriteLine("Zone: "& myDraftingDatumZone.VerticalZone & myDraftingDatumZone.HorizontalZone)
lw.WriteLine("")
End If
Next
lw.Close()
End Sub
Function AskDrawingSheet(ByVal theObject As TaggedObject) As Drawings.DrawingSheet
'Code written by Amy Webster of GTAC
' see nx_api4936 or nx_api4937
' This function will work for:
' an object which "Resides on drawing" or is "View Dependent In" a DraftingView
' a DraftingView
' a DrawingSheet.View
' Returns Nothing for all other (ie. model mode) objects
Dim theView As View = TryCast(theObject, View)
If Not theView Is Nothing Then
Dim sheetTag As Tag = Nothing
Try
theUfSession.Draw.AskDrawingOfView(theView.Tag, sheetTag)
Return Utilities.NXObjectManager.Get(sheetTag) ' the drawing it is on
Catch ex As NXException
Return Nothing ' it is a model view
End Try
End If
Dim viewName As String = Nothing
Dim status As Integer = Nothing
Try
theUfSession.View.AskViewDependentStatus(theObject.Tag, status, viewName)
Catch ex As NXException
Return Nothing
End Try
If status = 0 Then Return Nothing ' it is a model mode object
Dim viewTag As Tag = Nothing
theUfSession.View.AskTagOfViewName(viewName, viewTag)
Dim viewType As Integer = Nothing
Dim viewSubtype As Integer = Nothing
theUfSession.View.AskType(viewTag, viewType, viewSubtype)
If viewType = 0 Then Return Nothing ' it is view dependent in a modeling view
Dim drawingTag As Tag = Nothing
theUfSession.Draw.AskDrawingOfView(viewTag, drawingTag)
Return Utilities.NXObjectManager.Get(drawingTag) ' the drawing it is on!
End Function
Function ReportAnnotationSheetZone(ByVal theSheet As Drawings.DrawingSheet, ByVal theAnnotation As Annotations.Annotation) As NXJSheetZoneInfo
Dim info As New NXJSheetZoneInfo
Dim borderBuilder As Drawings.BordersAndZonesBuilder
If IsNothing(theSheet.BordersAndZones) Then
Return Nothing
End If
borderBuilder = theSession.Parts.Work.Drafting.BordersAndZonesObjects.CreateBordersAndZonesBuilder(theSheet.BordersAndZones)
Dim numHorizontalZones As Integer = (theSheet.Length - borderBuilder.LeftMargin - borderBuilder.RightMargin) / borderBuilder.HorizontalSize
Dim numVerticalZones As Integer = (theSheet.Height - borderBuilder.BottomMargin - borderBuilder.TopMargin) / borderBuilder.VerticalSize
'calculate zone wrt bottom left of drawing (ZoneOrigin.BottomLeft)
Dim Hcell As Double = (theAnnotation.AnnotationOrigin.X - borderBuilder.LeftMargin) / borderBuilder.HorizontalSize
Dim Vcell As Double = (theAnnotation.AnnotationOrigin.Y - borderBuilder.BottomMargin) / borderBuilder.VerticalSize
Hcell = Math.Ceiling(Hcell)
Vcell = Math.Ceiling(Vcell)
Dim theZoneOrigin As Drawings.BordersAndZonesBuilder.ZoneOrigin = borderBuilder.Origin
borderBuilder.Destroy()
Dim verticalLetterNum As Integer
Dim verticalLetter As Char
Dim horizontalNum As Integer
If theZoneOrigin = Drawings.BordersAndZonesBuilder.ZoneOrigin.BottomLeft Or theZoneOrigin = Drawings.BordersAndZonesBuilder.ZoneOrigin.TopLeft Then
'origin on left side
horizontalNum = Hcell
Else
'origin on right side
horizontalNum = numHorizontalZones - Hcell + 1
End If
If theZoneOrigin = Drawings.BordersAndZonesBuilder.ZoneOrigin.BottomLeft Or theZoneOrigin = Drawings.BordersAndZonesBuilder.ZoneOrigin.BottomRight Then
'origin on bottom
verticalLetterNum = Asc("A") + Vcell - 1
verticalLetter = Chr(verticalLetterNum)
Else
'origin on the top
verticalLetterNum = Asc("A") + numVerticalZones - Vcell
verticalLetter = Chr(verticalLetterNum)
End If
Dim theSheetNum As String = SheetNumber(theSheet)
info.Sheet = theSheetNum
info.VerticalZone = verticalLetter
info.HorizontalZone = horizontalNum
Return info
End Function
Function SheetNumber(ByVal theSheet As Drawings.DrawingSheet) As String
Dim sheetNum As Integer
Dim theSheetBuilder As Drawings.DrawingSheetBuilder = theSession.Parts.Work.DrawingSheets.DrawingSheetBuilder(theSheet)
sheetNum = theSheetBuilder.Number
theSheetBuilder.Destroy()
Return sheetNum.ToString
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 NXJSheetZoneInfo
Private _sheet As String = ""
Public Property Sheet() As String
Get
Return _sheet
End Get
Set(ByVal value As String)
_sheet = value
End Set
End Property
Private _horizontalZone As String = ""
Public Property HorizontalZone() As String
Get
Return _horizontalZone
End Get
Set(ByVal value As String)
_horizontalZone = value
End Set
End Property
Private _verticalZone As String = ""
Public Property VerticalZone() As String
Get
Return _verticalZone
End Get
Set(ByVal value As String)
_verticalZone = value
End Set
End Property
Public Sub New()
End Sub
End Class
Find and replacing note when attached with leader
Hello,
Below is code which is available in this site, it is working fine suppose when i am replacing word ABC with XYZ, but not working when same word ABC is attached with leader, can you please help, Thanks in advance
below is code :
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI
Imports NXOpen.Utilities
Imports NXOpen.Annotations
Module ChangeNoteWord
Sub Main()
Dim s As Session = Session.GetSession()
Dim dp As Part = s.Parts.Display
Dim nc As NoteCollection = dp.Notes
Dim notetext1 As String = "CURRENT WORD"
notetext1 = NXInputBox.GetInputString("Change Note", "Note word to be changed", notetext1)
Dim notetext2 As String = "REPLACEMENT WORD"
notetext2 = NXInputBox.GetInputString("Change Note", "New note word", notetext2)
Dim notestring() As String
Dim nolines As Integer = 0
Dim found1 As Boolean = False
Dim m1 As Session.UndoMarkId = s.SetUndoMark(Session.MarkVisibility.Visible, "M1")
For Each a_note As SimpleDraftingAid In nc
notestring = a_note.GetText()
nolines = notestring.Length
For i As Integer = 0 To nolines - 1
found1 = notestring(i).Contains(notetext1)
If found1 = True Then
notestring(i) = notestring(i).Replace(notetext1, notetext2)
End If
Next
a_note.SetText(notestring)
Next
s.UpdateManager.DoUpdate(m1)
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function
End Module
Point on face with work part
Here's a journal found on this forum. It can only be preformed on display part. How to make it functional on "work part".
Option Strict Off Imports System Imports System.CollectionsImports System.Collections.Generic Imports NXOpen Imports NXOpen.UFImports NXOpenUI Imports NXOpen.FeaturesImports NXOpen.Utilities Module Module1 Dim theSession As Session = Session.GetSession()Dim theUfSession As UFSession = UFSession.GetUFSession()Dim ui As UI = UI.GetUI()Dim workpart As Part = theSession.Parts.WorkDim lw As ListingWindow = theSession.ListingWindow() Sub Main() Dim displayPart As Part = theSession.Parts.DisplayDim response As Selection.Response= Selection.Response.CancelDim prompt AsString="Select Position on Face"Dim temptag As Tag = Tag.NullDim cp(2)AsDoubleDim face1 As Face =NothingDim facetag As Tag = Tag.NullDim point1 As Point =NothingDim mySelectedObject As NXObject Dim Name AsString=""Dim test AsStringDim i AsIntegerDim j AsInteger=1Dim FGTag As Tag = Tag.NullDim FGITag As Tag = Tag.NullDim feat_Group AsNew List(Of Tag) Dim MyBody As Body =NothingDim a_body As NXOpen.Tag= NXOpen.Tag.NullDim endPoint As Point3d Dim featuresToGroup As Tag()=Nothing lw.Open() lw.WriteLine("") Start1: facetag = select_point_on_face(prompt, cp)If facetag = Tag.NullThenGoTo End1 face1 = NXObjectManager.Get(facetag)Dim pnt3d As Point3d =New Point3d(cp(0), cp(1), cp(2)) point1 = PointFeatureOnFace(pnt3d) i +=1 Dim pt(2)AsDoubleDim u1(2)AsDoubleDim v1(2)AsDoubleDim u2(2)AsDoubleDim v2(2)AsDoubleDim norm(2)AsDoubleDim radii(1)AsDoubleDim param(1)AsDouble theUfSession.Modl.AskFaceParm(facetag, cp, param, pt) theUfSession.Modl.AskFaceProps(facetag, param, pt, u1, v1, u2, v2, norm, radii) Dim WcsNorm(2)AsDouble theUfSession.Csys.MapPoint(UFConstants.UF_CSYS_ROOT_COORDS, norm, UFConstants.UF_CSYS_ROOT_WCS_COORDS, WcsNorm) lw.WriteLine("X:"&(norm(0)).ToString&" Y:"&(norm(1)).ToString&" Z:"&(norm(2)).ToString) lw.WriteLine("XC: "& WcsNorm(0).ToString&" YC: "& WcsNorm(1).ToString&" ZC: "& WcsNorm(2).ToString) GoTo Start1 End1: EndSub PublicFunction select_point_on_face(ByVal prompt AsString, ByRef cp()AsDouble)As NXOpen.TagDim resp AsInteger=0Dim face1 As Face =NothingDim theView As NXOpen.Tag= NXOpen.Tag.NullDim mask_face As UFUi.SelInitFnT=AddressOf mask_for_face Dim facetag As Tag = Tag.Null theUfSession.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM) theUfSession.Ui.SelectWithSingleDialog("Select a face", prompt, UFConstants.UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY, mask_face, Nothing, resp, facetag, cp, theView) theUfSession.Ui.UnlockUgAccess(UFConstants.UF_UI_FROM_CUSTOM) If resp = UFConstants.UF_UI_OBJECT_SELECTEDOr resp = UFConstants.UF_UI_OBJECT_SELECTED_BY_NAMEThen ask_pos_on_obj(facetag, cp) theUfSession.Disp.SetHighlight(facetag, 0)Return facetag EndIfReturn Tag.NullEndFunction PublicSub map_view2abs(ByRef c()AsDouble)Dim vname AsString=""Dim abs_mx()AsDouble={0, 0, 0, 1, 0, 0, 0, 1, 0}Dim vw()AsDouble={0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}Dim mx()AsDouble={0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}Dim irc AsInteger=0 theUfSession.Ui.AskLastPickedView(vname)Dim wp As Part = theSession.Parts.WorkDim lastViewPicked As View =CType(wp.ModelingViews.FindObject(vname), ModelingView)Dim vmx As Matrix3x3 = lastViewPicked.Matrix() vw(3)= vmx.Xx vw(4)= vmx.Xy vw(5)= vmx.Xz vw(6)= vmx.Yx vw(7)= vmx.Yy vw(8)= vmx.Yz vw(9)= vmx.Zx vw(10)= vmx.Zy vw(11)= vmx.Zz theUfSession.Trns.CreateCsysMappingMatrix(vw, abs_mx, mx, irc) theUfSession.Trns.MapPosition(c, mx)EndSub PublicSub map_abs2view(ByRef c()AsDouble)Dim vname AsString=""Dim abs_mx()AsDouble={0, 0, 0, 1, 0, 0, 0, 1, 0}Dim vw()AsDouble={0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}Dim mx()AsDouble={0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}Dim irc AsInteger=0 theUfSession.Ui.AskLastPickedView(vname)Dim wp As Part = theSession.Parts.WorkDim lastViewPicked As View =CType(wp.ModelingViews.FindObject(vname), ModelingView)Dim vmx As Matrix3x3 = lastViewPicked.Matrix() vw(3)= vmx.Xx vw(4)= vmx.Xy vw(5)= vmx.Xz vw(6)= vmx.Yx vw(7)= vmx.Yy vw(8)= vmx.Yz vw(9)= vmx.Zx vw(10)= vmx.Zy vw(11)= vmx.Zz theUfSession.Trns.CreateCsysMappingMatrix(abs_mx, vw, mx, irc) theUfSession.Trns.MapPosition(c, mx)EndSub PublicSub ask_pos_on_obj(ByVal obj As NXOpen.Tag, ByValloc()AsDouble)Dim aLine As NXOpen.Tag= NXOpen.Tag.NullDim cp()AsDouble={0, 0, 0}Dim dist AsDouble=0Dim lp As UFCurve.LineDim sp(2)AsDoubleDim ep(2)AsDouble lp.start_point= sp lp.end_point= ep map_abs2view(loc) lp.start_point(0)=loc(0) lp.start_point(1)=loc(1) lp.start_point(2)=loc(2)+10000 lp.end_point(0)=loc(0) lp.end_point(1)=loc(1) lp.end_point(2)=loc(2)-10000 map_view2abs(lp.start_point) map_view2abs(lp.end_point) theUfSession.Curve.CreateLine(lp, aLine) theUfSession.Modl.AskMinimumDist(obj, aLine, 0, cp, 0, cp, dist, loc, cp) theUfSession.Obj.DeleteObject(aLine)EndSub PublicFunction mask_for_face(ByVal select_ As IntPtr, ByVal userdata As IntPtr)AsInteger Dim num_triples AsInteger=1Dim mask_triples(0)As UFUi.Mask mask_triples(0).object_type= UFConstants.UF_solid_type mask_triples(0).object_subtype=0 mask_triples(0).solid_type= UFConstants.UF_UI_SEL_FEATURE_ANY_FACE theUfSession.Ui.SetSelMask(select_, UFUi.SelMaskAction.SelMaskClearAndEnableSpecific, num_triples, mask_triples)Return UFConstants.UF_UI_SEL_SUCCESSEndFunction PublicFunction PointFeatureOnFace(ByValwhereAs Point3d)As Point Dim markId1 As Session.UndoMarkId= theSession.SetUndoMark(Session.MarkVisibility.Visible, "Create Point")Dim point1 As Point point1 = workpart.Points.CreatePoint(where)Dim nullFeatures_Feature As Features.Feature=NothingDim pointFeatureBuilder1 As Features.PointFeatureBuilder pointFeatureBuilder1 = workpart.BaseFeatures.CreatePointFeatureBuilder(nullFeatures_Feature) pointFeatureBuilder1.Point= point1 Dim nXObject1 As NXObject = pointFeatureBuilder1.Commit() pointFeatureBuilder1.Destroy()Return point1 EndFunction PublicFunction GetUnloadOption(ByVal dummy AsString)AsInteger GetUnloadOption = NXOpen.Session.LibraryUnloadOption.ImmediatelyEndFunctionEndModule <vbnet>
Type of Dimension - Reference Prefix
Hi Folks,
I have a problem with recalling the reference dimension which has changed type from
VALUE -> PREFIX. (Settings - Reference - Include - Prefix).
It seems that standard journal doesn't take this dimms into consideration.
Thanks in advance for your help.
Set Property of Drawing when saving part
Hello
I have a function that saves a part and it's drawing:
Sub save_part(name) Dim partOperationCopyBuilder1 As NXOpen.PDM.PartOperationCopyBuilder = theSession.PdmSession.CreateCopyOperationBuilder(NXOpen.PDM.PartOperationBuilder.OperationType.SaveAs) partOperationCopyBuilder1.SetOperationSubType(NXOpen.PDM.PartOperationCopyBuilder.OperationSubType.Default) partOperationCopyBuilder1.DependentFilesToCopyOption = NXOpen.PDM.PartOperationCopyBuilder.CopyDependentFiles.All partOperationCopyBuilder1.ReplaceAllComponentsInSession = True Dim selectedparts1(0) As NXOpen.BasePart selectedparts1(0) = workPart partOperationCopyBuilder1.SetSelectedPartsToCopy(selectedparts1, Nothing) Dim logicalobjects2() As NXOpen.PDM.LogicalObject = Nothing partOperationCopyBuilder1.CreateLogicalObjects(logicalobjects2) Dim objects2(-1) As NXOpen.NXObject Dim attributePropertiesBuilder1 As NXOpen.AttributePropertiesBuilder = theSession.AttributeManager.CreateAttributePropertiesBuilder(Nothing, objects2, NXOpen.AttributePropertiesBuilder.OperationType.None) attributePropertiesBuilder1.SetAttributeObjects(logicalobjects2(0).GetUserAttributeSourceObjects()) attributePropertiesBuilder1.Title = "DB_PART_NAME" attributePropertiesBuilder1.Category = "Item" attributePropertiesBuilder1.StringValue = name attributePropertiesBuilder1.CreateAttribute() partOperationCopyBuilder1.ValidateLogicalObjectsToCommit() partOperationCopyBuilder1.Commit() partOperationCopyBuilder1.Destroy() attributePropertiesBuilder1.Destroy() End Sub
The PropertyBuilder sets the new name of the Part. But can I also create a second property builder but for the drawing?
They don't share them as far as I know. But because I'm saving both at the same time it should be possible, right?
Regards
Engraving on the components
Hi,
I don't have any knowledge to edit the Journals to make it work on other similar components
Could someone share me more helpful resources to edit my own journals as needed
Someone please edit the code for me to work on other part files as well
using this journal, I am trying to engrave on the face & the curve as reference of a component
the engraving is "J1234 BODY 1"& "HH P20"
The part file name is "J1234_Body1"& I set the material of the Part as "HH P20" in the attributes
I would like someone to edit this journal to engrave on the component with user selected Face & Curve by reading the values for "J1234 BODY1" from the Part file name and the Material "HH P20" from the material attributes of the part file
Here is the journal I recorded
Imports System
Imports NXOpen
Module SCJournal
Sub Main (ByVal args() As String)
Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim workPart As NXOpen.Part = theSession.Parts.Work
Dim displayPart As NXOpen.Part = theSession.Parts.Display
' ----------------------------------------------
' Menu: Insert->Curve->Text...
' ----------------------------------------------
Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")
Dim nullNXOpen_Features_Text As NXOpen.Features.Text = Nothing
Dim textBuilder1 As NXOpen.Features.TextBuilder = Nothing
textBuilder1 = workPart.Features.CreateTextBuilder(nullNXOpen_Features_Text)
Dim origin1 As NXOpen.Point3d = New NXOpen.Point3d(0.0, 0.0, 0.0)
Dim normal1 As NXOpen.Vector3d = New NXOpen.Vector3d(0.0, 0.0, 1.0)
Dim plane1 As NXOpen.Plane = Nothing
plane1 = workPart.Planes.CreatePlane(origin1, normal1, NXOpen.SmartObject.UpdateOption.WithinModeling)
textBuilder1.SectionPlane = plane1
Dim unit1 As NXOpen.Unit = Nothing
unit1 = textBuilder1.PlanarFrame.Length.Units
Dim expression1 As NXOpen.Expression = Nothing
expression1 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)
Dim expression2 As NXOpen.Expression = Nothing
expression2 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)
Dim coordinates1 As NXOpen.Point3d = New NXOpen.Point3d(0.0, 0.0, 0.0)
Dim point1 As NXOpen.Point = Nothing
point1 = workPart.Points.CreatePoint(coordinates1)
textBuilder1.FrameOnPath.AnchorPosition.Expression.RightHandSide = "50"
textBuilder1.SelectFont("Arial", NXOpen.Features.TextBuilder.ScriptOptions.Western)
textBuilder1.TextString = "Text"
theSession.SetUndoMarkName(markId1, "Text Dialog")
textBuilder1.Type = NXOpen.Features.TextBuilder.Types.OnFace
Dim extrude1 As NXOpen.Features.Extrude = CType(workPart.Features.FindObject("EXTRUDE(1)"), NXOpen.Features.Extrude)
Dim face1 As NXOpen.Face = CType(extrude1.FindObject("FACE 160 {(0.2078271909714,-2.5,2.3754756627385) EXTRUDE(1)}"), NXOpen.Face)
Dim boundaryFaces1(-1) As NXOpen.Face
Dim faceTangentRule1 As NXOpen.FaceTangentRule = Nothing
faceTangentRule1 = workPart.ScRuleFactory.CreateRuleFaceTangent(face1, boundaryFaces1, 0.5)
Dim rules1(0) As NXOpen.SelectionIntentRule
rules1(0) = faceTangentRule1
textBuilder1.PlacementFaces.ReplaceRules(rules1, False)
textBuilder1.OnFacePlacementProfile.SetAllowedEntityTypes(NXOpen.Section.AllowTypes.OnlyCurves)
Dim markId2 As NXOpen.Session.UndoMarkId = Nothing
markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "section mark")
Dim markId3 As NXOpen.Session.UndoMarkId = Nothing
markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, Nothing)
Dim edge1 As NXOpen.Edge = CType(extrude1.FindObject("EDGE * 160 BLEND(4) 2 {(0,-4.2030442415266,0)(0.2078271909714,-3.9952170505553,2.3754756627385)(0.4156543819427,-3.7873898595839,4.7509513254771) EXTRUDE(1)}"), NXOpen.Edge)
Dim nullNXOpen_Edge As NXOpen.Edge = Nothing
Dim edgeTangentRule1 As NXOpen.EdgeTangentRule = Nothing
edgeTangentRule1 = workPart.ScRuleFactory.CreateRuleEdgeTangent(edge1, nullNXOpen_Edge, True, 0.5, False, False)
textBuilder1.OnFacePlacementProfile.AllowSelfIntersection(True)
Dim rules2(0) As NXOpen.SelectionIntentRule
rules2(0) = edgeTangentRule1
Dim nullNXOpen_NXObject As NXOpen.NXObject = Nothing
Dim helpPoint1 As NXOpen.Point3d = New NXOpen.Point3d(0.22045142856811575, -3.9825928129584871, 2.5197713587520219)
textBuilder1.OnFacePlacementProfile.AddToSection(rules2, edge1, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1, NXOpen.Section.Mode.Create, False)
theSession.DeleteUndoMark(markId3, Nothing)
theSession.DeleteUndoMark(markId2, Nothing)
textBuilder1.Script = NXOpen.Features.TextBuilder.ScriptOptions.Baltic
textBuilder1.Script = NXOpen.Features.TextBuilder.ScriptOptions.CentralEuropean
textBuilder1.SelectFont("Arial Black", NXOpen.Features.TextBuilder.ScriptOptions.Western)
textBuilder1.SelectFont("Modern", NXOpen.Features.TextBuilder.ScriptOptions.Oem)
textBuilder1.OnFacePlacementProfile.ReverseDirection()
textBuilder1.FrameOnPath.Offset.RightHandSide = "1.4"
textBuilder1.FrameOnPath.Offset.RightHandSide = "1.5"
textBuilder1.FrameOnPath.Offset.RightHandSide = "1.6"
textBuilder1.FrameOnPath.Offset.RightHandSide = "1.7"
textBuilder1.FrameOnPath.Offset.RightHandSide = "1.5"
textBuilder1.TextString = "Tex"
textBuilder1.TextString = "Te"
textBuilder1.TextString = ""
textBuilder1.TextString = "J"
textBuilder1.TextString = "J1"
textBuilder1.TextString = "J12"
textBuilder1.TextString = "J123"
textBuilder1.TextString = "J1234"
textBuilder1.TextString = "J1234 BODY 1"
textBuilder1.FrameOnPath.Height.RightHandSide = ".25"
textBuilder1.FrameOnPath.WScale = 50.0
textBuilder1.FrameOnPath.WScale = 100.0
textBuilder1.FrameOnPath.Length.RightHandSide = "1"
textBuilder1.FrameOnPath.Length.RightHandSide = "2"
textBuilder1.PlanarFrame.Length.RightHandSide = "6.57162346521146"
Dim markId4 As NXOpen.Session.UndoMarkId = Nothing
markId4 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Text")
theSession.DeleteUndoMark(markId4, Nothing)
Dim markId5 As NXOpen.Session.UndoMarkId = Nothing
markId5 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Text")
Dim nXObject1 As NXOpen.NXObject = Nothing
nXObject1 = textBuilder1.Commit()
theSession.DeleteUndoMark(markId5, Nothing)
theSession.SetUndoMarkName(markId1, "Text")
Dim expression3 As NXOpen.Expression = textBuilder1.FrameOnPath.Offset
Dim expression4 As NXOpen.Expression = textBuilder1.FrameOnPath.Length
Dim expression5 As NXOpen.Expression = textBuilder1.FrameOnPath.Height
Dim expression6 As NXOpen.Expression = textBuilder1.FrameOnPath.AnchorPosition.Expression
textBuilder1.Destroy()
Try
' Expression is still in use.
workPart.Expressions.Delete(expression2)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try
Try
' Expression is still in use.
workPart.Expressions.Delete(expression1)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try
plane1.DestroyPlane()
' ----------------------------------------------
' Menu: Insert->Curve->Text...
' ----------------------------------------------
Dim markId6 As NXOpen.Session.UndoMarkId = Nothing
markId6 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")
Dim textBuilder2 As NXOpen.Features.TextBuilder = Nothing
textBuilder2 = workPart.Features.CreateTextBuilder(nullNXOpen_Features_Text)
Dim origin2 As NXOpen.Point3d = New NXOpen.Point3d(0.0, 0.0, 0.0)
Dim normal2 As NXOpen.Vector3d = New NXOpen.Vector3d(0.0, 0.0, 1.0)
Dim plane2 As NXOpen.Plane = Nothing
plane2 = workPart.Planes.CreatePlane(origin2, normal2, NXOpen.SmartObject.UpdateOption.WithinModeling)
textBuilder2.SectionPlane = plane2
Dim expression7 As NXOpen.Expression = Nothing
expression7 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)
Dim expression8 As NXOpen.Expression = Nothing
expression8 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)
Dim coordinates2 As NXOpen.Point3d = New NXOpen.Point3d(0.0, 0.0, 0.0)
Dim point2 As NXOpen.Point = Nothing
point2 = workPart.Points.CreatePoint(coordinates2)
textBuilder2.FrameOnPath.AnchorPosition.Expression.RightHandSide = "50"
textBuilder2.Type = NXOpen.Features.TextBuilder.Types.OnFace
textBuilder2.Script = NXOpen.Features.TextBuilder.ScriptOptions.Oem
textBuilder2.PlanarFrame.AnchorLocation = NXOpen.GeometricUtilities.RectangularFrameBuilder.AnchorLocationType.BottomCenter
textBuilder2.PlanarFrame.Length.RightHandSide = "6.57162346521146"
textBuilder2.PlanarFrame.Height.RightHandSide = "1"
textBuilder2.PlanarFrame.Shear.RightHandSide = "0"
textBuilder2.FrameOnPath.AnchorPosition.Expression.RightHandSide = "50"
textBuilder2.FrameOnPath.Offset.RightHandSide = "1.5"
textBuilder2.FrameOnPath.Length.RightHandSide = "2"
textBuilder2.FrameOnPath.Height.RightHandSide = "0.25"
textBuilder2.FrameOnPath.WScale = 273.90359431596545
textBuilder2.SelectFont("Modern", NXOpen.Features.TextBuilder.ScriptOptions.Oem)
textBuilder2.TextString = "J1234 BODY 1"
theSession.SetUndoMarkName(markId6, "Text Dialog")
Dim boundaryFaces2(-1) As NXOpen.Face
Dim faceTangentRule2 As NXOpen.FaceTangentRule = Nothing
faceTangentRule2 = workPart.ScRuleFactory.CreateRuleFaceTangent(face1, boundaryFaces2, 0.5)
Dim rules3(0) As NXOpen.SelectionIntentRule
rules3(0) = faceTangentRule2
textBuilder2.PlacementFaces.ReplaceRules(rules3, False)
textBuilder2.OnFacePlacementProfile.SetAllowedEntityTypes(NXOpen.Section.AllowTypes.OnlyCurves)
Dim markId7 As NXOpen.Session.UndoMarkId = Nothing
markId7 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "section mark")
Dim markId8 As NXOpen.Session.UndoMarkId = Nothing
markId8 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, Nothing)
Dim edgeTangentRule2 As NXOpen.EdgeTangentRule = Nothing
edgeTangentRule2 = workPart.ScRuleFactory.CreateRuleEdgeTangent(edge1, nullNXOpen_Edge, True, 0.5, False, False)
textBuilder2.OnFacePlacementProfile.AllowSelfIntersection(True)
Dim rules4(0) As NXOpen.SelectionIntentRule
rules4(0) = edgeTangentRule2
Dim helpPoint2 As NXOpen.Point3d = New NXOpen.Point3d(0.26931255602824633, -3.9337316854983571, 3.0782566011932024)
textBuilder2.OnFacePlacementProfile.AddToSection(rules4, edge1, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint2, NXOpen.Section.Mode.Create, False)
theSession.DeleteUndoMark(markId8, Nothing)
theSession.DeleteUndoMark(markId7, Nothing)
textBuilder2.OnFacePlacementProfile.ReverseDirection()
textBuilder2.TextString = "H"
textBuilder2.TextString = "HH"
textBuilder2.TextString = "HH "
textBuilder2.TextString = "HH P"
textBuilder2.TextString = "HH P2"
textBuilder2.TextString = "HH P20"
textBuilder2.TextString = "HH P20"
textBuilder2.FrameOnPath.Offset.RightHandSide = "0.7"
textBuilder2.FrameOnPath.Offset.RightHandSide = "0.8"
textBuilder2.FrameOnPath.Offset.RightHandSide = "0.9"
textBuilder2.FrameOnPath.Length.RightHandSide = "2.47823906380607"
Dim markId9 As NXOpen.Session.UndoMarkId = Nothing
markId9 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Text")
theSession.DeleteUndoMark(markId9, Nothing)
Dim markId10 As NXOpen.Session.UndoMarkId = Nothing
markId10 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Text")
Dim nXObject2 As NXOpen.NXObject = Nothing
nXObject2 = textBuilder2.Commit()
theSession.DeleteUndoMark(markId10, Nothing)
theSession.SetUndoMarkName(markId6, "Text")
Dim expression9 As NXOpen.Expression = textBuilder2.FrameOnPath.Offset
Dim expression10 As NXOpen.Expression = textBuilder2.FrameOnPath.Length
Dim expression11 As NXOpen.Expression = textBuilder2.FrameOnPath.Height
Dim expression12 As NXOpen.Expression = textBuilder2.FrameOnPath.AnchorPosition.Expression
textBuilder2.Destroy()
Try
' Expression is still in use.
workPart.Expressions.Delete(expression8)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try
Try
' Expression is still in use.
workPart.Expressions.Delete(expression7)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try
plane2.DestroyPlane()
' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------
End Sub
Please help me
Thank you
View Dependent Edit
Hi NX Journaling,
I'm trying to make a journal for doing View Dependent Edit in the drawing. I recorded a journal and modified the code so that the code would run the View Dependent Edit for any number of points in a particular sheet. However i'm unable to replace the point and the body name in the code. Could you please help with the modification of the code. Below is the code.
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI
Module VDE
Sub Main (ByVal args() As String)
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim startSheet As Drawings.DrawingSheet = theSession.Parts.Work.DrawingSheets.CurrentDrawingSheet
Dim viewsToSelect() As Drawings.DraftingView = startSheet.GetDraftingViews
For Each tempView as Drawings.DraftingView in viewsToSelect
Dim markId1 As Session.UndoMarkId = Nothing
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "VDE erase objects")
Dim objects1(0) As NXOpen.DisplayableObject
Dim draftingBody1 As NXOpen.Drawings.DraftingBody = CType(tempview.DraftingBodies.FindObject("COMPONENT ModelZ 1 0"), NXOpen.Drawings.DraftingBody)
Dim draftingPoint1 As NXOpen.Drawings.DraftingPoint = CType(draftingBody1.DraftingPoints.FindObject("(Extracted Point) HANDLE R-2770"), NXOpen.Drawings.DraftingPoint)
objects1(0) = draftingPoint1
tempView.DependentDisplay.Erase(objects1)
tempView.Commit()
next
End Sub
End Module
Finding a part in a session, make current and save
Is it possible to find
1. if a part is already opened in a session or not
2. and if already opened in a session then make current and
3. save it?
I have a code that force the part drawing to reopen if it is already opened. But if the part drawing is not saved by the user, all the changes the user made will be lost because of the reopening.
Have someone done anything similar?
Open parts from assembly
Hi,
In the last few years working with NX whenever I want to open a complete assembly I have to do select assembly and open it several times until the assembly is completely open.
What you needed to know was whether there is a journal to open the assembly completely with one click?
Thank you
Automatically close popups
Hi
How do you automatically handle popups like this? I'd like to press ok with visual basic whenever this update event list pops up.
Set Feature name to the selected object
Hi NX Journaling,
I want to assign the feature name to the object. I understand that to access the feature of the object, i need to do type casting or get the name of the feature by checking the associated / referenced feature of the object.
I tried doing type casting, but i get an error, "Object reference not set to an instance of an Object"
while using Ctype i get other error, "Unable to cast object of type NXOpen.Point to NXopen.Features.PointFeature"
Could you please help and modify the below code so that,
1.) i can pick the object from 3D space and get the feature name associated with the object to rename the selected object
2.) also as a next step i want to make this journal for multiple selections
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Module RenameObj
Sub Main()
Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim workPart As NXOpen.Part = theSession.Parts.Work
Dim displayPart As NXOpen.Part = theSession.Parts.Display
'Dim ufs As UFSession = Nothing
Dim lw As ListingWindow = theSession.ListingWindow
Dim objPoint As NXObject = SelectPoint("Report Object ID")
Do While objPoint IsNot Nothing
lw.Open()
Dim objName As String = Nothing
Dim fName As String = Nothing
'lw.WriteLine(".Name: "& fPoint.Name)
'Dim objPoint As NXOpen.TaggedObject = SelectPoint("Report Object ID")
Dim fPoint As NXOpen.Features.PointFeature = TryCast(objPoint, NXOpen.Features.PointFeature)
'Dim fPoint As NXOpen.Features.PointFeature = CType(objPoint, NXOpen.Features.PointFeature)
lw.Close()
fName = fPoint.GetFeatureName ' comment this line and uncomment the next line
'fName = fPoint.Name
lw.WriteLine(".Name: "& fName)
objPoint.SetName(fName)
'objPoint.SetName(objName & 2)
objPoint = SelectPoint("Report Object ID")
Loop
End Sub
Function SelectPoint(ByVal prompt As String) As NXObject
Dim selobj As NXObject = Nothing
Dim theUI As UI = UI.GetUI
Dim cursor As Point3d
Dim typeArray() As Selection.SelectionType =
{Selection.SelectionType.All,
Selection.SelectionType.Faces,
Selection.SelectionType.Edges}
Dim resp As Selection.Response = theUI.SelectionManager.SelectObject(
prompt, "Select an object",
Selection.SelectionScope.AnyInAssembly,
False, typeArray, selobj, cursor)
Return selobj
End Function
End Module
Journal for assigning material
Below is the journal for assigning material to the part:
Upon running material to be assigned is keyed in through windows form.
Also this journal created measure body expression and i have tried to capture the expression with unit as 'kg' and rename the expression as 'Mass' and Mass attribute is added to the attribute properties.
This macro is running fine. But i want to improvise few things.
1.) i want to check if any material is assigned previously and delete if any material is added.
2.) also the macro is failing sometimes if there are so many expressions in the part already. While running the search querf for expression with units 'kg' the macro is failing.
Could you please help in updating the journal.
' NX 12.0.1.7' Journal created by Balaji_Sampath03 on Fri Mar 13 16:11:05 2019 India Standard Time'Imports System Imports NXOpen Imports System.Collections.GenericImports NXOpen.UFImports NXOpenUI Module NXJournal Sub Main (ByVal args()AsString) Dim theSession As NXOpen.Session= NXOpen.Session.GetSession()Dim workPart As NXOpen.Part= theSession.Parts.WorkDim displayPart As NXOpen.Part= theSession.Parts.Display ' ----------------------------------------------' Menu: Tools->Materials->Assign Materials...' ---------------------------------------------- Dim MaterialListBuilder1 As NXOpen.PhysMat.PhysicalMaterialListBuilder=Nothing MaterialListBuilder1 = workPart.MaterialManager.PhysicalMaterials.CreateListBlockBuilder() Dim MaterialAssignBuilder1 As NXOpen.PhysMat.PhysicalMaterialAssignBuilder=Nothing MaterialAssignBuilder1 = workPart.MaterialManager.PhysicalMaterials.CreateMaterialAssignBuilder() Dim physicalMaterialListBuilder3 As NXOpen.PhysMat.PhysicalMaterialListBuilder=Nothing physicalMaterialListBuilder3 = workPart.MaterialManager.PhysicalMaterials.CreateListBlockBuilder() Dim nXObject1 As NXOpen.NXObject=NothingDim physicalMaterial1 As NXOpen.PhysicalMaterial=CType(nXObject1, NXOpen.PhysicalMaterial) Dim MaterialToAssign As NXOpen.PhysicalMaterial=NothingDim MaterialToAdd AsString=Nothing 'create new form objectDim myForm AsNew AddMaterial 'set form object properties (current part attribute title and value) myForm.MaterialToAdd= MaterialToAdd 'display our form myForm.ShowDialog() If myForm.CanceledThen'user pressed cancel, exit journalReturnElse'user pressed OK, assign value from form to part attribute MaterialToAdd = myForm.MaterialToAdd EndIf MaterialToAssign = workPart.MaterialManager.PhysicalMaterials.LoadFromMatmlLibrary("Z:\Knowldege Management\BOK\References\RTCOE_MatLibrary\physicalmateriallibrary.xml", MaterialToAdd) Dim physicalMaterialBuilder1 As NXOpen.PhysicalMaterialBuilder=Nothing physicalMaterialBuilder1 = workPart.MaterialManager.PhysicalMaterials.CreatePhysicalMaterialInspectBuilder(MaterialToAssign) physicalMaterialBuilder1.Destroy() Dim theBody As Body If SelectSolidToAssignMaterial("select a body", theBody)= Selection.Response.CancelThenReturnEndIf Dim theBodies(0)As Body theBodies(0)= theBody MaterialToAssign.AssignObjects(theBodies) MaterialListBuilder1.Destroy() MaterialAssignBuilder1.Destroy() ' ----------------------------------------------' Menu: Analysis->Measure Body...' ---------------------------------------------- 'Dim MeasureToDelete As NXOpen.Measure = DeleteMeasure() Dim nullNXOpen_NXObject As NXOpen.NXObject=NothingDim measureBodyBuilder1 As NXOpen.MeasureBodyBuilder=Nothing measureBodyBuilder1 = workPart.MeasureManager.CreateMeasureBodyBuilder(nullNXOpen_NXObject) Dim BodyToMeasure(0)As NXOpen.Body BodyToMeasure(0)= theBody Dim bodyDumbRule1 As NXOpen.BodyDumbRule=Nothing bodyDumbRule1 = workPart.ScRuleFactory.CreateRuleBodyDumb(BodyToMeasure, True) Dim rules1(0)As NXOpen.SelectionIntentRule rules1(0)= bodyDumbRule1 measureBodyBuilder1.BodyCollector.ReplaceRules(rules1, False) Dim massUnits1(4)As NXOpen.UnitDim SurfaceArea As NXOpen.Unit=CType(workPart.UnitCollection.FindObject("SquareMilliMeter"), NXOpen.Unit)Dim Volume As NXOpen.Unit=CType(workPart.UnitCollection.FindObject("CubicMilliMeter"), NXOpen.Unit)Dim Mass As NXOpen.Unit=CType(workPart.UnitCollection.FindObject("Kilogram"), NXOpen.Unit)Dim Length As NXOpen.Unit=CType(workPart.UnitCollection.FindObject("MilliMeter"), NXOpen.Unit)Dim Weight As NXOpen.Unit=CType(workPart.UnitCollection.FindObject("Newton"), NXOpen.Unit) Dim measureBodies1 As NXOpen.MeasureBodies=Nothing measureBodies1 = workPart.MeasureManager.NewMassProperties(massUnits1, 0.98999999999999999, False, measureBodyBuilder1.BodyCollector)Dim measure1 As NXOpen.Measure=Nothing measure1 = measureBodies1.CreateFeature() measureBodies1.Dispose() measureBodyBuilder1.Destroy() ' ----------------------------------------------' Menu: Tools-> Expression-> Rename Measured Body Expressions' ---------------------------------------------- ForEach temp As Expression In workPart.Expressions If temp.Units.Symbol="kg"Then workPart.Expressions.Rename(temp, "Mass")EndIf ' If temp.Units.Symbol = "mm²" Then' workPart.Expressions.Rename(temp, "SurfaceArea")' End If ' If temp.Units.Symbol = "mm³" Then' workPart.Expressions.Rename(temp, "Volume")' End If ' If temp.Units.Symbol = "N" Then' workPart.Expressions.Rename(temp, "Weight")' End If Next ' ----------------------------------------------' Dialog Begin Expressions Properties Builder' ---------------------------------------------- Dim objectsAttribute(0)As NXOpen.NXObject objectsAttribute(0)= workPart Dim attributePropertiesBuilder1 As NXOpen.AttributePropertiesBuilder=Nothing attributePropertiesBuilder1 = theSession.AttributeManager.CreateAttributePropertiesBuilder(workPart, objectsAttribute, NXOpen.AttributePropertiesBuilder.OperationType.None) attributePropertiesBuilder1.Category="Materials" attributePropertiesBuilder1.Title="Weight" attributePropertiesBuilder1.DataType= NXOpen.AttributePropertiesBaseBuilder.DataTypeOptions.Number'attributePropertiesBuilder1.Units = "Tesla" attributePropertiesBuilder1.Units="Kilogram" Dim MassProperties As NXOpen.Expression=Nothing MassProperties = workPart.Expressions.CreateSystemExpressionWithUnits("0.0", Mass) MassProperties.RightHandSide="Mass" attributePropertiesBuilder1.IsReferenceType=False attributePropertiesBuilder1.Expression= MassProperties Dim nXObject2 As NXOpen.NXObject=Nothing nXObject2 = attributePropertiesBuilder1.Commit() attributePropertiesBuilder1.Destroy() EndSub Function SelectSolidToAssignMaterial(ByVal prompt AsString, ByRef selObj As TaggedObject)As Selection.Response Dim theUI As UI = UI.GetUIDim title AsString="Select Solid To Assign Material"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.MaskTriple With selectionMask_array(0).Type= UFConstants.UF_solid_type.SolidBodySubtype= UFConstants.UF_UI_SEL_FEATURE_SOLID_BODYEndWith 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.ObjectSelectedByNameThenReturn Selection.Response.OkElseReturn Selection.Response.CancelEndIf EndFunction PublicFunction GetUnloadOption(ByVal dummy AsString)AsInteger 'Unloads the image immediately after execution within NX GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately EndFunction 'Function DeleteMeasure() As NXOpen.Measure' Dim objects1(0) As NXOpen.TaggedObject' Dim MeasureToDelete As NXOpen.Measure = CType(workPart.Features.FindObject("BODY_MEASUREMENT(4)"), NXOpen.Measure)' objects1(0) = MeasureToDelete'End Function EndModule PublicClass AddMaterial Private _frmAttributeValue AsStringPublicProperty MaterialToAdd()AsStringGetReturn _frmAttributeValue EndGetSet(ByVal value AsString) _frmAttributeValue = value EndSetEndProperty Private _canceled AsBoolean=FalsePublicReadOnlyProperty Canceled()AsBooleanGetReturn _canceled EndGetEndProperty PrivateSub Form1_Load(sender As System.Object, e As System.EventArgs)HandlesMyBase.Load Label1.Text="Material" TextBox1.Text= _frmAttributeValue EndSub PrivateSub btnCancel_Click(sender As System.Object, e As System.EventArgs)Handles btnCancel.Click _canceled =TrueMe.Close()EndSub PrivateSub btnOK_Click(sender As System.Object, e As System.EventArgs)Handles btnOK.Click _frmAttributeValue = TextBox1.Text.ToUpperMe.Close()EndSub EndClass <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _ PartialClass AddMaterial Inherits System.Windows.Forms.Form 'Form overrides dispose to clean up the component list.<System.Diagnostics.DebuggerNonUserCode()> _ ProtectedOverridesSub Dispose(ByVal disposing AsBoolean)TryIf disposing AndAlso components IsNotNothingThen components.Dispose()EndIfFinallyMyBase.Dispose(disposing)EndTryEndSub 'Required by the Windows Form DesignerPrivate components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor.<System.Diagnostics.DebuggerStepThrough()> _ PrivateSub InitializeComponent()Me.btnCancel=New System.Windows.Forms.Button()Me.btnOK=New System.Windows.Forms.Button()Me.Label1=New System.Windows.Forms.Label()Me.TextBox1=New System.Windows.Forms.TextBox()Me.SuspendLayout()''btnCancel'Me.btnCancel.DialogResult= System.Windows.Forms.DialogResult.CancelMe.btnCancel.Location=New System.Drawing.Point(178, 107)Me.btnCancel.Name="btnCancel"Me.btnCancel.Size=New System.Drawing.Size(85, 50)Me.btnCancel.TabIndex=0Me.btnCancel.Text="Cancel"Me.btnCancel.UseVisualStyleBackColor=True''btnOK'Me.btnOK.Location=New System.Drawing.Point(66, 107)Me.btnOK.Name="btnOK"Me.btnOK.Size=New System.Drawing.Size(85, 50)Me.btnOK.TabIndex=1Me.btnOK.Text="Ok"Me.btnOK.UseVisualStyleBackColor=True''Label1'Me.Label1.Location=New System.Drawing.Point(12, 54)Me.Label1.Name="Label1"Me.Label1.Size=New System.Drawing.Size(79, 13)Me.Label1.TabIndex=2Me.Label1.Text="Label1"Me.Label1.TextAlign= System.Drawing.ContentAlignment.MiddleRight''TextBox1'Me.TextBox1.Location=New System.Drawing.Point(97, 51)Me.TextBox1.Name="TextBox1"Me.TextBox1.Size=New System.Drawing.Size(166, 20)Me.TextBox1.TabIndex=3''MaterialCreation'Me.AcceptButton=Me.btnOKMe.AutoScaleDimensions=New System.Drawing.SizeF(6.0!, 13.0!)Me.AutoScaleMode= System.Windows.Forms.AutoScaleMode.FontMe.CancelButton=Me.btnCancelMe.ClientSize=New System.Drawing.Size(284, 176)Me.Controls.Add(Me.TextBox1)Me.Controls.Add(Me.Label1)Me.Controls.Add(Me.btnOK)Me.Controls.Add(Me.btnCancel)Me.FormBorderStyle= System.Windows.Forms.FormBorderStyle.FixedDialogMe.MaximizeBox=FalseMe.MinimizeBox=FalseMe.Name="AddMaterial"Me.Text="AddMaterial"Me.ResumeLayout(False)Me.PerformLayout() EndSubFriendWithEvents btnCancel As System.Windows.Forms.ButtonFriendWithEvents btnOK As System.Windows.Forms.ButtonFriendWithEvents Label1 As System.Windows.Forms.LabelFriendWithEvents TextBox1 As System.Windows.Forms.TextBoxEndClass <vbnet> Thanks
create Library Material
Hello Everyone,
Below is the journal for adding new material to the NX library material.
This journal creates new material by receiving user inputs for,
1). Material Name, 2). Material type and 3). Density
New material will be created as local material and then exported to the Material library automatically by the Macro and the local material will be deleted.
This macro is created only to add density as our requirements are only to find the weight and update in the parts list.
' NX 12.0.1.7' Journal created by Balaji_Sampath03 on Fri Apr 17 11:07:51 2020 India Standard Time' Imports System Imports NXOpen Imports System.Collections.GenericImports NXOpen.UFImports NXOpenUI Module NXJournal Sub Main (ByVal args()AsString)Dim theSession As NXOpen.Session= NXOpen.Session.GetSession()Dim workPart As NXOpen.Part= theSession.Parts.WorkDim displayPart As NXOpen.Part= theSession.Parts.Display ' ----------------------------------------------' Menu: Tools->Materials->Manage Materials ...' ---------------------------------------------- Dim physicalMaterialListBuilder1 As NXOpen.PhysMat.PhysicalMaterialListBuilder=Nothing physicalMaterialListBuilder1 = workPart.MaterialManager.PhysicalMaterials.CreateListBlockBuilder() Dim physicalMaterialBuilder1 As NXOpen.PhysicalMaterialBuilder=Nothing physicalMaterialBuilder1 = workPart.MaterialManager.PhysicalMaterials.CreatePhysicalMaterialBuilder(NXOpen.PhysicalMaterial.Type.Isotropic) Dim propertyTable1 As NXOpen.CAE.PropertyTable=Nothing propertyTable1 = physicalMaterialBuilder1.ItemPropertyTable ' ----------------------------------------------' Dialog Begin Isotropic Material' ---------------------------------------------- Dim MaterialToCreate AsString=NothingDim MaterialType AsString=NothingDim DensityToAdd AsInteger=Nothing 'create new form objectDim myForm AsNew AddLibMatl 'set form object properties (current part attribute title and value) myForm.MaterialToCreate= MaterialToCreate myForm.MaterialType= MaterialType myForm.DensityToAdd= DensityToAdd 'display our form myForm.ShowDialog() If myForm.CanceledThen'user pressed cancel, exit journalReturnElse'user pressed OK, assign value from form to part attribute MaterialToCreate = myForm.MaterialToCreate MaterialType = myForm.MaterialType DensityToAdd = myForm.DensityToAddEndIf 'Create Material from Form Input physicalMaterialBuilder1.ItemName= MaterialToCreate Dim propertyTable2 As NXOpen.CAE.PropertyTable=Nothing propertyTable2 = physicalMaterialBuilder1.ItemPropertyTable 'Select MaterialType from Form Input propertyTable2.SetStringPropertyValue("Category", MaterialType) Dim scalarFieldWrapper1 As NXOpen.Fields.ScalarFieldWrapper=Nothing scalarFieldWrapper1 = propertyTable2.GetScalarFieldWrapperPropertyValue("MassDensity") Dim expression1 As NXOpen.Expression=Nothing expression1 = scalarFieldWrapper1.GetExpression() Dim unit1 As NXOpen.Unit=CType(workPart.UnitCollection.FindObject("KilogramPerCubicMeter"), NXOpen.Unit) 'Assign Density from FORM Input workPart.Expressions.EditWithUnits(expression1, unit1, DensityToAdd) Dim nXObject1 As NXOpen.NXObject=Nothing nXObject1 = physicalMaterialBuilder1.Commit() physicalMaterialBuilder1.Destroy() physicalMaterialListBuilder1.Destroy() ' ----------------------------------------------' Menu: Tools->Materials->Manage Library Materials...' ---------------------------------------------- Dim physicalMaterialListBuilder2 As NXOpen.PhysMat.PhysicalMaterialListBuilder=Nothing physicalMaterialListBuilder2 = workPart.MaterialManager.PhysicalMaterials.CreateListBlockBuilder() Dim physicalMaterialLibMgrBuilder1 As NXOpen.PhysMat.PhysicalMaterialLibMgrBuilder=Nothing physicalMaterialLibMgrBuilder1 = workPart.MaterialManager.PhysicalMaterials.CreateMaterialLibmgrBuilder() ' ----------------------------------------------' Dialog Begin Export Material(s) To Library' ---------------------------------------------- Dim pcmatlnames1(0)AsString pcmatlnames1(0)= MaterialToCreate Dim pclibnames1(0)AsString pclibnames1(0)=""Dim bupdatelibraryreference1(0)AsBoolean bupdatelibraryreference1(0)=True workPart.MaterialManager.PhysicalMaterials.ExportMaterialsToLibrary(pcmatlnames1, pclibnames1, "D:\Macro\FINAL\physicalmateriallibrary.xml", bupdatelibraryreference1) physicalMaterialLibMgrBuilder1.Destroy() physicalMaterialListBuilder2.Destroy() ' ----------------------------------------------' Menu: Tools->Materials->Manage Materials ...' ---------------------------------------------- Dim physicalMaterialListBuilder3 As NXOpen.PhysMat.PhysicalMaterialListBuilder=Nothing physicalMaterialListBuilder3 = workPart.MaterialManager.PhysicalMaterials.CreateListBlockBuilder() Dim physicalMaterial1 As NXOpen.PhysicalMaterial=CType(nXObject1, NXOpen.PhysicalMaterial) physicalMaterial1.Delete() physicalMaterialListBuilder3.Destroy() EndSub PublicFunction GetUnloadOption(ByVal dummy AsString)AsInteger 'Unloads the image immediately after execution within NX GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately EndFunctionEndModule PublicClass AddLibMatl Private _Material AsStringPrivate _MaterialType AsStringPrivate _Density AsInteger PublicProperty MaterialToCreate()AsStringGetReturn _Material EndGetSet(ByVal value AsString) _Material= value EndSetEndProperty PublicProperty MaterialType()AsStringGetReturn _MaterialType EndGetSet(ByVal value AsString) _MaterialType = value EndSetEndProperty PublicProperty DensityToAdd()AsIntegerGetReturn _Density EndGetSet(ByVal value AsInteger) _Density = value EndSetEndProperty Private _canceled AsBoolean=FalsePublicReadOnlyProperty Canceled()AsBooleanGetReturn _canceled EndGetEndProperty PrivateSub Form1_Load(sender AsObject, e As EventArgs)HandlesMyBase.Load TextBox1.Text= _Material ComboBox1.Text= _MaterialType TextBox2.Text= _Density EndSub PrivateSub Button1_Click(sender AsObject, e As EventArgs)Handles ButtonOK.Click _Material = TextBox1.Text.ToUpper _MaterialType = ComboBox1.Text.ToUpper _Density = TextBox2.Text.ToUpperMe.Close()EndSub PrivateSub Button2_Click(sender AsObject, e As EventArgs)Handles ButtonCancel.Click _canceled =TrueMe.Close()EndSub EndClass <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _ PartialClass AddLibMatl Inherits System.Windows.Forms.Form 'Form overrides dispose to clean up the component list.<System.Diagnostics.DebuggerNonUserCode()> _ ProtectedOverridesSub Dispose(ByVal disposing AsBoolean)TryIf disposing AndAlso components IsNotNothingThen components.Dispose()EndIfFinallyMyBase.Dispose(disposing)EndTryEndSub 'Required by the Windows Form DesignerPrivate components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor.<System.Diagnostics.DebuggerStepThrough()> _ PrivateSub InitializeComponent()Me.Label1=New System.Windows.Forms.Label()Me.Label2=New System.Windows.Forms.Label()Me.Label3=New System.Windows.Forms.Label()Me.TextBox1=New System.Windows.Forms.TextBox()Me.ComboBox1=New System.Windows.Forms.ComboBox()Me.TextBox2=New System.Windows.Forms.TextBox()Me.ButtonOK=New System.Windows.Forms.Button()Me.ButtonCancel=New System.Windows.Forms.Button()Me.SuspendLayout()''Label1'Me.Label1.AutoSize=TrueMe.Label1.Font=New System.Drawing.Font("Microsoft Sans Serif", 10.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))Me.Label1.Location=New System.Drawing.Point(12, 20)Me.Label1.Name="Label1"Me.Label1.Size=New System.Drawing.Size(58, 17)Me.Label1.TabIndex=0Me.Label1.Text="Material"''Label2'Me.Label2.AutoSize=TrueMe.Label2.Font=New System.Drawing.Font("Microsoft Sans Serif", 10.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))Me.Label2.Location=New System.Drawing.Point(12, 50)Me.Label2.Name="Label2"Me.Label2.Size=New System.Drawing.Size(94, 17)Me.Label2.TabIndex=1Me.Label2.Text="Material Type"''Label3'Me.Label3.AutoSize=TrueMe.Label3.Font=New System.Drawing.Font("Microsoft Sans Serif", 10.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))Me.Label3.Location=New System.Drawing.Point(12, 81)Me.Label3.Name="Label3"Me.Label3.Size=New System.Drawing.Size(55, 17)Me.Label3.TabIndex=2Me.Label3.Text="Density"''TextBox1'Me.TextBox1.Font=New System.Drawing.Font("Microsoft Sans Serif", 10.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))Me.TextBox1.Location=New System.Drawing.Point(136, 16)Me.TextBox1.Name="TextBox1"Me.TextBox1.Size=New System.Drawing.Size(100, 23)Me.TextBox1.TabIndex=3''ComboBox1'Me.ComboBox1.AllowDrop=TrueMe.ComboBox1.DropDownStyle= System.Windows.Forms.ComboBoxStyle.DropDownListMe.ComboBox1.Font=New System.Drawing.Font("Microsoft Sans Serif", 10.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))Me.ComboBox1.FormattingEnabled=TrueMe.ComboBox1.Items.AddRange(NewObject(){"Select Material Type:", "Metal", "Plastic", "Others"})Me.ComboBox1.Location=New System.Drawing.Point(136, 45)Me.ComboBox1.Name="ComboBox1"Me.ComboBox1.Size=New System.Drawing.Size(121, 24)Me.ComboBox1.TabIndex=4''TextBox2'Me.TextBox2.Font=New System.Drawing.Font("Microsoft Sans Serif", 10.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))Me.TextBox2.Location=New System.Drawing.Point(136, 81)Me.TextBox2.Name="TextBox2"Me.TextBox2.Size=New System.Drawing.Size(100, 23)Me.TextBox2.TabIndex=5''ButtonOK'Me.ButtonOK.Font=New System.Drawing.Font("Microsoft Sans Serif", 10.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))Me.ButtonOK.Location=New System.Drawing.Point(51, 111)Me.ButtonOK.Name="ButtonOK"Me.ButtonOK.Size=New System.Drawing.Size(42, 23)Me.ButtonOK.TabIndex=6Me.ButtonOK.Text="OK"Me.ButtonOK.UseVisualStyleBackColor=True''ButtonCancel'Me.ButtonCancel.Font=New System.Drawing.Font("Microsoft Sans Serif", 10.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))Me.ButtonCancel.Location=New System.Drawing.Point(136, 111)Me.ButtonCancel.Name="ButtonCancel"Me.ButtonCancel.Size=New System.Drawing.Size(75, 23)Me.ButtonCancel.TabIndex=7Me.ButtonCancel.Text="CANCEL"Me.ButtonCancel.UseVisualStyleBackColor=True''Form1'Me.AutoScaleDimensions=New System.Drawing.SizeF(6.0!, 13.0!)Me.AutoScaleMode= System.Windows.Forms.AutoScaleMode.FontMe.ClientSize=New System.Drawing.Size(275, 147)Me.Controls.Add(Me.ButtonCancel)Me.Controls.Add(Me.ButtonOK)Me.Controls.Add(Me.TextBox2)Me.Controls.Add(Me.ComboBox1)Me.Controls.Add(Me.TextBox1)Me.Controls.Add(Me.Label3)Me.Controls.Add(Me.Label2)Me.Controls.Add(Me.Label1)Me.Font=New System.Drawing.Font("Microsoft Sans Serif", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))Me.Name="Form1"Me.Text="Create Material"Me.TransparencyKey= System.Drawing.Color.FromArgb(CType(CType(128, Byte), Integer), CType(CType(255, Byte), Integer), CType(CType(255, Byte), Integer))Me.ResumeLayout(False)Me.PerformLayout() EndSub FriendWithEvents Label1 As System.Windows.Forms.LabelFriendWithEvents Label2 As System.Windows.Forms.LabelFriendWithEvents Label3 As System.Windows.Forms.LabelFriendWithEvents TextBox1 As System.Windows.Forms.TextBoxFriendWithEvents ComboBox1 As System.Windows.Forms.ComboBoxFriendWithEvents TextBox2 As System.Windows.Forms.TextBoxFriendWithEvents ButtonOK As System.Windows.Forms.ButtonFriendWithEvents ButtonCancel As System.Windows.Forms.ButtonEndClass <vbnet> Thanks, B
Set Drafting Preferences
Hello NX Journaling,
Below is a small journal i recorded while setting the drafting preferences.
This may not be pure journal in it's form but just a method of resetting the drafting preferences before starting to work on a drafting. Many a times drawing downloaded from the client server which were previously worked upon a local NX had got the default preferences as per the client server NX. To overcome this, before continuing to work on this downloaded drawing, i would run this journal to set the drafting preferences as per our requirement. Journal can be updated to include more settings.
' NX 12.0.1.7' Journal created by Balaji_Sampath03 on Thu Aug 22 20:32:14 2019 India Standard Time'*******************************************************************************'This Macro would set the drafting preferences as per the company standard requirements. '*******************************************************************************Imports System Imports NXOpen Module SetDraftingPref Sub Main (ByVal args()AsString) Dim theSession As NXOpen.Session= NXOpen.Session.GetSession()Dim workPart As NXOpen.Part= theSession.Parts.WorkDim displayPart As NXOpen.Part= theSession.Parts.Display Dim nXObject1 As NXOpen.NXObject=NothingDim nXObject2 As NXOpen.NXObject=Nothing'Dim nXObject3 As NXOpen.NXObject = Nothing Dim preferencesBuilder1 As NXOpen.Drafting.PreferencesBuilder=Nothing preferencesBuilder1 = workPart.SettingsManager.CreatePreferencesBuilder() Dim nullNXOpen_Annotations_SimpleDraftingAid As NXOpen.Annotations.SimpleDraftingAid=NothingDim draftingNoteBuilder1 As NXOpen.Annotations.DraftingNoteBuilder=Nothing draftingNoteBuilder1 = workPart.Annotations.CreateDraftingNoteBuilder(nullNXOpen_Annotations_SimpleDraftingAid) Dim leaderData1 As NXOpen.Annotations.LeaderData=Nothing leaderData1 = workPart.Annotations.CreateLeaderData() '---------------------------'Common - Lettering Settings'--------------------------- preferencesBuilder1.AnnotationStyle.LetteringStyle.GeneralTextColor= workPart.Colors.Find("Black") preferencesBuilder1.AnnotationStyle.LetteringStyle.GeneralTextFont=8 preferencesBuilder1.AnnotationStyle.LetteringStyle.GeneralTextLineWidth= NXOpen.Annotations.LineWidth.Thin preferencesBuilder1.AnnotationStyle.LineArrowStyle.TextOverStubFactor=0.3 preferencesBuilder1.AnnotationStyle.LineArrowStyle.DatumLengthPastArrow=2.0 '-----------------------------------------'Common - Line / Arrow Head Settings'----------------------------------------- preferencesBuilder1.AnnotationStyle.LineArrowStyle.FirstArrowheadColor= workPart.Colors.Find("Black") preferencesBuilder1.AnnotationStyle.LineArrowStyle.FirstArrowheadFont= NXOpen.DisplayableObject.ObjectFont.Solid preferencesBuilder1.AnnotationStyle.LineArrowStyle.FirstArrowheadWidth= NXOpen.Annotations.LineWidth.One preferencesBuilder1.AnnotationStyle.LineArrowStyle.SecondArrowheadColor= workPart.Colors.Find("Black") preferencesBuilder1.AnnotationStyle.LineArrowStyle.SecondArrowheadFont= NXOpen.DisplayableObject.ObjectFont.Solid preferencesBuilder1.AnnotationStyle.LineArrowStyle.SecondArrowheadWidth= NXOpen.Annotations.LineWidth.One '-----------------------------------------'Common - Line / Arrow Line Settings'----------------------------------------- preferencesBuilder1.AnnotationStyle.LineArrowStyle.FirstArrowLineColor= workPart.Colors.Find("Black") preferencesBuilder1.AnnotationStyle.LineArrowStyle.FirstArrowLineFont= NXOpen.DisplayableObject.ObjectFont.Solid preferencesBuilder1.AnnotationStyle.LineArrowStyle.FirstArrowLineWidth= NXOpen.Annotations.LineWidth.One preferencesBuilder1.AnnotationStyle.LineArrowStyle.SecondArrowLineColor= workPart.Colors.Find("Black") preferencesBuilder1.AnnotationStyle.LineArrowStyle.SecondArrowLineFont= NXOpen.DisplayableObject.ObjectFont.Solid preferencesBuilder1.AnnotationStyle.LineArrowStyle.SecondArrowLineWidth= NXOpen.Annotations.LineWidth.One '-----------------------------------------'Common - Line / Extension Line Settings'----------------------------------------- preferencesBuilder1.AnnotationStyle.LineArrowStyle.FirstExtensionLineColor= workPart.Colors.Find("Black") preferencesBuilder1.AnnotationStyle.LineArrowStyle.FirstExtensionLineFont= NXOpen.DisplayableObject.ObjectFont.Solid preferencesBuilder1.AnnotationStyle.LineArrowStyle.FirstExtensionLineWidth= NXOpen.Annotations.LineWidth.One preferencesBuilder1.AnnotationStyle.LineArrowStyle.SecondExtensionLineColor= workPart.Colors.Find("Black") preferencesBuilder1.AnnotationStyle.LineArrowStyle.SecondExtensionLineFont= NXOpen.DisplayableObject.ObjectFont.Solid preferencesBuilder1.AnnotationStyle.LineArrowStyle.SecondExtensionLineWidth= NXOpen.Annotations.LineWidth.One '--------------------------------------'Common - Dimension Break Line Settings'-------------------------------------- preferencesBuilder1.AnnotationStyle.BreakSettings.CreateBreaks=True '------------------------'Common - Symbol Settings'------------------------ preferencesBuilder1.AnnotationStyle.SymbolStyle.UserDefinedSymbolColor= workPart.Colors.Find("Black") preferencesBuilder1.AnnotationStyle.SymbolStyle.UserDefinedSymbolFont= NXOpen.DisplayableObject.ObjectFont.Solid preferencesBuilder1.AnnotationStyle.SymbolStyle.UserDefinedSymbolWidth= NXOpen.Annotations.LineWidth.One ' ----------------------------------------------' Dialog Begin Drafting Preferences' ---------------------------------------------- preferencesBuilder1.ViewStyle.ViewStyleGeneral.ExtractedEdges= NXOpen.Preferences.GeneralExtractedEdgesOption.Associative ' -----------------------------'View - Common - Angle Settings' ----------------------------- preferencesBuilder1.ViewStyle.ViewStyleGeneral.AngleSetting.AngleValue=0.0 preferencesBuilder1.ViewStyle.ViewStyleGeneral.AngleSetting.SetIsMeasure(False) preferencesBuilder1.ViewStyle.ViewStyleGeneral.AngleSetting.CreateScalarObject() preferencesBuilder1.ViewStyle.ViewStyleGeneral.AnglePrecision=2 preferencesBuilder1.ViewStyle.ViewStyleGeneral.AngleDecimalPointCharacter= NXOpen.Preferences.DecimalPointCharacter.Period preferencesBuilder1.ViewStyle.ViewStyleGeneral.AngleShowLeadingZeros=True preferencesBuilder1.ViewStyle.ViewStyleGeneral.AngleShowTrailingZeros=False ' ------------------------------------'View - Common - Visible Line Settings' ------------------------------------ preferencesBuilder1.ViewStyle.ViewStyleVisibleLines.VisibleColor= workPart.Colors.Find("Black") preferencesBuilder1.ViewStyle.ViewStyleVisibleLines.VisibleFont= NXOpen.DisplayableObject.ObjectFont.Solid preferencesBuilder1.ViewStyle.ViewStyleVisibleLines.VisibleWidth= NXOpen.Preferences.Width.Three ' -----------------------------------'View - Common - Hidden Line Settings' ----------------------------------- preferencesBuilder1.ViewStyle.ViewStyleHiddenLines.Color= workPart.Colors.Find("Black") preferencesBuilder1.ViewStyle.ViewStyleHiddenLines.Font= NXOpen.Preferences.Font.Invisible preferencesBuilder1.ViewStyle.ViewStyleHiddenLines.Width= NXOpen.Preferences.Width.Two ' ---------------------------------------------'View - Common - Virtual Intersections Settings' --------------------------------------------- preferencesBuilder1.ViewStyle.ViewStyleVirtualIntersections.Color= workPart.Colors.Find("Black") preferencesBuilder1.ViewStyle.ViewStyleVirtualIntersections.Font= NXOpen.DisplayableObject.ObjectFont.Solid preferencesBuilder1.ViewStyle.ViewStyleVirtualIntersections.Width= NXOpen.Preferences.Width.Two ' ------------------------------'View - Common - Thread Settings' ------------------------------ preferencesBuilder1.ViewStyle.ViewStyleThreads.StandardData=4 ' ------------------------------------'View - Common - Smooth Edges Settings' ------------------------------------ preferencesBuilder1.ViewStyle.ViewStyleSmoothEdges.Color= workPart.Colors.Find("Black") preferencesBuilder1.ViewStyle.ViewStyleSmoothEdges.Font= NXOpen.DisplayableObject.ObjectFont.Solid preferencesBuilder1.ViewStyle.ViewStyleSmoothEdges.Width= NXOpen.Preferences.Width.Two ' -----------------------------------'View - Base / Drawing Label Settings' ----------------------------------- preferencesBuilder1.ViewStyle.ViewStyleBase.InheritClippingBoundary=False preferencesBuilder1.ViewLabel.LabelPosition= NXOpen.Drawings.LabelPositionTypes.Above preferencesBuilder1.ViewLabel.ShowViewLabel=True preferencesBuilder1.ViewLabel.ViewLabelOption= NXOpen.Drawings.ViewLabelTypes.Name preferencesBuilder1.ViewLabel.LetterFormat= NXOpen.Drawings.LetterFormatTypes.A preferencesBuilder1.ViewLabel.LabelPrefix="" preferencesBuilder1.ViewLabel.LabelCharacterHeightFactor=2.0 preferencesBuilder1.ViewLabel.ShowViewScale=True preferencesBuilder1.ViewLabel.ScalePosition= NXOpen.Drawings.ScalePositionTypes.After preferencesBuilder1.ViewLabel.ScalePrefix="" preferencesBuilder1.ViewLabel.PrefixCharacterHeightFactor=1.0 preferencesBuilder1.ViewLabel.ScaleCharacterHeightFactor=1.0 preferencesBuilder1.ViewLabel.IncludeParentheses=True ' -----------------------------------'View - Projected View Label Settings' ----------------------------------- preferencesBuilder1.ViewStyle.ViewProjectedArrowSettings.LineColorFontWidth.LineColor= workPart.Colors.Find("Black") preferencesBuilder1.ViewStyle.ViewProjectedViewSettings.DisplayArrowOnParentView= NXOpen.Drawings.ViewProjectedViewSettingsBuilder.DisplayArrowOnParentViewType.All preferencesBuilder1.ViewProjectedLabel.LabelPosition= NXOpen.Drawings.LabelPositionTypes.Above preferencesBuilder1.ViewProjectedLabel.ShowViewLabel=True preferencesBuilder1.ViewProjectedLabel.ViewLabelOption= NXOpen.Drawings.ViewLabelTypes.Name preferencesBuilder1.ViewProjectedLabel.LabelPrefix="" preferencesBuilder1.ViewProjectedLabel.LetterFormat= NXOpen.Drawings.LetterFormatTypes.A preferencesBuilder1.ViewProjectedLabel.IncludeRotationAngle=True preferencesBuilder1.ViewProjectedLabel.LabelCharacterHeightFactor=2.0 preferencesBuilder1.ViewProjectedLabel.ShowViewScale=True preferencesBuilder1.ViewProjectedLabel.ScalePosition= NXOpen.Drawings.ScalePositionTypes.After preferencesBuilder1.ViewProjectedLabel.ScalePrefix="" preferencesBuilder1.ViewProjectedLabel.PrefixCharacterHeightFactor=1.0 preferencesBuilder1.ViewProjectedLabel.ScaleCharacterHeightFactor=1.0 preferencesBuilder1.ViewProjectedLabel.IncludeParentheses=True ' ---------------------------------'View - Section View Label Settings' --------------------------------- preferencesBuilder1.ViewStyle.ViewStyleSection.Background=True preferencesBuilder1.ViewStyle.ViewStyleSection.SheetBodies=True preferencesBuilder1.ViewStyle.ViewStyleSection.Crosshatch=True preferencesBuilder1.ViewStyle.ViewStyleSection.AdjacencyToleranceData=1.0 preferencesBuilder1.ViewSectionLabel.LabelPosition= NXOpen.Drawings.LabelPositionTypes.Above preferencesBuilder1.ViewSectionLabel.ShowViewLabel=True preferencesBuilder1.ViewSectionLabel.ViewLabelOption= NXOpen.Drawings.ViewLabelTypes.Name preferencesBuilder1.ViewSectionLabel.LabelPrefix="" preferencesBuilder1.ViewSectionLabel.LetterFormat= NXOpen.Drawings.LetterFormatTypes.A preferencesBuilder1.ViewSectionLabel.IncludeRotationAngle=True preferencesBuilder1.ViewSectionLabel.LabelCharacterHeightFactor=2.0 preferencesBuilder1.ViewSectionLabel.ShowViewScale=True preferencesBuilder1.ViewSectionLabel.ScalePosition= NXOpen.Drawings.ScalePositionTypes.After preferencesBuilder1.ViewSectionLabel.ScalePrefix="" preferencesBuilder1.ViewSectionLabel.PrefixCharacterHeightFactor=1.0 preferencesBuilder1.ViewSectionLabel.ScaleCharacterHeightFactor=1.0 preferencesBuilder1.ViewSectionLabel.IncludeParentheses=True ' --------------------------------'View - Detail View Label Settings' -------------------------------- preferencesBuilder1.ViewStyle.ViewStyleDetail.ViewBoundaryWidth= NXOpen.Preferences.Width.Two preferencesBuilder1.ViewStyle.ViewStyleDetail.ViewBoundaryColor= workPart.Colors.Find("Black") preferencesBuilder1.ViewDetailLabel.TextPlacement= NXOpen.Drawings.ViewDetailLabelBuilder.LabelParentTextPlacement.AboveStub preferencesBuilder1.ViewDetailLabel.ShowViewLabel=True preferencesBuilder1.ViewDetailLabel.LabelPosition= NXOpen.Drawings.LabelPositionTypes.Above preferencesBuilder1.ViewDetailLabel.ViewLabelOption= NXOpen.Drawings.ViewLabelTypes.Name preferencesBuilder1.ViewDetailLabel.LabelPrefix="" preferencesBuilder1.ViewDetailLabel.LetterFormat= NXOpen.Drawings.LetterFormatTypes.A preferencesBuilder1.ViewDetailLabel.LabelCharacterHeightFactor=2.0 preferencesBuilder1.ViewDetailLabel.ShowViewScale=True preferencesBuilder1.ViewDetailLabel.LabelParentDisplay= NXOpen.Drawings.ViewDetailLabelBuilder.LabelParentDisplayTypes.Label preferencesBuilder1.ViewDetailLabel.ScalePosition= NXOpen.Drawings.ScalePositionTypes.After preferencesBuilder1.ViewDetailLabel.ScalePrefix="" preferencesBuilder1.ViewDetailLabel.PrefixCharacterHeightFactor=1.0 preferencesBuilder1.ViewDetailLabel.ScaleCharacterHeightFactor=1.0 preferencesBuilder1.ViewDetailLabel.IncludeParentheses=True ' ---------------------------'View - Section Line Settings' --------------------------- preferencesBuilder1.ViewSectionLine.LineColorFontWidth.LineColor= workPart.Colors.Find("Black") preferencesBuilder1.ViewSectionLine.LineColorFontWidth.LineWidth= NXOpen.Preferences.Width.Two preferencesBuilder1.ViewSectionLine.LineColorFontWidth.LineFont.LineFont= NXOpen.LineFontBuilder.LineFontType.Centerline ' -----------------------------'Dimension - Tolerance Settings' ----------------------------- preferencesBuilder1.AnnotationStyle.DimensionStyle.ToleranceType= NXOpen.Annotations.ToleranceType.None preferencesBuilder1.AnnotationStyle.DimensionStyle.DimZeroToleranceDisplayStyle= NXOpen.Annotations.ZeroToleranceDisplayStyle.AsZero preferencesBuilder1.AnnotationStyle.DimensionStyle.AngularToleranceValuePrecision=2 preferencesBuilder1.AnnotationStyle.DimensionStyle.ToleranceValuePrecision=2 preferencesBuilder1.AnnotationStyle.UnitsStyle.DisplayLeadingToleranceZeros=True ' ----------------------------------'Dimension - Dual Dimension Settings' ---------------------------------- preferencesBuilder1.AnnotationStyle.UnitsStyle.DualDimensionFormat= NXOpen.Annotations.DualDimensionPlacement.None ' --------------------------'Dimension - Narrow Settings' -------------------------- preferencesBuilder1.AnnotationStyle.DimensionStyle.NarrowDisplayType= NXOpen.Annotations.NarrowDisplayOption.None ' --------------------------------------'Dimension - Ordinate dimension Settings' -------------------------------------- preferencesBuilder1.AnnotationStyle.OrdinateStyle.DoglegCreationOption= NXOpen.Annotations.OrdinateDoglegCreationOption.No preferencesBuilder1.AnnotationStyle.OrdinateStyle.DisplayNameStyle= NXOpen.Annotations.OrdinateOriginDisplayOption.NoText preferencesBuilder1.AnnotationStyle.OrdinateStyle.OrdinateTextOrientation= NXOpen.Annotations.TextOrientation.Horizontal preferencesBuilder1.AnnotationStyle.OrdinateStyle.OrdinateTextOrientation= NXOpen.Annotations.TextOrientation.OverDimensionLine ' -----------------------------------------------'Dimension - Text Orientation & Location Settings' ----------------------------------------------- preferencesBuilder1.AnnotationStyle.DimensionStyle.Orientation= NXOpen.Annotations.TextOrientation.OverDimensionLine preferencesBuilder1.AnnotationStyle.DimensionStyle.TextPosition= NXOpen.Annotations.TextPosition.AboveStub ' ------------------------------'Dimension - Text Units Settings' ------------------------------ preferencesBuilder1.AnnotationStyle.UnitsStyle.DimensionLinearUnits= NXOpen.Annotations.DimensionUnit.Millimeters preferencesBuilder1.AnnotationStyle.DimensionStyle.AngularDimensionValuePrecision=2 preferencesBuilder1.AnnotationStyle.DimensionStyle.DimensionValuePrecision=2 preferencesBuilder1.AnnotationStyle.UnitsStyle.DecimalPointCharacter= NXOpen.Annotations.DecimalPointCharacter.Period preferencesBuilder1.AnnotationStyle.UnitsStyle.DisplayLeadingDimensionZeros=True preferencesBuilder1.AnnotationStyle.UnitsStyle.DisplayTrailingZeros=False ' ----------------------------------'Dimension - Dimension Text Settings' ---------------------------------- preferencesBuilder1.AnnotationStyle.LetteringStyle.DimensionTextFont=8 preferencesBuilder1.AnnotationStyle.LetteringStyle.DimensionTextColor= workPart.Colors.Find("Green") preferencesBuilder1.AnnotationStyle.LetteringStyle.DimensionTextLineWidth= NXOpen.Annotations.LineWidth.Thin ' ---------------------------------'Dimension - Appended Text Settings' --------------------------------- preferencesBuilder1.AnnotationStyle.LetteringStyle.AppendedTextFont=8 preferencesBuilder1.AnnotationStyle.LetteringStyle.AppendedTextColor= workPart.Colors.Find("Brown") preferencesBuilder1.AnnotationStyle.LetteringStyle.AppendedTextLineWidth= NXOpen.Annotations.LineWidth.Thin ' ----------------------------------'Dimension - Tolerance Text Settings' ---------------------------------- preferencesBuilder1.AnnotationStyle.LetteringStyle.ToleranceTextColor= workPart.Colors.Find("Strong Stone") preferencesBuilder1.AnnotationStyle.LetteringStyle.ToleranceTextFont=8 preferencesBuilder1.AnnotationStyle.LetteringStyle.ToleranceTextLineWidth= NXOpen.Annotations.LineWidth.Thin ' ------------------------'Annotation - GDT Settings' ------------------------ preferencesBuilder1.AnnotationStyle.SymbolStyle.GdtSymbolColor= workPart.Colors.Find("Yellow") preferencesBuilder1.AnnotationStyle.SymbolStyle.GdtSymbolFont= NXOpen.DisplayableObject.ObjectFont.Solid preferencesBuilder1.AnnotationStyle.SymbolStyle.GdtSymbolWidth= NXOpen.Annotations.LineWidth.Two ' ---------------------------------------------'Annotation - Symbol Style - Id Symbol settings' --------------------------------------------- preferencesBuilder1.AnnotationStyle.SymbolStyle.IdSymbolColor= workPart.Colors.Find("Yellow") preferencesBuilder1.AnnotationStyle.SymbolStyle.IdSymbolFont= NXOpen.DisplayableObject.ObjectFont.Solid preferencesBuilder1.AnnotationStyle.SymbolStyle.IdSymbolWidth= NXOpen.Annotations.LineWidth.Two ' --------------------------------------------------'Annotation - Symbol Style - Surface Finish settings' -------------------------------------------------- preferencesBuilder1.AnnotationStyle.SymbolStyle.SurfaceFinishColor= workPart.Colors.Find("Yellow") preferencesBuilder1.AnnotationStyle.SymbolStyle.SurfaceFinishFont= NXOpen.DisplayableObject.ObjectFont.Solid preferencesBuilder1.AnnotationStyle.SymbolStyle.SurfaceFinishWidth= NXOpen.Annotations.LineWidth.Two ' -----------------------------------------------'Annotation - Symbol Style - Weld Symbol settings' ----------------------------------------------- preferencesBuilder1.AnnotationStyle.SymbolStyle.WeldSymbolColor= workPart.Colors.Find("Yellow") preferencesBuilder1.AnnotationStyle.SymbolStyle.WeldSymbolFont= NXOpen.DisplayableObject.ObjectFont.Solid preferencesBuilder1.AnnotationStyle.SymbolStyle.WeldSymbolWidth= NXOpen.Annotations.LineWidth.Two ' -------------------------------------------------'Annotation - Symbol Style - Target Symbol settings' ------------------------------------------------- preferencesBuilder1.AnnotationStyle.SymbolStyle.TargetSymbolColor= workPart.Colors.Find("Yellow") preferencesBuilder1.AnnotationStyle.SymbolStyle.TargetSymbolFont= NXOpen.DisplayableObject.ObjectFont.Phantom preferencesBuilder1.AnnotationStyle.SymbolStyle.TargetSymbolWidth= NXOpen.Annotations.LineWidth.Two ' -------------------------------------------------------'Annotation - Symbol Style - Intersection Symbol settings' ------------------------------------------------------- preferencesBuilder1.AnnotationStyle.SymbolStyle.IntersectionSymbolColor= workPart.Colors.Find("Yellow") preferencesBuilder1.AnnotationStyle.SymbolStyle.IntersectionSymbolFont= NXOpen.DisplayableObject.ObjectFont.Phantom preferencesBuilder1.AnnotationStyle.SymbolStyle.IntersectionSymbolWidth= NXOpen.Annotations.LineWidth.Two ' -----------------------------------------------------'Annotation - Symbol Style - Center Line Symbol settings' ----------------------------------------------------- preferencesBuilder1.AnnotationStyle.SymbolStyle.CenterlineSymbolColor= workPart.Colors.Find("Black") preferencesBuilder1.AnnotationStyle.SymbolStyle.CenterlineSymbolWidth= NXOpen.Annotations.LineWidth.Two ' --------------------------------------------'Annotation - Cross Hatch / Area Fill Settings' -------------------------------------------- preferencesBuilder1.AnnotationStyle.HatchStyle.Color= workPart.Colors.Find("Black") preferencesBuilder1.AnnotationStyle.HatchStyle.HatchAngle=45.0 preferencesBuilder1.AnnotationStyle.HatchStyle.LineWidth= NXOpen.Annotations.LineWidth.Two ' -----------------------------'Table - Common - Cell Settings' ----------------------------- preferencesBuilder1.TableCellStyle.TextAlignment= NXOpen.Annotations.TableCellStyleBuilder.TextAlignmentType.MidCenter preferencesBuilder1.TableCellStyle.BorderColor=216 preferencesBuilder1.TableCellStyle.ZeroDisplay= NXOpen.Annotations.TableCellStyleBuilder.ZeroDisplayType.Dash preferencesBuilder1.TableCellStyle.BorderFont=1 preferencesBuilder1.TableCellStyle.BorderWidth=6 preferencesBuilder1.TableCellStyle.TabDirection= NXOpen.Annotations.TableCellStyleBuilder.TabDirectionType.Down preferencesBuilder1.TableCellStyle.TextAlignment= NXOpen.Annotations.TableCellStyleBuilder.TextAlignmentType.MidCenter ' --------------------------------'Table - Common - Section Settings' -------------------------------- preferencesBuilder1.TableSection.HeaderLocation= NXOpen.Annotations.TableSectionStyleBuilder.LocationOfHeader.Above preferencesBuilder1.TableSection.MaximumHeight=2000.0 preferencesBuilder1.TableSection.AlignmentPosition= NXOpen.Annotations.TableSectionStyleBuilder.AlignmentPositionType.TopLeft ' -----------------------------------'Table - Common - Parts List Settings' ----------------------------------- preferencesBuilder1.PartsList.GrowDirectionOptions= NXOpen.Annotations.PartsListBuilder.PartsListGrowDirectionOptions.Down preferencesBuilder1.PartsList.AutomaticUpdate=False preferencesBuilder1.PartsList.SortOnUpdate=False preferencesBuilder1.PartsList.AllowManualRows=True ' -----------------------------------'Table - Common - Tabular Note Settings' ----------------------------------- preferencesBuilder1.TabularNoteStyle.LockTableFormat=True preferencesBuilder1.TabularNoteStyle.LockTableContents=True ' -----------------------------------'Drafting / Leader Note Settings' ----------------------------------- draftingNoteBuilder1.Origin.Anchor= NXOpen.Annotations.OriginBuilder.AlignmentPosition.MidCenter draftingNoteBuilder1.TextAlignment= NXOpen.Annotations.DraftingNoteBuilder.TextAlign.Belowbottom leaderData1.StubSize=5 leaderData1.Arrowhead= NXOpen.Annotations.LeaderData.ArrowheadType.FilledArrow leaderData1.VerticalAttachment= NXOpen.Annotations.LeaderVerticalAttachment.Center leaderData1.StubSide= NXOpen.Annotations.LeaderSide.Inferred EndSubEndModule
Section Line Thickness Change
Hello,
Below is the code that i have recorded to change the thickness of section line t0 0.13mm (NXOpen.DisplayableObject.ObjectWidth.One),
How to modify this code to process all the section line in all drawing sheets of workpart
Can you please help me, Thanks in advance, below is recorded code
Imports System Imports NXOpen Module NXJournal Sub Main (ByVal args()AsString) Dim theSession As NXOpen.Session= NXOpen.Session.GetSession()Dim workPart As NXOpen.Part= theSession.Parts.WorkDim displayPart As NXOpen.Part= theSession.Parts.Display Dim sectionlines1(0)As NXOpen.Drawings.SectionLineDim steppedSectionLine1 As NXOpen.Drawings.SteppedSectionLine=CType(workPart.FindObject("HANDLE R-360966"), NXOpen.Drawings.SteppedSectionLine) sectionlines1(0)= steppedSectionLine1 Dim editSectionLineSettingsBuilder1 As NXOpen.Drawings.EditSectionLineSettingsBuilder=Nothing editSectionLineSettingsBuilder1 = workPart.SettingsManager.CreateDrawingEditSectionLineSettingsBuilder(sectionlines1) Dim editsettingsbuilders1(0)As NXOpen.Drafting.BaseEditSettingsBuilder editsettingsbuilders1(0)= editSectionLineSettingsBuilder1 workPart.SettingsManager.ProcessForMultipleObjectsSettings(editsettingsbuilders1) editSectionLineSettingsBuilder1.ViewSectionLine.LineColorFontWidth.LineWidth= NXOpen.DisplayableObject.ObjectWidth.One Dim nXObject1 As NXOpen.NXObject=Nothing nXObject1 = editSectionLineSettingsBuilder1.Commit() EndSubEndModule