Forums:
Hi everyone.
The code bellow, creates a feature point into Assembly or Part Navigator, named CoG. Great for now.
Some questions came out to improve this code.
1st - Selection mode is looking for everything in teh wok part. I'm just looking for displayed parts and components. How can I set this?
2nd - Regarding 1st, the mass in some cases that I've tested, was double when using Wave linked geometry, except when set the body base as non-geometric (as reference, for Teamcenter users). There's some tips for that too?
3rd, but not less important - how can I set this point to be updated and send it to the last feature order if its already exists?
Option Strict Off Imports System Imports System.Collections.GenericImports NXOpen Imports NXOpen.UF Module Module1 Dim theSession As Session = Session.GetSession()Dim theUfSession As UFSession = UFSession.GetUFSession()Dim lw As ListingWindow = theSession.ListingWindow Sub Main() Dim workPart As Part = theSession.Parts.Work lw.Open()Dim max AsIntegerIf workPart.PartUnits= Part.Units.InchesThen max =10Else'metric file max =250EndIfConst undoMarkName AsString="report assembly mass props"Dim markId1 As Session.UndoMarkId markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName) Dim bodyTags AsNew List(Of Tag) bodyTags = AskAllBodyTags(theSession.Parts.Display) lw.WriteLine("number of body tags found: "& bodyTags.Count.ToString) Dim acc_value(10)AsDouble acc_value(0)=0.999Dim mass_props(46)AsDoubleDim stats(12)AsDouble theUfSession.Modl.AskMassProps3d(bodyTags.ToArray, bodyTags.Count, 1, 1, 0.03, 1, acc_value, mass_props, stats) lw.WriteLine("Mass: "& mass_props(2).ToString&" lbf") lw.WriteLine("Center of Mass:") lw.writeline("X: "& mass_props(3).ToString) lw.writeline("Y: "& mass_props(4).ToString) lw.writeline("Z: "& mass_props(5).ToString) Dim p1 = NXOpen.Session.GetSession.Parts.Work.Points.CreatePoint(New Point3d(mass_props(3), mass_props(4), mass_props(5))) p1.SetVisibility(SmartObject.VisibilityOption.Visible) Dim nullNXOpen_Features_Feature As NXOpen.Features.Feature=Nothing Dim pointFeatureBuilder1 As NXOpen.Features.PointFeatureBuilder=Nothing pointFeatureBuilder1 = workPart.BaseFeatures.CreatePointFeatureBuilder(nullNXOpen_Features_Feature) pointFeatureBuilder1.Point= p1 Dim nXObject1 As NXOpen.NXObject=Nothing nXObject1 = pointFeatureBuilder1.Commit() nXObject1.SetName("CoG") pointFeatureBuilder1.Destroy() lw.Close()EndSub Function AskAllBodyTags(ByVal thePart As Part)As List(Of Tag) Dim theBodyTags AsNew List(Of Tag)Dim aBodyTag As Tag = Tag.NullDo theUfSession.Obj.CycleObjsInPart(thePart.Tag, UFConstants.UF_solid_type, aBodyTag)If aBodyTag = Tag.NullThenExitDoEndIf Dim theType AsInteger, theSubtype AsInteger theUfSession.Obj.AskTypeAndSubtype(aBodyTag, theType, theSubtype)If theSubtype = UFConstants.UF_solid_body_subtypeThen Dim bodyType AsInteger=0 theUfSession.Modl.AskBodyType(aBodyTag, bodyType)If bodyType = UFConstants.UF_MODL_SOLID_BODYThen theBodyTags.Add(aBodyTag)EndIf EndIf LoopWhileTrue Return theBodyTags EndFunction PublicFunction GetUnloadOption(ByVal dummy AsString)AsInteger 'Unloads the image when the NX session terminates GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination EndFunction EndModule