コード例 #1
0
    static void setANTOrderAndSaveAllLevels(BasePart thePart)
    {
        NXOpen.Assemblies.Component root = thePart.ComponentAssembly.RootComponent;
        if (root == null)
        {
            return;
        }

        PartLoadStatus loadStatus;

        theSession.Parts.SetDisplay(thePart, false, true, out loadStatus);
        reportPartLoadStatus(loadStatus);

        NXOpen.Assemblies.ComponentOrder componentOrder1 =
            (NXOpen.Assemblies.ComponentOrder)
            thePart.ComponentAssembly.OrdersSet.FindObject("Alphabetic");
        componentOrder1.Activate();

        thePart.Save(BasePart.SaveComponents.False, BasePart.CloseAfterSave.False);

        foreach (NXOpen.Assemblies.Component kid in root.GetChildren())
        {
            setANTOrderAndSaveAllLevels((BasePart)kid.Prototype);
        }
    }
コード例 #2
0
        /// <summary>
        /// 替换电极图纸
        /// </summary>
        /// <param name="oldParenInfo"></param>
        /// <param name="newParenInfo"></param>
        /// <returns></returns>
        public List <string> AlterEleDra(ParentAssmblieInfo oldParenInfo, ParentAssmblieInfo newParenInfo)
        {
            List <string> err          = new List <string>();
            UFSession     theUFSession = UFSession.GetUFSession();
            Part          workPart     = Session.GetSession().Parts.Work;
            string        oldDra       = directoryPath + oldNameInfo.EleName + "_dwg.prt";

            if (!File.Exists(oldDra))
            {
                return(err);
            }
            string newDra = directoryPath + newNameInfo.EleName + "_dwg.prt";

            if (File.Exists(newDra))
            {
                err.Add(newNameInfo.EleName + "            替换失败,替换后有同名工件!          ");
                return(err);
            }
            else
            {
                foreach (Part pt in Session.GetSession().Parts)
                {
                    if (pt.Name.Equals(oldNameInfo.EleName + "_dwg", StringComparison.CurrentCultureIgnoreCase))
                    {
                        pt.Close(NXOpen.BasePart.CloseWholeTree.False, NXOpen.BasePart.CloseModified.UseResponses, null);
                    }
                }
                File.Move(oldDra, newDra);
                Tag partTag;
                UFPart.LoadStatus error_status;
                theUFSession.Part.Open(newDra, out partTag, out error_status);
                Part newPart = NXObjectManager.Get(partTag) as Part;

                PartUtils.SetPartDisplay(newPart);
                NXOpen.Assemblies.Component comp = newPart.ComponentAssembly.RootComponent.GetChildren()[0];
                string workName = comp.Name.Replace(oldParenInfo.MoldInfo.MoldNumber + "-" + oldParenInfo.MoldInfo.WorkpieceNumber, newParenInfo.MoldInfo.MoldNumber + "-" + newParenInfo.MoldInfo.WorkpieceNumber);
                try
                {
                    Basic.AssmbliesUtils.ReplaceComp(comp, this.directoryPath + workName + ".prt", workName);
                }
                catch
                {
                }
                if (newPart != null)
                {
                    newNameInfo.SetAttribute(newPart);
                    ParentAssmblieInfo info = ParentAssmblieInfo.GetAttribute(newPart);
                    info.MoldInfo  = newParenInfo.MoldInfo;
                    info.UserModel = newParenInfo.UserModel;
                    info.SetAttribute(newPart);
                    foreach (DrawingSheet st in newPart.DrawingSheets)
                    {
                        Basic.DrawingUtils.UpdateViews(st);
                    }
                }
                PartUtils.SetPartDisplay(workPart);
                err.Add(newNameInfo.EleName + "           图纸替换成功!          ");
                return(err);
            }
        }
コード例 #3
0
ファイル: ComponentEx.cs プロジェクト: zcstkhk/RhinoInside.NX
        /// <summary>
        /// 绕旋转轴旋转组件
        /// </summary>
        /// <param name="componentToRotate"></param>
        /// <param name="rotateOrigin"></param>
        /// <param name="rotateVector"></param>
        /// <param name="rotateAngle"></param>
        /// <param name="copyOriginal"></param>
        public static Component RotateComponent(this NXOpen.Assemblies.Component componentToRotate, Point3d rotateOrigin, Vector3d rotateVector, double rotateAngle, bool copyOriginal = false)
        {
            componentToRotate.GetPosition(out Point3d componentOrigin, out Matrix3x3 orientation);
            if (copyOriginal)
            {
                componentToRotate = WorkPart.ComponentAssembly.AddComponent(componentToRotate.Prototype as Part, componentOrigin, orientation);
            }

            double[] rotateMtx = new double[9];
            TheUfSession.Mtx3.RotateAboutAxis(rotateVector.ToArray(), (rotateAngle * Math.PI) / 180, rotateMtx);

            var orientationInDouble = orientation.ToArray();

            double[] xVec = new double[3];
            double[] yVec = new double[3];
            double[] zVec = new double[3];
            TheUfSession.Mtx3.XVec(orientationInDouble, xVec);
            TheUfSession.Mtx3.YVec(orientationInDouble, yVec);
            TheUfSession.Mtx3.ZVec(orientationInDouble, zVec);

            TheUfSession.Mtx3.VecMultiply(xVec, rotateMtx, xVec);
            TheUfSession.Mtx3.VecMultiply(yVec, rotateMtx, yVec);
            TheUfSession.Mtx3.VecMultiply(zVec, rotateMtx, zVec);

            double[] rotatedOrientation = new double[9];
            TheUfSession.Mtx3.Initialize(xVec, yVec, rotatedOrientation);

            var rotatedOrigin = componentOrigin.Rotate(rotateOrigin, rotateVector, rotateAngle);

            TheUfSession.Assem.RepositionInstance(TheUfSession.Assem.AskInstOfPartOcc(componentToRotate.Tag), rotatedOrigin.ToArray(), rotatedOrientation);

            return(componentToRotate);
        }
