/// <summary> /// 创建唯一 /// </summary> /// <param name="component"></param> /// <param name="str"></param> public static NXObject MakeUnique(NXOpen.Assemblies.Component component, string newFileName) { Part workPart = theSession.Parts.Work; NXOpen.Assemblies.MakeUniquePartBuilder makeUniquePartBuilder1; makeUniquePartBuilder1 = workPart.AssemblyManager.CreateMakeUniquePartBuilder(); bool added1; added1 = makeUniquePartBuilder1.SelectedComponents.Add(component); Tag partTag = theUFSession.Assem.AskPrototypeOfOcc(component.Tag); try { NXOpen.Part part1 = (Part)NXObjectManager.Get(partTag); part1.SetMakeUniqueName(newFileName); NXOpen.NXObject nXObject1; nXObject1 = makeUniquePartBuilder1.Commit(); return(nXObject1); } catch (Exception ex) { LogMgr.WriteLog("AssmbliesUtils:MakeUnique: " + ex.Message); return(null); } finally { makeUniquePartBuilder1.Destroy(); } }
internal ExpressionPoint(string name, Position value) { NXOpen.Part workPart = (NXOpen.Part)Globals.WorkPart; string str = "Point(" + value.X.ToString() + "," + value.Y.ToString() + "," + value.Z.ToString() + ")"; base.nxopenExpression = workPart.Expressions.CreateExpression("Point", name + "=" + str); }
public static CartesianCoordinateSystem CreateCoordinateSystem(Point3d ori, Vector3d xVec, Vector3d yVec, Vector3d zVec) { NXOpen.Session theSession = NXOpen.Session.GetSession(); NXOpen.Part workPart = theSession.Parts.Work; Matrix3x3 mat = new Matrix3x3(); mat.Xx = xVec.X; mat.Xy = xVec.Y; mat.Xz = xVec.Z; mat.Yx = yVec.X; mat.Yy = yVec.Y; mat.Yz = yVec.Z; //Vector3d zVec = UMathUtils.VectorCross(xVec, yVec); mat.Zx = zVec.X; mat.Zy = zVec.Y; mat.Zz = zVec.Z; try { return(workPart.CoordinateSystems.CreateCoordinateSystem(ori, mat, true)); } catch (Exception ex) { return(workPart.CoordinateSystems.CreateCoordinateSystem(ori, xVec, yVec)); } }
internal ExpressionString(string name, string value) { NXOpen.Part workPart = (NXOpen.Part)Globals.WorkPart; char ch = '"'; base.nxopenExpression = workPart.Expressions.CreateExpression("String", string.Concat(new object[] { name, "=", ch, value.ToString(), ch })); }
internal static Snap.NX.Revolve CreateRevolve(Snap.NX.ICurve[] icurves, Position axisPoint, Vector axisVector, Snap.Number[] extents, bool offset, Snap.Number[] offsetValues, bool createSheet) { NXOpen.Part workPart = (NXOpen.Part)Globals.WorkPart; NXOpen.Features.RevolveBuilder featureBuilder = workPart.Features.CreateRevolveBuilder(null); featureBuilder.Tolerance = Globals.DistanceTolerance; Snap.NX.Section section = Snap.NX.Section.CreateSection(icurves); featureBuilder.Section = (NXOpen.Section)section; section.NXOpenSection.DistanceTolerance = Globals.DistanceTolerance; section.NXOpenSection.ChainingTolerance = (Globals.UnitType == Globals.Unit.Millimeter) ? 0.02413 : 0.00095; featureBuilder.BooleanOperation.Type = BooleanOperation.BooleanType.Create; if (createSheet) { featureBuilder.FeatureOptions.BodyType = FeatureOptions.BodyStyle.Sheet; } featureBuilder.Limits.StartExtend.Value.RightHandSide = extents[0].ToString(); featureBuilder.Limits.EndExtend.Value.RightHandSide = extents[1].ToString(); featureBuilder.Offset.Option = NXOpen.GeometricUtilities.Type.NoOffset; if (offset) { featureBuilder.Offset.Option = NXOpen.GeometricUtilities.Type.NonsymmetricOffset; featureBuilder.Offset.StartOffset.RightHandSide = offsetValues[0].ToString(); featureBuilder.Offset.EndOffset.RightHandSide = offsetValues[1].ToString(); } Direction direction = workPart.Directions.CreateDirection((Point3d)axisPoint, (Vector3d)axisVector, SmartObject.UpdateOption.WithinModeling); NXOpen.Point point = null; NXOpen.Axis axis = workPart.Axes.CreateAxis(point, direction, SmartObject.UpdateOption.WithinModeling); featureBuilder.Axis = axis; NXOpen.Features.Revolve revolve = (NXOpen.Features.Revolve)Snap.NX.Feature.CommitFeature(featureBuilder); featureBuilder.Destroy(); return(new Snap.NX.Revolve(revolve)); }
internal static Snap.NX.TrimBody CreateTrimBody(Snap.NX.Body targetBody, Snap.NX.DatumPlane toolDatumPlane, bool direction) { NXOpen.Part workPart = (NXOpen.Part)Globals.WorkPart; TrimBodyBuilder featureBuilder = workPart.Features.CreateTrimBodyBuilder(null); //featureBuilder.Tolerance = Globals.DistanceTolerance; //featureBuilder.BooleanTool.ExtrudeRevolveTool.ToolSection.DistanceTolerance = Globals.DistanceTolerance; //featureBuilder.BooleanTool.ExtrudeRevolveTool.ToolSection.ChainingTolerance = (Globals.UnitType == Globals.Unit.Millimeter) ? 0.02413 : 0.00095; //ScCollector collector = workPart.ScCollectors.CreateCollector(); //NXOpen.Body[] bodies = new NXOpen.Body[] { targetBody }; //BodyDumbRule rule = workPart.ScRuleFactory.CreateRuleBodyDumb(bodies); //SelectionIntentRule[] rules = new SelectionIntentRule[] { rule }; //collector.ReplaceRules(rules, false); //featureBuilder.TargetBodyCollector = collector; featureBuilder.SetTargets(new NXOpen.Body[] { targetBody }); featureBuilder.Tool = toolDatumPlane.NXOpenDisplayableObject; featureBuilder.TrimDirection = direction ? TrimBodyBuilder.DirectionType.PositiveNormal : TrimBodyBuilder.DirectionType.NegativeNormal; //SelectionIntentRule[] ruleArray2 = new SelectionIntentRule[1]; //NXOpen.DatumPlane[] faces = new NXOpen.DatumPlane[] { toolDatumPlane.NXOpenDatumPlaneFeature.DatumPlane }; //ruleArray2[0] = workPart.ScRuleFactory.CreateRuleFaceDatum(faces); //featureBuilder.BooleanTool.FacePlaneTool.ToolFaces.FaceCollector.ReplaceRules(ruleArray2, false); //featureBuilder.BooleanTool.ReverseDirection = direction; NXOpen.Features.TrimBody trim = (NXOpen.Features.TrimBody)Snap.NX.Feature.CommitFeature(featureBuilder); featureBuilder.Destroy(); return(new Snap.NX.TrimBody(trim)); }
public static CartesianCoordinateSystem CreateCoordinateSystem(Point3d ori, Vector3d xVec, Vector3d yVec, Vector3d zVec) { NXOpen.Session theSession = NXOpen.Session.GetSession(); NXOpen.Part workPart = theSession.Parts.Work; Matrix3x3 mat = new Matrix3x3(); mat.Xx = xVec.X; mat.Xy = xVec.Y; mat.Xz = xVec.Z; mat.Yx = yVec.X; mat.Yy = yVec.Y; mat.Yz = yVec.Z; //Vector3d zVec = UMathUtils.VectorCross(xVec, yVec); mat.Zx = zVec.X; mat.Zy = zVec.Y; mat.Zz = zVec.Z; try { return(workPart.CoordinateSystems.CreateCoordinateSystem(ori, mat, true)); } catch (Exception ex) { LogMgr.WriteLog("BoundingBoxUtils.CreateCoordinateSystem 矩阵不是正交!" + ex.Message); CartesianCoordinateSystem cas = workPart.CoordinateSystems.CreateCoordinateSystem(ori, xVec, yVec); cas.Blank(); return(cas); } }
internal ExpressionVector(string name, Vector value) { NXOpen.Part workPart = (NXOpen.Part)Globals.WorkPart; string str = "Vector(" + value.X.ToString() + "," + value.Y.ToString() + "," + value.Z.ToString() + ")"; base.nxopenExpression = workPart.Expressions.CreateExpression("Vector", name + "=" + str.ToString()); }
public static void Main(string[] args) { NXOpen.Session theSession = NXOpen.Session.GetSession(); NXOpen.Part workPart = theSession.Parts.Work; NXOpen.Part displayPart = theSession.Parts.Display; String currentPath = ""; if (workPart != null) { try { String dirName = new FileInfo(displayPart.FullPath).Directory.FullName; Process myApp = new Process(); myApp.StartInfo.FileName = @"EXPLORER.exe"; myApp.StartInfo.Arguments = String.Format("{0}", dirName); myApp.Start(); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error...", MessageBoxButtons.OK); } } else { MessageBox.Show("No parts are open."); } }
public static void SetLineFont(DisplayType type, Font lineFontType) { PartObject.LineFontType lineFont = ConvertLineFontType((DisplayableObject.ObjectFont)lineFontType); NXOpen.Part workPart = (NXOpen.Part)WorkPart; PartObject.ObjectType type3 = (PartObject.ObjectType)type; workPart.Preferences.ObjectPreferences.SetLineFont(type3, lineFont); }
internal static Snap.NX.EdgeBlend CreateEdgeBlend(Snap.Number radius, Snap.NX.Edge[] edges) { NXOpen.Part workPart = (NXOpen.Part)Globals.WorkPart; NXOpen.Features.EdgeBlendBuilder featureBuilder = workPart.Features.CreateEdgeBlendBuilder(null); BlendLimitsData limitsListData = featureBuilder.LimitsListData; ScCollector collector = workPart.ScCollectors.CreateCollector(); NXOpen.Edge[] seedEdges = new NXOpen.Edge[edges.Length]; for (int i = 0; i < seedEdges.Length; i++) { seedEdges[i] = (NXOpen.Edge)edges[i]; } EdgeMultipleSeedTangentRule rule = workPart.ScRuleFactory.CreateRuleEdgeMultipleSeedTangent(seedEdges, Globals.AngleTolerance, true); SelectionIntentRule[] rules = new SelectionIntentRule[] { rule }; collector.ReplaceRules(rules, false); featureBuilder.Tolerance = Globals.DistanceTolerance; featureBuilder.AllInstancesOption = false; featureBuilder.RemoveSelfIntersection = true; featureBuilder.ConvexConcaveY = false; featureBuilder.RollOverSmoothEdge = true; featureBuilder.RollOntoEdge = true; featureBuilder.MoveSharpEdge = true; featureBuilder.TrimmingOption = false; featureBuilder.OverlapOption = NXOpen.Features.EdgeBlendBuilder.Overlap.AnyConvexityRollOver; featureBuilder.BlendOrder = NXOpen.Features.EdgeBlendBuilder.OrderOfBlending.ConvexFirst; featureBuilder.SetbackOption = NXOpen.Features.EdgeBlendBuilder.Setback.SeparateFromCorner; featureBuilder.AddChainset(collector, radius.ToString()); NXOpen.Features.Feature feature = (NXOpen.Features.Feature)Snap.NX.Feature.CommitFeature(featureBuilder); featureBuilder.Destroy(); return((NXOpen.Features.EdgeBlend)feature); }
internal static Snap.NX.ProjectCurve CreateProjectCurve(Snap.NX.Curve[] curves, Snap.NX.Point[] points, Snap.NX.Face face) { NXOpen.Part workPart = (NXOpen.Part)Globals.WorkPart; NXOpen.Features.ProjectCurveBuilder featureBuilder = workPart.Features.CreateProjectCurveBuilder(null); featureBuilder.CurveFitData.Tolerance = Globals.DistanceTolerance; featureBuilder.AngleToProjectionVector.RightHandSide = "0"; featureBuilder.SectionToProject.DistanceTolerance = Globals.DistanceTolerance; featureBuilder.SectionToProject.ChainingTolerance = (Globals.UnitType == Globals.Unit.Millimeter) ? 0.02413 : 0.00095; featureBuilder.SectionToProject.SetAllowedEntityTypes(NXOpen.Section.AllowTypes.CurvesAndPoints); featureBuilder.ProjectionDirectionMethod = NXOpen.Features.ProjectCurveBuilder.DirectionType.AlongFaceNormal; Snap.NX.Section sectionToProject = featureBuilder.SectionToProject; sectionToProject.AddICurve(curves); sectionToProject.AddPoints(points); ScCollector collector = workPart.ScCollectors.CreateCollector(); NXOpen.Face[] faces = new NXOpen.Face[] { face }; FaceDumbRule rule = workPart.ScRuleFactory.CreateRuleFaceDumb(faces); SelectionIntentRule[] rules = new SelectionIntentRule[] { rule }; collector.ReplaceRules(rules, false); featureBuilder.FaceToProjectTo.Add(collector); NXOpen.Features.Feature feature = (NXOpen.Features.Feature)Snap.NX.Feature.CommitFeature(featureBuilder); featureBuilder.SectionToProject.CleanMappingData(); featureBuilder.Destroy(); return((NXOpen.Features.ProjectCurve)feature); }
/// <summary> /// 创建镜像几何体 /// </summary> public static Body Geomcopy(NXOpen.Part workPart, NXOpen.Body body, NXOpen.Plane plane) { NXOpen.Features.Feature nullFeatures_Feature = null; NXOpen.Features.GeomcopyBuilder geomcopyBuilder1; geomcopyBuilder1 = workPart.Features.CreateGeomcopyBuilder(nullFeatures_Feature); //选择对象 geomcopyBuilder1.GeometryToInstance.Add(body); //选择平面 geomcopyBuilder1.MirrorPlane = plane; geomcopyBuilder1.Type = NXOpen.Features.GeomcopyBuilder.TransformTypes.Mirror; Geomcopy feature1; feature1 = geomcopyBuilder1.CommitFeature() as Geomcopy; geomcopyBuilder1.Destroy(); var b = feature1.GetBodies().FirstOrDefault(); RemoveParameters(new List <Body> { b }); return(b); }
/// <summary> /// 计算面的面积 /// </summary> /// <param name="face"></param> /// <returns></returns> public static double GetFaceArea(Face face) { NXOpen.Session theSession = NXOpen.Session.GetSession(); NXOpen.Part workPart = theSession.Parts.Work; try { Unit unit1 = workPart.UnitCollection.FindObject("SquareMilliMeter"); Unit unit2 = workPart.UnitCollection.FindObject("MilliMeter"); double accuracy = workPart.Preferences.Modeling.AngleToleranceData; IParameterizedSurface[] objects1 = new IParameterizedSurface[1]; objects1[0] = face as IParameterizedSurface; MeasureFaces measureface = workPart.MeasureManager.NewFaceProperties(unit1, unit2, accuracy, objects1); return(measureface.Area); } catch (Exception ex) { LogMgr.WriteLog("FaceUtils:GetFaceArea:" + ex.Message); } finally { } return(0); }
/// <summary> /// 设置视图线框颜色源 /// </summary> /// <param name="option"></param> /// <param name="views"></param> public static void SetWireframeColorSource(NXOpen.Preferences.GeneralWireframeColorSourceOption option, params View[] views) { NXOpen.Session theSession = NXOpen.Session.GetSession(); NXOpen.Part workPart = theSession.Parts.Work; NXOpen.Drawings.EditViewSettingsBuilder editViewSettingsBuilder1; editViewSettingsBuilder1 = workPart.SettingsManager.CreateDrawingEditViewSettingsBuilder(views); NXOpen.Drafting.BaseEditSettingsBuilder[] editsettingsbuilders1 = new NXOpen.Drafting.BaseEditSettingsBuilder[1]; editsettingsbuilders1[0] = editViewSettingsBuilder1; workPart.SettingsManager.ProcessForMultipleObjectsSettings(editsettingsbuilders1); editViewSettingsBuilder1.ViewStyle.ViewStyleGeneral.WireframeColorSource = option; editViewSettingsBuilder1.ViewStyle.ViewStyleVisibleLines.VisibleColor = workPart.Colors.Find("Background"); try { NXOpen.NXObject nXObject1; nXObject1 = editViewSettingsBuilder1.Commit(); } catch (NXException ex) { LogMgr.WriteLog("DrawingUtils:SetWireframeColorSource" + ex.Message); throw ex; } finally { editViewSettingsBuilder1.Destroy(); } }
internal static Snap.NX.FaceBlend CreateFaceBlend(Snap.NX.Face face1, Snap.NX.Face face2, Snap.Number radius) { NXOpen.Part workPart = (NXOpen.Part)Globals.WorkPart; NXOpen.Features.FaceBlendBuilder featureBuilder = workPart.Features.CreateFaceBlendBuilder(null); featureBuilder.Tolerance = Globals.DistanceTolerance; ScCollector collector = workPart.ScCollectors.CreateCollector(); NXOpen.Face[] boundaryFaces = new NXOpen.Face[0]; FaceTangentRule rule = workPart.ScRuleFactory.CreateRuleFaceTangent((NXOpen.Face)face1, boundaryFaces, 0.5); SelectionIntentRule[] rules = new SelectionIntentRule[] { rule }; collector.ReplaceRules(rules, false); featureBuilder.FirstFaceCollector = collector; featureBuilder.ReverseFirstFaceNormal = true; ScCollector collector2 = workPart.ScCollectors.CreateCollector(); NXOpen.Face[] faceArray2 = new NXOpen.Face[0]; FaceTangentRule rule2 = workPart.ScRuleFactory.CreateRuleFaceTangent((NXOpen.Face)face2, faceArray2, 0.5); SelectionIntentRule[] ruleArray2 = new SelectionIntentRule[] { rule2 }; collector2.ReplaceRules(ruleArray2, false); featureBuilder.SecondFaceCollector = collector2; featureBuilder.ReverseSecondFaceNormal = true; featureBuilder.CircularCrossSection.SetRadius(radius.ToString()); NXOpen.Features.Feature feature = (NXOpen.Features.Feature)Snap.NX.Feature.CommitFeature(featureBuilder); featureBuilder.Destroy(); return((NXOpen.Features.FaceBlend)feature); }
internal static Snap.NX.SplitBody CreateSplitBody(Snap.NX.Body targetBody, Snap.NX.Face[] toolFaces) { NXOpen.Part work = Globals.Session.Parts.Work; NXOpen.Features.SplitBodyBuilder featureBuilder = work.Features.CreateSplitBodyBuilder(null); featureBuilder.BooleanTool.ExtrudeRevolveTool.ToolSection.PrepareMappingData(); featureBuilder.BooleanTool.ExtrudeRevolveTool.ToolSection.DistanceTolerance = Globals.DistanceTolerance; featureBuilder.BooleanTool.ExtrudeRevolveTool.ToolSection.ChainingTolerance = (Globals.UnitType == Globals.Unit.Millimeter) ? 0.02413 : 0.00095; ScCollector collector = work.ScCollectors.CreateCollector(); NXOpen.Body[] bodies = new NXOpen.Body[] { targetBody }; BodyDumbRule rule = work.ScRuleFactory.CreateRuleBodyDumb(bodies); SelectionIntentRule[] rules = new SelectionIntentRule[] { rule }; collector.ReplaceRules(rules, false); featureBuilder.TargetBodyCollector = collector; SelectionIntentRule[] ruleArray2 = new SelectionIntentRule[toolFaces.Length]; for (int i = 0; i < toolFaces.Length; i++) { ruleArray2[i] = work.ScRuleFactory.CreateRuleFaceBody((NXOpen.Body)toolFaces[i].Body); } featureBuilder.BooleanTool.FacePlaneTool.ToolFaces.FaceCollector.ReplaceRules(ruleArray2, false); NXOpen.Features.SplitBody split = (NXOpen.Features.SplitBody)Snap.NX.Feature.CommitFeature(featureBuilder); featureBuilder.Destroy(); return(new Snap.NX.SplitBody(split)); }
public static void SetLineWidth(DisplayType type, Width widthType) { PartObject.WidthType width = ConvertLineWidthType((DisplayableObject.ObjectWidth)widthType); NXOpen.Part workPart = (NXOpen.Part)WorkPart; PartObject.ObjectType type3 = (PartObject.ObjectType)type; workPart.Preferences.ObjectPreferences.SetWidth(type3, width); }
internal static Snap.NX.Chamfer CreateChamfer(Snap.NX.Edge edge, Snap.Number distance1, Snap.Number distance2, bool offsetFaces) { NXOpen.Part workPart = (NXOpen.Part)Globals.WorkPart; NXOpen.Features.ChamferBuilder featureBuilder = workPart.Features.CreateChamferBuilder(null); featureBuilder.Option = NXOpen.Features.ChamferBuilder.ChamferOption.TwoOffsets; if (offsetFaces) { featureBuilder.Method = NXOpen.Features.ChamferBuilder.OffsetMethod.FacesAndTrim; } else { featureBuilder.Method = NXOpen.Features.ChamferBuilder.OffsetMethod.EdgesAlongFaces; } featureBuilder.FirstOffset = distance1.ToString(); featureBuilder.SecondOffset = distance2.ToString(); //featureBuilder.Tolerance = Globals.DistanceTolerance; ScCollector collector = workPart.ScCollectors.CreateCollector(); EdgeTangentRule rule = workPart.ScRuleFactory.CreateRuleEdgeTangent((NXOpen.Edge)edge, null, false, Globals.AngleTolerance, false, false); SelectionIntentRule[] rules = new SelectionIntentRule[] { rule }; collector.ReplaceRules(rules, false); featureBuilder.SmartCollector = collector; NXOpen.Features.Feature feature = (NXOpen.Features.Feature)Snap.NX.Feature.CommitFeature(featureBuilder); featureBuilder.Destroy(); return((NXOpen.Features.Chamfer)feature); }
public static void Main(string[] args) { NXOpen.Session theSession = NXOpen.Session.GetSession(); NXOpen.Part workPart = theSession.Parts.Work; NXOpen.Part displayPart = theSession.Parts.Display; String currentPath = ""; try { String dirName = new FileInfo(displayPart.FullPath).Directory.FullName; String fileName = Path.GetFileNameWithoutExtension(displayPart.FullPath); String sourceFile = @"L:\IevgenZ\template\PM_validation_template.docx"; String destFile = dirName + "\\" + fileName + ".docx"; //MessageBox.Show(destFile + " - exists: " + System.IO.Directory.Exists(destFile).ToString()); //Boolean DirectoryExists = new DirectoryInfo(destFile).Exists; Boolean DirectoryExists = System.IO.File.Exists(destFile); //MessageBox.Show(destFile + " - exists: " + DirectoryExists.ToString()); if (!DirectoryExists) { System.IO.File.Copy(sourceFile, destFile, false); // Copy, do not overwrite } System.Diagnostics.Process.Start(String.Format(@"{0}", destFile)); // Open file } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error...", MessageBoxButtons.OK); } }
internal static NXOpen.Point CreatePointInvisible(double x, double y, double z) { NXOpen.Part workPart = (NXOpen.Part)Globals.WorkPart; Point3d coordinates = new Point3d(x, y, z); NXOpen.Point point = workPart.Points.CreatePoint(coordinates); point.SetVisibility(SmartObject.VisibilityOption.Invisible); return(point); }
new public static Element FromElementId(DB.Part doc, DB.Tag Id) { if (doc?.GetElement(Id ?? DB.Tag.Null) is DB.TaggedObject value) { return(FromElement(value)); } return(null); }
internal static Snap.NX.Ellipse CreateEllipse(Snap.Position center, Vector axisX, Vector axisY, double a, double b, double angle1, double angle2) { NXOpen.Part workPart = (NXOpen.Part)Globals.WorkPart; double num = 0.017453292519943295; angle1 *= num; angle2 *= num; return(new Snap.NX.Ellipse(workPart.Curves.CreateEllipse((Point3d)center, (Vector3d)axisX, (Vector3d)axisY, a, b, angle1, angle2))); }
public void loadAssemblyInfo(NXOpen.Part assemblyFilePart) { //Get root component which is top level assembly component rootComponent = assemblyFilePart.ComponentAssembly.RootComponent; //Get components and constraints in (root)assembly nxComponents = rootComponent.GetChildren(); //Get constraint information nxPositioner = assemblyFilePart.ComponentAssembly.Positioner; nxConstraints = nxPositioner.Constraints.ToArray(); numComponents = nxComponents.Length; tcad_PartList = new TransCAD.Part[numComponents]; componentPositions = new Point3d[numComponents]; componentOrientations = new Matrix3x3[numComponents]; nxCompNames = new string[numComponents]; for (int i = 0; i < numComponents; i++) { NXOpen.Assemblies.Component nxComponent = nxComponents[i]; //save name of NX Part into string array nxCompNames[i] = nxComponent.DisplayName; //Get position and orientation of each part and save them into componentPositions, componentOrientations Point3d componentPosition; Matrix3x3 componentOrientation; nxComponent.GetPosition(out componentPosition, out componentOrientation); componentPositions[i] = componentPosition; componentOrientations[i] = componentOrientation; //Get file directory of each part in assembly NXOpen.Part nxPart = null; nxPart = (Part)nxComponent.Prototype; string xmlPartDir = Path.ChangeExtension(nxPart.FullPath, ".xml"); //chaneg extension from .prt to .xml //Load transCAD xml part file corresponding to each NX part using file name, the transCAD xml should be in same folder with same name except extension(.prt -> .xml) TransCAD.Part tcad_Part = tComp.CreatePart(nxComponent.DisplayName); tcad_Part = tComp.ImportPartFromXML(xmlPartDir, tcad_Part); //save transCAD part data into array "tcad_PartList" tcad_PartList[i] = tcad_Part; //Place each part in TransCAD double extraDisplacement = i * 100; //To see whether constraints are applied or not, intentionally, place part with extra displacement which is different from original NX part tComp.SetPartPlacement(tcad_Part, componentPosition.X, componentPosition.Y + extraDisplacement, componentPosition.Z - extraDisplacement, componentOrientation.Zx, componentOrientation.Zy, componentOrientation.Zz, componentOrientation.Xx, componentOrientation.Xy, componentOrientation.Xz); tComp.AddPart(tcad_Part); } tAssem.AddComponent(tComp); tAssemDoc.Update(); }
internal static Snap.NX.DatumCsys CreateDatumCsys(Position origin, Snap.NX.Matrix matrix) { NXOpen.Part workPart = (NXOpen.Part)Globals.WorkPart; NXOpen.Features.DatumCsysBuilder featureBuilder = workPart.Features.CreateDatumCsysBuilder(null); Xform xform = workPart.Xforms.CreateXform((Point3d)origin, (Vector3d)matrix.AxisX, (Vector3d)matrix.AxisY, SmartObject.UpdateOption.WithinModeling, 1.0); CartesianCoordinateSystem system = workPart.CoordinateSystems.CreateCoordinateSystem(xform, SmartObject.UpdateOption.WithinModeling); featureBuilder.Csys = system; NXOpen.Features.DatumCsys datumCsys = (NXOpen.Features.DatumCsys)Snap.NX.Feature.CommitFeature(featureBuilder); featureBuilder.Destroy(); return(new Snap.NX.DatumCsys(datumCsys)); }
public static void SetColor(DisplayType type, System.Drawing.Color color) { int num = Snap.Color.ColorIndex(color); NXOpen.Part workPart = (NXOpen.Part)WorkPart; PartObject.ObjectType type2 = (PartObject.ObjectType)type; workPart.Preferences.ObjectPreferences.SetColor(type2, num); if (type == DisplayType.AllButDefault) { ColorOfAllButDefault = color; StateOfAllButDefault = true; } }
public static Snap.NX.Part Wrap(Tag nxopenPartTag) { if (nxopenPartTag == Tag.Null) { throw new ArgumentException("Input tag is NXOpen.Tag.Null"); } NXOpen.Part objectFromTag = Snap.NX.NXObject.GetObjectFromTag(nxopenPartTag) as NXOpen.Part; if (objectFromTag == null) { throw new ArgumentException("Input tag doesn't belong to an NXOpen.Part object"); } return(objectFromTag); }
internal static Snap.NX.DatumAxis CreateDatumAxis(Snap.Position startPoint, Snap.Position endPoint) { NXOpen.Part workPart = (NXOpen.Part)Globals.WorkPart; NXOpen.Features.DatumAxisBuilder featureBuilder = workPart.Features.CreateDatumAxisBuilder(null); featureBuilder.Type = NXOpen.Features.DatumAxisBuilder.Types.TwoPoints; featureBuilder.IsAssociative = true; featureBuilder.IsAxisReversed = false; featureBuilder.Point1 = workPart.Points.CreatePoint((Point3d)startPoint); featureBuilder.Point2 = workPart.Points.CreatePoint((Point3d)endPoint); NXOpen.Features.Feature feature = (NXOpen.Features.Feature)Snap.NX.Feature.CommitFeature(featureBuilder); featureBuilder.Destroy(); return(new Snap.NX.DatumAxis((DatumAxisFeature)feature)); }
internal static Snap.NX.Ellipse CreateEllipse(Snap.Position center, Vector axisX, Vector axisY, double rotationAngle, double a, double b, double angle1, double angle2) { NXOpen.Part workPart = (NXOpen.Part)Globals.WorkPart; double num = 0.017453292519943295; angle1 *= num; angle2 *= num; rotationAngle *= num; Vector axisZ = Vector.UnitCross(axisX, axisY); Snap.NX.Matrix matrix = Snap.NX.Matrix.CreateMatrix(axisX, axisY, axisZ); return(new Snap.NX.Ellipse(workPart.Curves.CreateEllipse((Point3d)center, a, b, angle1, angle2, rotationAngle, (NXMatrix)matrix))); }
internal static Snap.NX.DatumAxis CreateDatumAxis(Snap.Position origin, Vector direction) { NXOpen.Part workPart = (NXOpen.Part)Globals.WorkPart; NXOpen.Features.DatumAxisBuilder featureBuilder = workPart.Features.CreateDatumAxisBuilder(null); featureBuilder.Type = NXOpen.Features.DatumAxisBuilder.Types.PointAndDir; NXOpen.Direction direction2 = workPart.Directions.CreateDirection((Point3d)origin, (Vector3d)direction, SmartObject.UpdateOption.WithinModeling); featureBuilder.IsAssociative = true; featureBuilder.IsAxisReversed = false; featureBuilder.Vector = direction2; featureBuilder.Point = workPart.Points.CreatePoint((Point3d)origin); NXOpen.Features.Feature feature = (NXOpen.Features.Feature)Snap.NX.Feature.CommitFeature(featureBuilder); featureBuilder.Destroy(); return(new Snap.NX.DatumAxis((DatumAxisFeature)feature)); }