UGperson
Automotive
- Mar 18, 2004
- 104
I have to questions.
How would I check for an expression and if it exists delete it?
how could I have an expression always equal the mass of the measured body?
Thanks
How would I check for an expression and if it exists delete it?
how could I have an expression always equal the mass of the measured body?
Thanks
Code:
' NX 7.5.4.4
' Journal created by UGperson on Wed Mar 06 13:07:42 2013 Eastern Standard Time
'
Option Strict Off
Imports System
Imports NXOpen
Imports System.Collections
Imports NXOpen.UF
Module NXJournal
Sub Main
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
' ----------------------------------------------
' Menu: Tools->Expression...
' ----------------------------------------------
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Expression")
'Dim expressionMassAttr As string
'Dim expressMass As string
'Dim expression1 As Expression = CType(workPart.Expressions.FindObject("MASS_ATTRIBUTE"), Expression)
'Check for expression "MASS_ATTRIBUTE"
Dim expressionMassAttr As Expression = CType(workPart.Expressions.FindObject("MASS_ATTRIBUTE"), Expression)
'workPart.Expressions.Delete(expression1)
'Delete expression "MASS_ATTRIBUTE"
workPart.Expressions.Delete(expressionMassAttr)
'Dim expression2 As Expression = CType(workPart.Expressions.FindObject("MASS"), Expression)
'Check for expression "MASS"
Dim expressMass As Expression = CType(workPart.Expressions.FindObject("MASS"), Expression)
'workPart.Expressions.Delete(expression2)
'Delete expression "MASS"
workPart.Expressions.Delete(expressMass)
Dim nErrs2 As Integer
nErrs2 = theSession.UpdateManager.DoUpdate(markId1)
' ----------------------------------------------
' Menu: Analysis->Measure Bodies...
' ----------------------------------------------
Dim markIdMeasure As Session.UndoMarkId
markIdMeasure = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")
Dim nullNXObject As NXObject = Nothing
Dim measureBodyBuilder1 As MeasureBodyBuilder
measureBodyBuilder1 = workPart.MeasureManager.CreateMeasureBodyBuilder(nullNXObject)
theSession.SetUndoMarkName(markIdMeasure, "Measure Bodies Dialog")
'Dim body1 As Body = CType(workPart.Bodies.FindObject("BLOCK(1)"), Body)
Dim lw As ListingWindow = theSession.ListingWindow
Dim mySelections() as NXObject
Dim myFaces as New ArrayList()
Dim myBodys as New ArrayList()
Dim i as Integer
Dim myFace as Face
Dim myBody as Body
If (SelectFaces(mySelections) = Selection.Response.Ok) Then
lw.Open
lw.WriteLine(UBound(mySelections) + 1 & "Bodys selected")
For each myEntity as NXObject in mySelections
if myEntity.GetType().ToString = "NXOpen.Body" then
myBodys.Add(myEntity)
end if
Next
Else
lw.Open
lw.WriteLine("Selection cancelled")
lw.WriteLine("")
lw.Close
End If
Dim body1 As Body = myBody
Dim added1 As Boolean
added1 = measureBodyBuilder1.BodyObjects.Add(body1)
Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Measure Bodies")
Dim massUnits1(4) As Unit
Dim unit1 As Unit = CType(workPart.UnitCollection.FindObject("SquareMilliMeter"), Unit)
massUnits1(0) = unit1
Dim unit2 As Unit = CType(workPart.UnitCollection.FindObject("CubicMilliMeter"), Unit)
massUnits1(1) = unit2
Dim unit3 As Unit = CType(workPart.UnitCollection.FindObject("Kilogram"), Unit)
massUnits1(2) = unit3
Dim unit4 As Unit = CType(workPart.UnitCollection.FindObject("MilliMeter"), Unit)
massUnits1(3) = unit4
Dim unit5 As Unit = CType(workPart.UnitCollection.FindObject("Newton"), Unit)
massUnits1(4) = unit5
Dim objects1(0) As IBody
objects1(0) = body1
Dim measureBodies1 As MeasureBodies
measureBodies1 = workPart.MeasureManager.NewMassProperties(massUnits1, 0.99, objects1)
Dim measure1 As Measure
measure1 = measureBodies1.CreateFeature()
measureBodies1.Dispose()
measureBodyBuilder1.BodyObjects.Clear()
theSession.DeleteUndoMark(markId2, Nothing)
theSession.SetUndoMarkName(markIdMeasure, "Measure Bodies")
measureBodyBuilder1.Destroy()
' ----------------------------------------------
' Menu: Tools->Expression...
' ----------------------------------------------
Dim markIdExpression As Session.UndoMarkId
markIdExpression = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Expression")
Dim nullUnit As Unit = Nothing
'how do a mke p15 always = mass of measured body?
'Sets mass from kg to g
Dim expression1 As Expression
expression1 = workPart.Expressions.CreateWithUnits("MASS=p15*1000", nullUnit)
'sets the mass to be an attribute
Dim expression2 As Expression
expression2 = workPart.Expressions.CreateWithUnits("MASS_ATTRIBUTE=ug_setPartAttrValue( ""MASS"",format(""%0.2f"",mass))", nullUnit)
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(markIdExpression)
' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------
End Sub
Function SelectFaces(ByRef selectedObjects() As NXObject) As Selection.Response
Dim ui As UI = NXOpen.UI.GetUI
Dim message As String = "Select Body"
Dim title As String = "Selection"
Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly
Dim keepHighlighted As Boolean = False
Dim includeFeatures As Boolean = False
Dim resp As Selection.Response
Dim selectionAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim selectionMask_array(1) As Selection.MaskTriple
With selectionMask_array(1)
.Type = UFConstants.UF_solid_type
End With
resp = ui.SelectionManager.SelectObjects(message, title, scope, selectionAction, includeFeatures, keepHighlighted, selectionMask_array, selectedObjects)
Return resp
End Function
End Module