コード例 #4
0
        /// <summary>
        /// 设置连接体
        /// </summary>
        public void WaveBodys()
        {
            Part      workPart     = Session.GetSession().Parts.Work;
            UFSession theUFSession = UFSession.GetUFSession();

            if (workPart.Tag != this.PartTag.Tag)
            {
                NXOpen.Assemblies.Component ct = AssmbliesUtils.GetPartComp(workPart, this.PartTag);
                PartUtils.SetPartWork(ct);
            }
            foreach (Part part in Session.GetSession().Parts)
            {
                string type = AttributeUtils.GetAttrForString(part, "PartType");
                if (type.Equals("Workpiece"))
                {
                    Body[] bodys = part.Bodies.ToArray();
                    NXOpen.Features.Feature feat = AssmbliesUtils.WaveAssociativeBodys(bodys);
                    Body[] waveBodys             = ((NXOpen.Features.BodyFeature)feat).GetBodies();
                    foreach (Body body in waveBodys)
                    {
                        body.Layer = 2;
                        theUFSession.Layer.SetStatus(2, 2);
                    }
                    break;
                }
            }
            PartUtils.SetPartWork(null);
        }
コード例 #5
0
        /// <summary>
        /// 获取work
        /// </summary>
        /// <param name="model"></param>
        /// <param name="asmPart"></param>
        /// <returns></returns>
        private WorkModel GetWorkModel(ElectrodeModel model)
        {
            List <NXOpen.Assemblies.Component> eleComs = AssmbliesUtils.GetPartComp(this.asmPart, model.PartTag);
            List <WorkModel> works = new List <WorkModel>();

            foreach (NXOpen.Assemblies.Component ct in eleComs)
            {
                NXOpen.Assemblies.Component parent = ct.Parent;
                if (parent != null)
                {
                    Part pt = parent.Prototype as Part;
                    if (WorkModel.IsWork(pt) && !works.Exists(a => a.PartTag.Equals(pt)) && ParentAssmblieInfo.GetAttribute(pt).MoldInfo.Equals(model.Info.MoldInfo))
                    {
                        works.Add(new WorkModel(pt));
                    }
                }
            }
            works.Sort();
            if (works.Count != 0)
            {
                return(works[0]);
            }
            else
            {
                return(null);
            }
        }
コード例 #6
0
        public static bool CreateNewEmptyComp(string comp_path, out NXOpen.Assemblies.Component component, string TemplateFileName = "model-plain-1-mm-template.prt", string ReferenceSetName = "Entire Part")
        {
            try
            {
                Session theSession  = Session.GetSession();
                Part    workPart    = theSession.Parts.Work;
                Part    displayPart = theSession.Parts.Display;
                // ----------------------------------------------
                //   Menu: Assemblies->Components->Create New Component...
                // ----------------------------------------------
                FileNew fileNew1;
                fileNew1 = theSession.Parts.FileNew();
                fileNew1.TemplateFileName = TemplateFileName;
                fileNew1.Application      = FileNewApplication.Modeling;
                fileNew1.Units            = NXOpen.Part.Units.Millimeters;
                //fileNew1.TemplateType = FileNewTemplateType.Item;
                fileNew1.NewFileName       = comp_path;
                fileNew1.MasterFileName    = "";
                fileNew1.UseBlankTemplate  = false;
                fileNew1.MakeDisplayedPart = false;
                string newNameNoExt = "";
                newNameNoExt = Path.GetFileNameWithoutExtension(comp_path);
                string newNameNoExtUpper = "";
                newNameNoExtUpper = newNameNoExt.ToUpper();

                NXOpen.Assemblies.CreateNewComponentBuilder createNewComponentBuilder1;

                createNewComponentBuilder1 = workPart.AssemblyManager.CreateNewComponentBuilder();

                createNewComponentBuilder1.NewComponentName = newNameNoExtUpper;

                createNewComponentBuilder1.ReferenceSet = NXOpen.Assemblies.CreateNewComponentBuilder.ComponentReferenceSetType.EntirePartOnly;

                createNewComponentBuilder1.ReferenceSetName = ReferenceSetName;

                // ----------------------------------------------
                //   Dialog Begin Create New Component
                // ----------------------------------------------
                createNewComponentBuilder1.ReferenceSet = NXOpen.Assemblies.CreateNewComponentBuilder.ComponentReferenceSetType.Model;
                createNewComponentBuilder1.NewFile      = fileNew1;
                NXObject nXObject1;
                nXObject1 = createNewComponentBuilder1.Commit();

                component = (NXOpen.Assemblies.Component)nXObject1;

                //UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Information, component.Name);


                createNewComponentBuilder1.Destroy();
            }
            catch (System.Exception ex)
            {
                CaxLog.ShowListingWindow(ex.ToString());
                component = null;
                return(false);
            }

            return(true);
        }
