Submitted by noraboke on Tue, 04/28/2020 - 07:12
Forums:
I'm trying to use AskPointContainment to determine whether a point is inside a body or not.
According to https://docs.plm.automation.siemens.com/data_services/resources/nx/11/nx..., the function should take a list of float and a body object.
I've tried using Point objects, Point3d, and something like [0.0, 0.0, 0.0] to represent a list of floats without any success. The error message states that a 'NXOpen.UF.Modeling' object is required, but something else has been received.
I'm wondering if anyone has had any experience with this or know how to get it working?
re: AskPointContainment
Try the code below. It will loop through the work part's .Bodies collection and test the given point (hardcoded values) on each body. For testing, I made a new file and created a block feature (corners at 0,0,0 and 100,100,100); I then entered different point values for each run.
import NXOpen
import NXOpen.UF
theSession = NXOpen.Session.GetSession()
theUfSession = NXOpen.UF.UFSession.GetUFSession()
theLw = theSession.ListingWindow
def main():
workPart = theSession.Parts.Work
theLw.Open()
for tempBody in workPart.Bodies:
if tempBody.Layer < 0 or tempBody.Layer > 256:
continue
theLw.WriteLine("body tag: " + str(tempBody.Tag))
isAlive = theUfSession.Obj.AskStatus(tempBody.Tag)
#theLw.WriteLine("isAlive: " + str(isAlive))
if isAlive == NXOpen.UF.UFConstants.UF_OBJ_ALIVE:
theLw.WriteLine("body is alive")
ptContain = theUfSession.Modeling.AskPointContainment([50.0, 50.0, 50.0],tempBody.Tag)
theLw.WriteLine("return value: " + str(ptContain))
if ptContain == 1:
theLw.WriteLine("point is in the body")
if ptContain == 2:
theLw.WriteLine("point is outside the body")
if ptContain == 3:
theLw.WriteLine("point is on the body")
theLw.Close()
if __name__ == '__main__':
main()
curves array to temp surface
Thanks for sharing this code.
I have arrays of 4 connected curves(quadrilaterals).
Any tips on how can those arrays be converted to a temp surface?
To check if an arc point falls on the temp surface ?
BH
re: curves to temp surface
If you have 4 curves that bound an area, I'd suggest using through curve mesh to create a surface for your calculations. You can simply delete the surface when you are done with it.
curves array to Tag of temp surface
Thanks a lot for the tip.
I tweaked Fill Surface Command's recorded journal, it looked much simpler than the Curve Mesh recorded journal.
Below code is working with my quad array.
public static NXOpen.Tag CreatedSheetsTag(Curve[] curvesarray)
{
NXOpen.Session theSession = NXOpen.Session.GetSession();
NXOpen.Part workPart = theSession.Parts.Work;
NXOpen.Part displayPart = theSession.Parts.Display;
UFSession theUfSession = UFSession.GetUFSession();
// ----------------------------------------------
// Menu: Insert->Surface->Fill Surface...
// ----------------------------------------------
NXOpen.Session.UndoMarkId markId1;
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start");
NXOpen.ListingWindow lw = theSession.ListingWindow;
NXOpen.Features.FillHole nullNXOpen_Features_FillHole = null;
NXOpen.Features.FillHoleBuilder fillHoleBuilder1;
fillHoleBuilder1 = workPart.Features.FreeformSurfaceCollection.CreateFillHoleBuilder(nullNXOpen_Features_FillHole);
fillHoleBuilder1.Tolerance = 0.0004;
fillHoleBuilder1.DefaultEdgeContinuity = NXOpen.Features.FillHoleBuilder.ContinuityTypes.G1;
fillHoleBuilder1.Fullness.SetFormula("0");
theSession.SetUndoMarkName(markId1, "Fill Surface Dialog");
fillHoleBuilder1.CurveChain.DistanceTolerance = 0.0004;
fillHoleBuilder1.CurveChain.ChainingTolerance = 0.00038;
fillHoleBuilder1.SelectPassThrougCurves.DistanceTolerance = 0.0004;
fillHoleBuilder1.SelectPassThrougCurves.ChainingTolerance = 0.00038;
fillHoleBuilder1.CurveChain.SetAllowedEntityTypes(NXOpen.Section.AllowTypes.OnlyCurves);
NXOpen.SelectionIntentRuleOptions selectionIntentRuleOptions1;
selectionIntentRuleOptions1 = workPart.ScRuleFactory.CreateRuleOptions();
selectionIntentRuleOptions1.SetSelectedFromInactive(false);
NXOpen.IBaseCurve[] curves1 = new NXOpen.IBaseCurve[1];
NXOpen.Curve line1 = curvesarray[0];
curves1[0] = line1;
NXOpen.CurveDumbRule curveDumbRule1;
curveDumbRule1 = workPart.ScRuleFactory.CreateRuleBaseCurveDumb(curves1, selectionIntentRuleOptions1);
selectionIntentRuleOptions1.Dispose();
fillHoleBuilder1.CurveChain.AllowSelfIntersection(true);
fillHoleBuilder1.CurveChain.AllowDegenerateCurves(false);
NXOpen.SelectionIntentRule[] rules1 = new NXOpen.SelectionIntentRule[1];
rules1[0] = curveDumbRule1;
NXOpen.NXObject nullNXOpen_NXObject = null;
NXOpen.Point3d helpPoint1 = new NXOpen.Point3d(0, 0, 0.0);
fillHoleBuilder1.CurveChain.AddToSection(rules1, line1, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1, NXOpen.Section.Mode.Create, false);
// theSession.DeleteUndoMark(markId3, null);
NXOpen.Features.FillHoleBuilder.BorderContinuity[] markertonodelistitem1 = new NXOpen.Features.FillHoleBuilder.BorderContinuity[1];
markertonodelistitem1[0].BorderObject = line1;
markertonodelistitem1[0].Continuity = NXOpen.Features.FillHoleBuilder.ContinuityTypes.G0;
fillHoleBuilder1.SetBorderTypeItems(markertonodelistitem1);
// theSession.DeleteUndoMark(markId2, null);
NXOpen.Session.UndoMarkId markId4;
markId4 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "section mark");
NXOpen.Session.UndoMarkId markId5;
markId5 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, null);
NXOpen.SelectionIntentRuleOptions selectionIntentRuleOptions2;
selectionIntentRuleOptions2 = workPart.ScRuleFactory.CreateRuleOptions();
selectionIntentRuleOptions2.SetSelectedFromInactive(false);
NXOpen.IBaseCurve[] curves2 = new NXOpen.IBaseCurve[1];
NXOpen.Curve line2 = curvesarray[1];
curves2[0] = line2;
NXOpen.CurveDumbRule curveDumbRule2;
curveDumbRule2 = workPart.ScRuleFactory.CreateRuleBaseCurveDumb(curves2, selectionIntentRuleOptions2);
selectionIntentRuleOptions2.Dispose();
fillHoleBuilder1.CurveChain.AllowSelfIntersection(true);
fillHoleBuilder1.CurveChain.AllowDegenerateCurves(false);
NXOpen.SelectionIntentRule[] rules2 = new NXOpen.SelectionIntentRule[1];
rules2[0] = curveDumbRule2;
fillHoleBuilder1.CurveChain.AddToSection(rules2, line2, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1, NXOpen.Section.Mode.Create, false);
theSession.DeleteUndoMark(markId5, null);
NXOpen.Features.FillHoleBuilder.BorderContinuity[] markertonodelistitem2 = new NXOpen.Features.FillHoleBuilder.BorderContinuity[2];
markertonodelistitem2[0].BorderObject = line1;
markertonodelistitem2[0].Continuity = NXOpen.Features.FillHoleBuilder.ContinuityTypes.G0;
markertonodelistitem2[1].BorderObject = line2;
markertonodelistitem2[1].Continuity = NXOpen.Features.FillHoleBuilder.ContinuityTypes.G0;
fillHoleBuilder1.SetBorderTypeItems(markertonodelistitem2);
theSession.DeleteUndoMark(markId4, null);
NXOpen.Session.UndoMarkId markId6;
markId6 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "section mark");
NXOpen.Session.UndoMarkId markId7;
markId7 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, null);
NXOpen.SelectionIntentRuleOptions selectionIntentRuleOptions3;
selectionIntentRuleOptions3 = workPart.ScRuleFactory.CreateRuleOptions();
selectionIntentRuleOptions3.SetSelectedFromInactive(false);
NXOpen.IBaseCurve[] curves3 = new NXOpen.IBaseCurve[1];
NXOpen.Curve line3 = curvesarray[2];
curves3[0] = line3;
NXOpen.CurveDumbRule curveDumbRule3;
curveDumbRule3 = workPart.ScRuleFactory.CreateRuleBaseCurveDumb(curves3, selectionIntentRuleOptions3);
selectionIntentRuleOptions3.Dispose();
fillHoleBuilder1.CurveChain.AllowSelfIntersection(true);
fillHoleBuilder1.CurveChain.AllowDegenerateCurves(false);
NXOpen.SelectionIntentRule[] rules3 = new NXOpen.SelectionIntentRule[1];
rules3[0] = curveDumbRule3;
// NXOpen.Point3d helpPoint3 = new NXOpen.Point3d(40.740237573113525, -41.5, 0.0);
fillHoleBuilder1.CurveChain.AddToSection(rules3, line3, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1, NXOpen.Section.Mode.Create, false);
theSession.DeleteUndoMark(markId7, null);
NXOpen.Features.FillHoleBuilder.BorderContinuity[] markertonodelistitem3 = new NXOpen.Features.FillHoleBuilder.BorderContinuity[3];
markertonodelistitem3[0].BorderObject = line1;
markertonodelistitem3[0].Continuity = NXOpen.Features.FillHoleBuilder.ContinuityTypes.G0;
markertonodelistitem3[1].BorderObject = line2;
markertonodelistitem3[1].Continuity = NXOpen.Features.FillHoleBuilder.ContinuityTypes.G0;
markertonodelistitem3[2].BorderObject = line3;
markertonodelistitem3[2].Continuity = NXOpen.Features.FillHoleBuilder.ContinuityTypes.G0;
fillHoleBuilder1.SetBorderTypeItems(markertonodelistitem3);
theSession.DeleteUndoMark(markId6, null);
NXOpen.Session.UndoMarkId markId8;
markId8 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "section mark");
NXOpen.Session.UndoMarkId markId9;
markId9 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, null);
NXOpen.SelectionIntentRuleOptions selectionIntentRuleOptions4;
selectionIntentRuleOptions4 = workPart.ScRuleFactory.CreateRuleOptions();
selectionIntentRuleOptions4.SetSelectedFromInactive(false);
NXOpen.IBaseCurve[] curves4 = new NXOpen.IBaseCurve[1];
NXOpen.Curve line4 = curvesarray[3];
curves4[0] = line4;
NXOpen.CurveDumbRule curveDumbRule4;
curveDumbRule4 = workPart.ScRuleFactory.CreateRuleBaseCurveDumb(curves4, selectionIntentRuleOptions4);
selectionIntentRuleOptions4.Dispose();
fillHoleBuilder1.CurveChain.AllowSelfIntersection(true);
fillHoleBuilder1.CurveChain.AllowDegenerateCurves(false);
NXOpen.SelectionIntentRule[] rules4 = new NXOpen.SelectionIntentRule[1];
rules4[0] = curveDumbRule4;
fillHoleBuilder1.CurveChain.AddToSection(rules4, line4, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1, NXOpen.Section.Mode.Create, false);
theSession.DeleteUndoMark(markId9, null);
NXOpen.Features.FillHoleBuilder.BorderContinuity[] markertonodelistitem4 = new NXOpen.Features.FillHoleBuilder.BorderContinuity[4];
markertonodelistitem4[0].BorderObject = line1;
markertonodelistitem4[0].Continuity = NXOpen.Features.FillHoleBuilder.ContinuityTypes.G0;
markertonodelistitem4[1].BorderObject = line2;
markertonodelistitem4[1].Continuity = NXOpen.Features.FillHoleBuilder.ContinuityTypes.G0;
markertonodelistitem4[2].BorderObject = line3;
markertonodelistitem4[2].Continuity = NXOpen.Features.FillHoleBuilder.ContinuityTypes.G0;
markertonodelistitem4[3].BorderObject = line4;
markertonodelistitem4[3].Continuity = NXOpen.Features.FillHoleBuilder.ContinuityTypes.G0;
fillHoleBuilder1.SetBorderTypeItems(markertonodelistitem4);
theSession.DeleteUndoMark(markId8, null);
NXOpen.Session.UndoMarkId markId10;
markId10 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Fill Surface");
theSession.DeleteUndoMark(markId10, null);
NXOpen.Session.UndoMarkId markId11;
markId11 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Fill Surface");
NXOpen.NXObject nXObject1;
nXObject1 = fillHoleBuilder1.Commit();
NXOpen.Features.Feature[] newSheetfeature = workPart.Features.ToArray();
NXOpen.Features.Feature lastsheetfeature = newSheetfeature[newSheetfeature.Length - 1];
NXObject[] sheetbodies;
DeleteTags.Add(lastsheetfeature.Tag);
sheetbodies = lastsheetfeature.GetBodies();
//lw.WriteLine(sheetbodies[0].Tag.ToString());
Tag sheetbodytag = sheetbodies[0].Tag;
return sheetbodytag;
}
BH
re: curves to temp surface
Ah, I forgot about fill surface - a good choice!
Ahhh, I see! Thank you!
Ahhh, I see! Thank you!