Hello
When i try scale 1 body, i need to use a variable but the formula only accept integer variables, but i need to use double, what i need to change or is there another way to do this?
Imports System
Imports NXOpen
Module NXJournal
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->Offset/Scale->Scale Body...
Dim nullNXOpen_Features_Feature As NXOpen.Features.Feature = Nothing
Dim scaleBuilder1 As NXOpen.Features.ScaleBuilder = Nothing
scaleBuilder1 = workPart.Features.CreateScaleBuilder(nullNXOpen_Features_Feature)
Dim scCollector1 As NXOpen.ScCollector = Nothing
scCollector1 = workPart.ScCollectors.CreateCollector()
Dim selectionIntentRuleOptions1 As NXOpen.SelectionIntentRuleOptions = Nothing
selectionIntentRuleOptions1 = workPart.ScRuleFactory.CreateRuleOptions()
selectionIntentRuleOptions1.SetSelectedFromInactive(False)
Dim bodies1(0) As NXOpen.Body
Dim body1 As NXOpen.Body = CType(workPart.Bodies.FindObject("UNPARAMETERIZED_FEATURE(1)"), NXOpen.Body)
bodies1(0) = body1
Dim bodyDumbRule1 As NXOpen.BodyDumbRule = Nothing
bodyDumbRule1 = workPart.ScRuleFactory.CreateRuleBodyDumb(bodies1, True, selectionIntentRuleOptions1)
selectionIntentRuleOptions1.Dispose()
Dim rules1(0) As NXOpen.SelectionIntentRule
rules1(0) = bodyDumbRule1
scCollector1.ReplaceRules(rules1, False)
scaleBuilder1.BodyCollector = scCollector1
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)
scaleBuilder1.Point = point1
Dim origin1 As NXOpen.Point3d = New NXOpen.Point3d(0.0, 0.0, 0.0)
Dim vector1 As NXOpen.Vector3d = New NXOpen.Vector3d(0.0, 0.0, 1.0)
Dim direction1 As NXOpen.Direction = Nothing
direction1 = workPart.Directions.CreateDirection(origin1, vector1, NXOpen.SmartObject.UpdateOption.WithinModeling)
scaleBuilder1.Vector = direction1
Dim unit1 As NXOpen.Unit = CType(workPart.UnitCollection.FindObject("MilliMeter"), NXOpen.Unit)
Dim origin2 As NXOpen.Point3d = New NXOpen.Point3d(0.0, 0.0, 0.0)
Dim xDirection1 As NXOpen.Vector3d = New NXOpen.Vector3d(1.0, 0.0, 0.0)
Dim yDirection1 As NXOpen.Vector3d = New NXOpen.Vector3d(0.0, 1.0, 0.0)
Dim xform1 As NXOpen.Xform = Nothing
xform1 = workPart.Xforms.CreateXform(origin2, xDirection1, yDirection1, NXOpen.SmartObject.UpdateOption.WithinModeling, 1.0)
Dim cartesianCoordinateSystem1 As NXOpen.CartesianCoordinateSystem = Nothing
cartesianCoordinateSystem1 = workPart.CoordinateSystems.CreateCoordinateSystem(xform1, NXOpen.SmartObject.UpdateOption.WithinModeling)
scaleBuilder1.Csys = cartesianCoordinateSystem1
dim a as integer = 1.001
scaleBuilder1.UniformFactor.SetFormula(a)
Dim nXObject1 As NXOpen.NXObject = Nothing
nXObject1 = scaleBuilder1.Commit()
scaleBuilder1.Destroy()
workPart.MeasureManager.SetPartTransientModification()
workPart.MeasureManager.ClearPartTransientModification()
theSession.CleanUpFacetedFacesAndEdges()
End Sub
End Module
I found the solution but i
I found the solution but i need to add quote marks in the begin and in the end, but now i have new problem.
How to add " to the begin and to the end of a string?
Like this:
dim a as string = 1.001
dim b as string = " & a & " ' <------ how to add this two " to have "1.001"
scaleBuilder1.UniformFactor.SetFormula(b)
can someone help me?
re: string expression
Try the following:
dim a as string = """1.001"""
scaleBuilder1.UniformFactor.SetFormula(a)
When creating a string expression in NX, it wants the double quotes around the string value. In VB.net, the escape character for this is itself the double quote character, so we end up with 3 double quotes in a row - the first to tell VB this is a string, the 2nd is an escape character, and the 3rd is the literal character we want to include in the string. For a more detailed explanation, see the "create a string expression" section of the following article:
https://nxjournaling.com/content/expressions-creating-expressions-no-units
The problem is that i have
The problem is that i have the string variable A that have a number, like 1.001, and i need a new variable B that is the variable A with " at the begin and in the end to become "1.001"
I already tried but didnt
I already tried but didnt work
dim a as string
dim b as string
a= 1.006
b= chr(34) & a & chr(34)
scaleBuilder1.UniformFactor.SetFormula( b)
Sorry, this worked, the
Sorry, this worked, the problem was that when i did a = 1.006, i dont know why but a had 1,006, changed dot to comma.
I can use """" or chr(34), both work
thank you
re: string expression
The Windows regional settings will determine how a dot vs. a comma is interpreted when converting strings to numbers.