コード例 #7
0
ファイル: ComponentEx.cs プロジェクト: zcstkhk/RhinoInside.NX
        /// <summary>
        /// 获取组件的位置矩阵,该矩阵中包含方位与原点
        /// </summary>
        /// <param name="component"></param>
        /// <returns></returns>
        public static Matrix4x4 GetPosition(this NXOpen.Assemblies.Component component)
        {
            Point3d   point;
            Matrix3x3 matrix;

            component.GetPosition(out point, out matrix);
            Matrix4x4 result = Matrix4x4Ex.Create(point, matrix);

            return(result);
        }
コード例 #8
0
        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();
        }
コード例 #9
0
        /// <summary>
        /// 创建装配
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public NXOpen.Assemblies.Component CreateCompPart()
        {
            CsysUtils.SetWcsOfCenteAndMatr(this.CenterPt, this.EleMatr.GetMatrix3());
            NXObject obj = AssmbliesUtils.CreateNew(this.AssembleName, WorkpiecePath);

            NXOpen.Assemblies.Component comp = obj as NXOpen.Assemblies.Component;
            this.PartTag = obj.Prototype as Part;
            SetAttribute();
            CsysUtils.SetWcsToAbs();
            return(comp);
        }
コード例 #10
0
ファイル: ComponentEx.cs プロジェクト: zcstkhk/RhinoInside.NX
 /// <summary>
 /// 查询组件原型部件的名称
 /// </summary>
 /// <param name="component"></param>
 /// <returns></returns>
 public static string GetPrototypeName(this NXOpen.Assemblies.Component component)
 {
     try
     {
         return(component.GetStringUserAttribute("DB_PART_NAME", -1));
     }
     catch (Exception)
     {
         return(component.DisplayName);
     }
 }
コード例 #11
0
 public static Snap.NX.Component Wrap(Tag nxopenComponentTag)
 {
     if (nxopenComponentTag == Tag.Null)
     {
         throw new ArgumentException("Input tag is NXOpen.Tag.Null");
     }
     NXOpen.Assemblies.Component objectFromTag = Snap.NX.NXObject.GetObjectFromTag(nxopenComponentTag) as NXOpen.Assemblies.Component;
     if (objectFromTag == null)
     {
         throw new ArgumentException("Input tag doesn't belong to an NXOpen.Assemblies.Component object");
     }
     return(objectFromTag);
 }
コード例 #12
0
ファイル: ComponentEx.cs プロジェクト: zcstkhk/RhinoInside.NX
        /// <summary>
        /// 判断组件内是否含有体
        /// </summary>
        /// <param name="component"></param>
        /// <returns></returns>
        public static bool ContainsBody(this NXOpen.Assemblies.Component component)
        {
            var prototyBodies = (component.Prototype as Part).Bodies.ToArray();

            if (prototyBodies.Length != 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #13
0
        /// <summary>
        /// 画中心点和中心线
        /// </summary>
        /// <param name="disPt"></param>
        public void CreatePointAndCenterLine(Point3d centerPt, Point3d disPt)
        {
            Part workPart = Session.GetSession().Parts.Work;

            if (workPart.Tag != PartTag.Tag)
            {
                NXOpen.Assemblies.Component ct = AssmbliesUtils.GetPartComp(workPart, PartTag);
                PartUtils.SetPartWork(ct);
            }
            CreateCenterLine(centerPt, disPt);
            CreateCenterPoint();
            PartUtils.SetPartWork(null);
        }
コード例 #14
0
        public static bool SetWorkComponent(NXOpen.Assemblies.Component component)
        {
            try
            {
                NXOpen.Assemblies.Component component1 = component;
                PartLoadStatus partLoadStatus1;
                theSession.Parts.SetWorkComponent(component1, out partLoadStatus1);
                partLoadStatus1.Dispose();
            }
            catch (System.Exception ex)
            {
                return(false);
            }

            return(true);
        }
コード例 #15
0
ファイル: ComponentEx.cs プロジェクト: zcstkhk/RhinoInside.NX
        /// <summary>
        /// 移动组件
        /// </summary>
        /// <param name="componentToMove">要移动的组件</param>
        /// <param name="vector"></param>
        /// <param name="distance"></param>
        /// <param name="copyOriginal"></param>
        public static Component MoveComponent(this NXOpen.Assemblies.Component componentToMove, Vector3d vector, double distance, bool copyOriginal = false)
        {
            componentToMove.GetPosition(out Point3d componentOrigin, out Matrix3x3 orientation);

            if (copyOriginal)
            {
                componentToMove = WorkPart.ComponentAssembly.AddComponent(componentToMove.Prototype as Part, componentOrigin, orientation);
            }

            var orientationInDouble = orientation.ToArray();

            componentOrigin = componentOrigin.Move(vector, distance);

            TheUfSession.Assem.RepositionInstance(TheUfSession.Assem.AskInstOfPartOcc(componentToMove.Tag), componentOrigin.ToArray(), orientation.ToArray());

            return(componentToMove);
        }
コード例 #16
0
 /// <summary>
 /// 取得子Comp集合(遞迴搜尋)
 /// </summary>
 /// <param name="FatherComp"></param>
 /// <param name="ListChildrenComp"></param>
 /// <returns></returns>
 public static bool GetCompChildren(NXOpen.Assemblies.Component FatherComp, ref List <NXOpen.Assemblies.Component> ListChildrenComp)
 {
     try
     {
         NXOpen.Assemblies.Component[] ChildrenCompAry = FatherComp.GetChildren();
         ListChildrenComp.AddRange(ChildrenCompAry.ToArray());
         foreach (NXOpen.Assemblies.Component i in ChildrenCompAry)
         {
             GetCompChildren(i, ref ListChildrenComp);
         }
     }
     catch (System.Exception ex)
     {
         return(false);
     }
     return(true);
 }
コード例 #17
0
ファイル: ComponentEx.cs プロジェクト: zcstkhk/RhinoInside.NX
        /// <summary>
        /// 获取组件内某一类型的所有对象,如果无法获取,可能需要先更改引用集
        /// </summary>
        /// <typeparam name="T">类型名</typeparam>
        /// <param name="component">要获取对象的组件</param>
        /// <param name="GetObjectsInPart">获取对象集合的方法</param>
        /// <returns></returns>
        public static List <T> GetObjects <T>(this NXOpen.Assemblies.Component component, Func <Part, TaggedObjectCollection> GetObjectsInPart) where T : TaggedObject
        {
            if (!(component.Prototype is Part))
            {
                DisplayPart.ComponentAssembly.OpenComponents(ComponentAssembly.OpenOption.ComponentOnly, new Component[] { component }, out ComponentAssembly.OpenComponentStatus[] openCompStatus);
            }

            var originalRefSet = component.ReferenceSet;

            if (originalRefSet != component.EntirePartRefsetName)
            {
                WorkPart.ComponentAssembly.ReplaceReferenceSetInOwners(component.EntirePartRefsetName, new Component[] { component });  // 没有设置引用集时,可能会查找不到某些对象
            }
            Part prototypePart = component.Prototype as Part;
            TaggedObjectCollection prototyObjects = GetObjectsInPart(prototypePart);

            List <T> prototyObjectList = prototyObjects.Cast <TaggedObject>().Where(obj => obj is T).Select(obj => obj as T).ToList();

            if (originalRefSet != component.EntirePartRefsetName)
            {
                WorkPart.ComponentAssembly.ReplaceReferenceSetInOwners(originalRefSet, new Component[] { component });
            }

            if (component == DisplayPart.ComponentAssembly.RootComponent)
            {
                return(prototyObjectList);
            }
            else
            {
                List <T> resultObjects = new List <T>();
                foreach (var obj in prototyObjectList)
                {
                    Tag tagObj = TheUfSession.Assem.FindOccurrence(component.Tag, obj.Tag);
                    if (tagObj != Tag.Null)
                    {
                        resultObjects.Add(tagObj.GetTaggedObject() as T);
                    }
                }

                return(resultObjects);
            }
        }
コード例 #18
0
        //------------------------------------------------------------------------------
        //Callback Name: filter_cb
        //------------------------------------------------------------------------------
        public int filter_cb(NXOpen.BlockStyler.UIBlock block, NXOpen.TaggedObject selectedObject)
        {
            NXOpen.Assemblies.Component ct = selectedObject as Component;
            Component workPartCt           = workPart.ComponentAssembly.RootComponent;

            if (ct != null)
            {
                if (ct.Parent.Equals(workPartCt))
                {
                    return(NXOpen.UF.UFConstants.UF_UI_SEL_ACCEPT);
                }
                else
                {
                    return(NXOpen.UF.UFConstants.UF_UI_SEL_FAILURE);
                }
            }
            else
            {
                return(NXOpen.UF.UFConstants.UF_UI_SEL_ACCEPT);
            }
        }
コード例 #19
0
ファイル: ComponentEx.cs プロジェクト: zcstkhk/RhinoInside.NX
        /// <summary>
        /// 通过名称获取组件中的对象
        /// </summary>
        /// <param name="component"></param>
        /// <param name="objName"></param>
        /// <returns></returns>
        public static List <TaggedObject> GetObjectsByName(this NXOpen.Assemblies.Component component, string objName)
        {
            List <TaggedObject> namedObjects = new List <TaggedObject>();

            var originalRefSet = component.ReferenceSet;

            if (originalRefSet != component.EntirePartRefsetName)
            {
                WorkPart.ComponentAssembly.ReplaceReferenceSet(component, component.EntirePartRefsetName);  // 没有设置引用集时,可能会查找不到某些对象
            }
            Tag startTag = Tag.Null;

            do
            {
                TheUfSession.Obj.CycleByName(objName, ref startTag);

                if (startTag != Tag.Null)
                {
                    var partOcc = TheUfSession.Assem.AskPartOccurrence(startTag);

                    var taggedObj = startTag.GetTaggedObject();

                    if (partOcc == component.Tag)
                    {
                        namedObjects.Add(startTag.GetTaggedObject());
                    }
                }
                else
                {
                    break;
                }
            } while (true);

            if (originalRefSet != component.EntirePartRefsetName)
            {
                WorkPart.ComponentAssembly.ReplaceReferenceSet(component, originalRefSet);
            }

            return(namedObjects);
        }
コード例 #20
0
        /// <summary>
        /// 获取Comp下设定点
        /// </summary>
        /// <returns></returns>
        public List <Point> GetEleCompPint()
        {
            List <Point> eleCompPoints = new List <Point>();

            foreach (ElectrodeModel ele in Eles)
            {
                Point elePt = null;
                foreach (Point pt in ele.PartTag.Points)
                {
                    if (pt.Name.ToUpper().Equals("SetValuePoint".ToUpper()))
                    {
                        elePt = pt;
                    }
                }
                if (elePt != null)
                {
                    NXOpen.Assemblies.Component ct = AssmbliesUtils.GetPartComp(this.PartTag, ele.PartTag);
                    eleCompPoints.Add(AssmbliesUtils.GetNXObjectOfOcc(ct.Tag, elePt.Tag) as Point);
                }
            }
            return(eleCompPoints);
        }
コード例 #21
0
 /// <summary>
 /// 创建装配
 /// </summary>
 /// <param name="filePath"></param>
 /// <returns></returns>
 public NXOpen.Assemblies.Component CreateCompPart(string directoryPath)
 {
     this.WorkpieceDirectoryPath = directoryPath;
     this.WorkpiecePath          = directoryPath + this.AssembleName + ".prt";
     CsysUtils.SetWcsToAbs();
     CsysUtils.SetWcsOfCenteAndMatr(this.Info.Matr.GetCenter(), this.Info.Matr.GetMatrix3());
     try
     {
         NXObject obj = AssmbliesUtils.CreateNew(this.AssembleName, WorkpiecePath);
         NXOpen.Assemblies.Component comp = obj as NXOpen.Assemblies.Component;
         this.PartTag = obj.Prototype as Part;
         if (this.PartTag != null)
         {
             SetAttribute(this.PartTag);
         }
         CsysUtils.SetWcsToAbs();
         return(comp);
     }
     catch (NXException ex)
     {
         ClassItem.WriteLogFile("创建装配档错误!" + ex.Message);
         throw ex;
     }
 }
コード例 #22
0
        /// <summary>
        /// 创建间隙分析
        /// </summary>
        /// <param name="setName">间隙分析名字</param>
        /// <param name="oneObjects">第一个工件</param>
        /// <param name="twoObjects">等二个工件</param>
        /// <returns></returns>
        public static ClearanceSet CreateClearanceAnalysis(string setName, NXOpen.Assemblies.Component oneObjects, params Component[] twoObjects)
        {
            Part workPart = Session.GetSession().Parts.Work;

            NXOpen.Assemblies.ClearanceSet             nullNXOpen_Assemblies_ClearanceSet = null;
            NXOpen.Assemblies.ClearanceAnalysisBuilder clearanceAnalysisBuilder1;
            clearanceAnalysisBuilder1 = workPart.AssemblyManager.CreateClearanceAnalysisBuilder(nullNXOpen_Assemblies_ClearanceSet);
            clearanceAnalysisBuilder1.CalculationMethod           = NXOpen.Assemblies.ClearanceAnalysisBuilder.CalculationMethodType.ExactifLoaded;
            clearanceAnalysisBuilder1.ClearanceSetName            = setName;
            clearanceAnalysisBuilder1.TotalCollectionCount        = NXOpen.Assemblies.ClearanceAnalysisBuilder.NumberOfCollections.Two;
            clearanceAnalysisBuilder1.CollectionOneRange          = NXOpen.Assemblies.ClearanceAnalysisBuilder.CollectionRange.SelectedObjects;
            clearanceAnalysisBuilder1.CollectionTwoRange          = NXOpen.Assemblies.ClearanceAnalysisBuilder.CollectionRange.SelectedObjects;
            clearanceAnalysisBuilder1.ClearanceBetween            = NXOpen.Assemblies.ClearanceAnalysisBuilder.ClearanceBetweenEntity.Components;
            clearanceAnalysisBuilder1.SaveInterferenceGeometry    = true;
            clearanceAnalysisBuilder1.IsCalculatePenetrationDepth = true;
            bool added1;

            added1 = clearanceAnalysisBuilder1.CollectionOneObjects.Add(oneObjects);
            bool added2;

            added2 = clearanceAnalysisBuilder1.CollectionTwoObjects.Add(twoObjects);

            try
            {
                return(clearanceAnalysisBuilder1.Commit() as ClearanceSet);
            }
            catch (NXException ex)
            {
                LogMgr.WriteLog("ClearanceAnalysisUtils.CreateClearanceAnalysis" + ex.Message);
                return(null);
            }
            finally
            {
                clearanceAnalysisBuilder1.Destroy();
            }
        }
コード例 #23
0
        public void ToNXFile(Session nxSession)
        {
            NXOpen.Part nxSubAssem;
            var         newFile = new NewNXfile();
            var         fileDir = new NewNXfile();

            for (int i = 0; i < compCount; i++)
            {
                nxRootAssem = nxSession.Parts.Work;
                if (compName[i] == "Default SubAssembly")
                {
                    continue;
                }
                NXOpen.FileNew compFile = nxSession.Parts.FileNew();
                newFile.NXfile(compFile, fileDir.subassemdir(compName[i]));
                compFile.MakeDisplayedPart = false;
                NXOpen.Assemblies.CreateNewComponentBuilder createNewComponentBuilder1;
                createNewComponentBuilder1 = nxRootAssem.AssemblyManager.CreateNewComponentBuilder();
                createNewComponentBuilder1.NewComponentName = compName[i];
                createNewComponentBuilder1.ReferenceSet     = NXOpen.Assemblies.CreateNewComponentBuilder.ComponentReferenceSetType.EntirePartOnly;
                createNewComponentBuilder1.ReferenceSetName = "Entire Part";
                createNewComponentBuilder1.NewFile          = compFile;
                NXOpen.NXObject nXObject_SubAssem = createNewComponentBuilder1.Commit();
                createNewComponentBuilder1.Destroy();
                nxSubAssem = (NXOpen.Part)nxSession.Parts.FindObject(compName[i]);
                NXObject[] nxGeom = new NXObject[partCount];
                for (int j = 0; j < partCount; j++)
                {
                    NXOpen.BasePart       basePart1;
                    NXOpen.PartLoadStatus partLoadStatus, partLoadStatus2;
                    basePart1 = nxSession.Parts.OpenBase(fileDir.partdir(partFileName[j]), out partLoadStatus);
                    partLoadStatus.Dispose();
                    basepoint1      = new NXOpen.Point3d(0.0, 0.0, 0.0);
                    orientation1    = new NXOpen.Matrix3x3();
                    orientation1.Xx = 1.0;
                    orientation1.Xy = 0.0;
                    orientation1.Xz = 0.0;
                    orientation1.Yx = 0.0;
                    orientation1.Yy = 1.0;
                    orientation1.Yz = 0.0;
                    orientation1.Zx = 0.0;
                    orientation1.Zy = 0.0;
                    orientation1.Zz = 1.0;
                    NXOpen.Assemblies.Component component1;
                    component1 = nxRootAssem.ComponentAssembly.AddComponent(fileDir.partdir(partFileName[j]), "MODEL", "A1-1", basepoint1, orientation1, -1, out partLoadStatus2, true);
                    partLoadStatus2.Dispose();
                    NXOpen.Assemblies.Component[] origComponents1 = new NXOpen.Assemblies.Component[1];
                    origComponents1[0] = component1;
                    NXOpen.Assemblies.Component   component2 = (NXOpen.Assemblies.Component)nXObject_SubAssem;
                    NXOpen.Assemblies.Component[] newComponents1;
                    NXOpen.ErrorList errorList1;
                    nxSubAssem.ComponentAssembly.RestructureComponents(origComponents1, component2, true, out newComponents1, out errorList1);
                    errorList1.Dispose();
                    nxGeom[i] = origComponents1[0];
                    string reef = nxGeom[i].OwningComponent.DisplayName;
                    Console.WriteLine("*************************" + reef);
                }
                /*Working Information with Hardcoded information;*/
                ComponentPositioner[]         tempcomponentPositioner1 = new ComponentPositioner[2];
                ComponentConstraint[]         tempcomponentConstraint1 = new ComponentConstraint[2];
                ComponentPositioner[]         componentPositioner1     = new ComponentPositioner[2];
                ComponentPositioner[]         componentPositioner2     = new ComponentPositioner[2];
                ComponentConstraint[]         componentConstraint1     = new ComponentConstraint[2];
                ComponentConstraint[]         componentConstraint2     = new ComponentConstraint[2];
                NXOpen.Assemblies.Component[] component01 = new Component[2];
                NXOpen.Assemblies.Component[] component02 = new Component[2];
                for (int m = 0; m < 2; m++)
                {
                    component01[m] = (NXOpen.Assemblies.Component)nxSubAssem.ComponentAssembly.RootComponent.FindObject("COMPONENT " + partname[m] + " 1");
                    //NXOpen.Assemblies.Component component02 = (NXOpen.Assemblies.Component)nxSubAssem.ComponentAssembly.RootComponent.FindObject("COMPONENT " + partname[0] + " 1");
                }

                /*
                 * tempcomponentPositioner1[0] = nxSubAssem.ComponentAssembly.Positioner;
                 * tempcomponentPositioner1[0].BeginAssemblyConstraints();
                 * Constraint tempconstraint1;
                 * tempconstraint1 = tempcomponentPositioner1[0].CreateConstraint(true);
                 * tempcomponentConstraint1[0] = (NXOpen.Positioning.ComponentConstraint)tempconstraint1;
                 * tempcomponentConstraint1[0].ConstraintType = NXOpen.Positioning.Constraint.Type.Concentric;
                 * Edge edge1 = (NXOpen.Edge)component01[0].FindObject(EdgeNames[0]);
                 * ConstraintReference ConsRef1 = tempcomponentConstraint1[0].CreateConstraintReference(component01[0],edge1,false,false,false);
                 * Edge edge2 = (NXOpen.Edge)component01[1].FindObject(EdgeNames[1]);
                 * ConstraintReference ConsRef2 = tempcomponentConstraint1[0].CreateConstraintReference(component01[1], edge2, false, false, false);
                 */


                for (int k = 0; k < 2; k++)
                {
                    if (constNamesTemp[k].Contains("Coaxial"))
                    {
                        componentPositioner1[k] = nxSubAssem.ComponentAssembly.Positioner;
                        componentPositioner1[k].BeginAssemblyConstraints();
                        Constraint constraint1;
                        constraint1             = componentPositioner1[k].CreateConstraint(true);
                        componentConstraint1[k] = (NXOpen.Positioning.ComponentConstraint)constraint1;
                        //componentConstraint1[k].ConstraintAlignment = NXOpen.Positioning.Constraint.Alignment.ContraAlign;
                        componentConstraint1[k].ConstraintType = NXOpen.Positioning.Constraint.Type.Fit;
                        NXOpen.Face face1 = (NXOpen.Face)component01[0].FindObject(ConstNames1[k]);
                        NXOpen.Positioning.ConstraintReference constraintReference1;
                        constraintReference1 = componentConstraint1[k].CreateConstraintReference(component01[0], face1, false, false, false);
                        component01[1]       = (NXOpen.Assemblies.Component)nxSubAssem.ComponentAssembly.RootComponent.FindObject("COMPONENT " + partname[1] + " 1");
                        NXOpen.Face face2 = (NXOpen.Face)component01[1].FindObject(ConstNames2[k]);
                        //Face face3 = (NXOpen.Face)component01[1].FindObject(ConstNames2[1]);
                        NXOpen.Positioning.ConstraintReference constraintReference2;
                        constraintReference2 = componentConstraint1[k].CreateConstraintReference(component01[1], face2, false, false, false);
                    }
                    else
                    {
                        componentPositioner2[k] = nxSubAssem.ComponentAssembly.Positioner;
                        componentPositioner2[k].BeginAssemblyConstraints();
                        Constraint constraint1;
                        constraint1             = componentPositioner2[k].CreateConstraint(true);
                        componentConstraint2[k] = (NXOpen.Positioning.ComponentConstraint)constraint1;
                        //componentConstraint2[k].ConstraintAlignment = NXOpen.Positioning.Constraint.Alignment.InferAlign;
                        componentConstraint2[k].ConstraintType = NXOpen.Positioning.Constraint.Type.Touch;
                        NXOpen.Face face1 = (NXOpen.Face)component01[0].FindObject(ConstNames1[k]);
                        NXOpen.Positioning.ConstraintReference constraintReference3;
                        constraintReference3 = componentConstraint2[k].CreateConstraintReference(component01[0], face1, false, false, false);
                        component01[1]       = (NXOpen.Assemblies.Component)nxSubAssem.ComponentAssembly.RootComponent.FindObject("COMPONENT " + partname[1] + " 1");
                        NXOpen.Face face2 = (NXOpen.Face)component01[1].FindObject(ConstNames2[k]);
                        NXOpen.Positioning.ConstraintReference constraintReference4;
                        constraintReference4 = componentConstraint2[k].CreateConstraintReference(component01[1], face2, false, false, false);
                        constraintReference4.SetFixHint(true);
                    }
                }
                break;
            }
            PartSaveStatus fileSave;

            fileSave = nxRootAssem.Save(BasePart.SaveComponents.True, BasePart.CloseAfterSave.False);
        }
コード例 #24
0
 internal Component(NXOpen.Assemblies.Component component) : base(component)
 {
     this.NXOpenComponent = component;
 }
コード例 #25
0
ファイル: ComponentEx.cs プロジェクト: zcstkhk/RhinoInside.NX
 /// <summary>
 /// 查询组件的名称(除非添加组件时设置,否则与部件名称通常相同)
 /// </summary>
 /// <param name="component"></param>
 /// <returns></returns>
 public static string GetName(this NXOpen.Assemblies.Component component)
 {
     return(component.Name);
 }
コード例 #26
0
        public static bool AddComponentToAsmByDefault(string componentPath, out NXOpen.Assemblies.Component newComponent, string referenceSetName = "MODEL", int layer = -1, bool uomAsNgc = true)
        {
            newComponent = null;
            try
            {
                string componentName = Path.GetFileNameWithoutExtension(componentPath);

                /*
                 * Session theSession = Session.GetSession();
                 * Part workPart = theSession.Parts.Work;
                 *
                 * string componentName = Path.GetFileNameWithoutExtension(componentPath);
                 * //string componentName = Path.GetFileName(componentPath);
                 *
                 * BasePart basePart1;
                 * PartLoadStatus partLoadStatus1;
                 * basePart1 = theSession.Parts.OpenBase(componentPath, out partLoadStatus1);
                 * partLoadStatus1.Dispose();
                 *
                 * //組裝設計檔
                 * Point3d basePoint1 = new Point3d(0.0, 0.0, 0.0);
                 * Matrix3x3 orientation1;
                 * orientation1.Xx = 1.0;
                 * orientation1.Xy = 0.0;
                 * orientation1.Xz = 0.0;
                 * orientation1.Yx = 0.0;
                 * orientation1.Yy = 1.0;
                 * orientation1.Yz = 0.0;
                 * orientation1.Zx = 0.0;
                 * orientation1.Zy = 0.0;
                 * orientation1.Zz = 1.0;
                 * PartLoadStatus partLoadStatus2;
                 * //NXOpen.Assemblies.Component componentDesign;
                 * newComponent = workPart.ComponentAssembly.AddComponent(componentPath, referenceSetName, componentName, basePoint1, orientation1, layer, out partLoadStatus2, uomAsNgc);
                 * partLoadStatus2.Dispose();
                 */


                Session theSession  = Session.GetSession();
                Part    workPart    = theSession.Parts.Work;
                Part    displayPart = theSession.Parts.Display;
                // ----------------------------------------------
                //   Menu: Assemblies->Components->Add Component...
                // ----------------------------------------------
                NXOpen.Session.UndoMarkId markId1;
                markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Add Component");

                NXOpen.Session.UndoMarkId markId2;
                markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Start");

                theSession.SetUndoMarkName(markId2, "Add Component Dialog");
                // 20150610 Stewart 重複組裝同一個零件時,OpenBase會錯
                try
                {
                    PartLoadStatus partLoadStatus1;
                    BasePart       basePart1;
                    basePart1 = theSession.Parts.OpenBase(componentPath, out partLoadStatus1);
                    partLoadStatus1.Dispose();
                }
                catch (System.Exception ex)
                {
                }
                // 20150610
                int nErrs1;
                nErrs1 = theSession.UpdateManager.DoUpdate(markId1);

                NXOpen.Session.UndoMarkId markId3;
                markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Add Component");

                theSession.DeleteUndoMark(markId3, null);

                NXOpen.Session.UndoMarkId markId4;
                markId4 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Add Component");

                Point3d   basePoint1 = new Point3d(0.0, 0.0, 0.0);
                Matrix3x3 orientation1;
                orientation1.Xx = 1.0;
                orientation1.Xy = 0.0;
                orientation1.Xz = 0.0;
                orientation1.Yx = 0.0;
                orientation1.Yy = 1.0;
                orientation1.Yz = 0.0;
                orientation1.Zx = 0.0;
                orientation1.Zy = 0.0;
                orientation1.Zz = 1.0;
                PartLoadStatus partLoadStatus2;
                //NXOpen.Assemblies.Component component1;

                newComponent = workPart.ComponentAssembly.AddComponent(componentPath, referenceSetName, componentName, basePoint1, orientation1, -1, out partLoadStatus2, true);

                partLoadStatus2.Dispose();
                NXObject[] objects1 = new NXObject[0];
                int        nErrs2;
                nErrs2 = theSession.UpdateManager.AddToDeleteList(objects1);

                theSession.DeleteUndoMark(markId4, null);

                theSession.SetUndoMarkName(markId2, "Add Component");

                theSession.DeleteUndoMark(markId2, null);
            }
            catch (System.Exception ex)
            {
                //CaxLog.ShowListingWindow(ex.Message);
                return(false);
            }

            return(true);
        }
コード例 #27
0
ファイル: ComponentEx.cs プロジェクト: zcstkhk/RhinoInside.NX
 /// <summary>
 /// 移动组件,距离为矢量的长度
 /// </summary>
 /// <param name="componentToMove">要移动的组件</param>
 /// <param name="vector"></param>
 /// <param name="copyOriginal"></param>
 public static Component MoveComponent(this NXOpen.Assemblies.Component componentToMove, Vector3d vector, bool copyOriginal = false) => MoveComponent(componentToMove, vector.X, vector.Y, vector.Z, copyOriginal);