国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

UG/NX二次開發(fā)(C#) 一個方法遍歷部件的體、面、邊屬性

這篇具有很好參考價值的文章主要介紹了UG/NX二次開發(fā)(C#) 一個方法遍歷部件的體、面、邊屬性。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報違法"按鈕提交疑問。

?初學(xué)UG/NX, 對體的各種tag還不熟悉,更別說各種面、邊、點(diǎn)的操作,感覺就像一口鍋里面的餃子,根本分不清哪個是哪個。

所以,這里對體的面、邊、點(diǎn)以及各對象進(jìn)行了一次整理,廢話不說,直接上代碼:

1、先定義體、面、邊模型

using NXOpen;
using NXOpen.Assemblies;
using NXOpen.Facet;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Text;

namespace Auto_Init.Model
{
    /// <summary>
    /// 基本屬性
    /// </summary>
    public class Base
    {
        public string StrTag { get; set; }                                   //返回對象的tag
        public Tag Tag { get; set; }
        public int Layer { get; set; }                               //返回當(dāng)前對象所在層
        public bool IsOccurrence { get; set; }                       //返回此對象是否為實(shí)例
        public bool IsBlanked { get; set; }                          //返回此對象是否為空白狀態(tài)
        public string Name { get; set; }                                //Returns the custom name of the object.
        public Point3d NameLocation { get; set; }                    //Returns the location of the object's name. (可能是中心點(diǎn)坐標(biāo))
        public string JournalIdentifier { get; set; }                //返回此對象的日志中的標(biāo)識符
        public int Color { get; set; }                               //返回顏色
        public DisplayableObject.ObjectFont LineFont { get; set; }   //Returns or sets the line font of the object
        public DisplayableObject.ObjectWidth LineWidth { get; set; } //Returns or sets the line width of the object. 
        public Component OwningComponent { get; set; }               //如果此對象是引用,則返回所屬組件
        public BasePart OwningPart { get; set; }                     //Returns the owning part of this object 
        public INXObject Prototype { get; set; }                     //Returns the prototype of this object if it is an occurrence. 
    }

    /// <summary>
    /// 塊/體
    /// </summary>
    public class BodyModel : Base
    {
        public List<FaceModel> FaceList { get; set; }
        public FaceFlag faceFlag { get; set; }
        public double Density { get; set; }                          //密度
        public bool IsSheetBody { get; set; }                        //是否為sheet
        public bool IsSolidBody { get; set; }                        //是否為實(shí)體
        public IMessageSink NextSink { get; set; }                   //Gets the next message sink in the sink chain. 
        public Type Type { get; set; }                               //類型
        public FacetedBody facetBody { get; set; }                   //鑲嵌體
        public bool upToDate { get; set; }                           //過期時間
        public Dictionary<string, FaceModel> DicFace { get; set; }   //面字典,key為面的tag
        public Dictionary<string, EdgeModel> DicEdge { get; set; }   //邊字典,key為邊的tag
    }

    public class FaceFlag
    { 
        public string faceTop { get;set;}
        public string faceBotton { get;set;}
        public string face2 {get;set;}
        public string face3 { get; set; }
        public string face4 { get; set; }
        public string face5 { get; set; }
    }

    /// <summary>
    /// 面
    /// </summary>
    public class FaceModel : Base
    {
        public Face.FaceType SolidFaceType { get; set; }             //返回面的實(shí)體類型
        public List<EdgeModel> EdgeList { get; set; }
        public List<Point3d> PointList { get; set; }
        public Body fatherBody { get; set; }
        public NXObject.AttributeInformation[] Attribute { get; set; }  //返回對象上的所有屬性
    }

    /// <summary>
    /// 邊
    /// </summary>
    public class EdgeModel : Base
    {
        public double Len { get; set; }                              //邊長
        public bool IsReference { get; set; }                        //返回曲線的參考狀態(tài)
        public Edge.EdgeType SolidEdgeType { get; set; }             //返回邊的實(shí)體類型
        public Face[] FatherFaces { get; set; }                      //邊所在的面
        public Body FatherBody { get; set; }                         //邊所在的體
        public Type Type { get; set; }                               //類型
        public Point3d Vertex1 { get; set; }
        public Point3d Vertex2 { get; set; }
    }
}

2、加載體的方法如下

public class BodyInit
    {
        public Body body;
        public BodyModel bodyModel;
        public UI theUI;
        public NXOpen.UF.UFSession theUFSession;

        public BodyInit(Body body)
        {
            this.body = body;
            this.theUI = UI.GetUI();
            theUFSession = UFSession.GetUFSession();
        }

        public FaceModel GetFaceByTag(string tag)
        {
            if (bodyModel.DicFace.ContainsKey(tag))
                return bodyModel.DicFace[tag];
            return null;
        }

        public EdgeModel GetEdgeModelByTag(string tag)
        {
            if (bodyModel.DicEdge.ContainsKey(tag))
                return bodyModel.DicEdge[tag];
            return null;
        }

        /// <summary>
        /// 加載體
        /// </summary>
        /// <returns></returns>
        public BodyModel ProcBody()
        {
            bodyModel = new BodyModel();
            bodyModel.FaceList = new List<FaceModel>();
            bodyModel.DicFace = new Dictionary<string, FaceModel>();
            bodyModel.DicEdge = new Dictionary<string, EdgeModel>();

            try
            {
                foreach (Face faceObj in body.GetFaces())
                {
                    FaceModel face = ProcFace(faceObj);
                    bodyModel.FaceList.Add(face);
                    bodyModel.DicFace.Add(faceObj.Tag.ToString(), face);
                }

                foreach (Edge edgeObj in body.GetEdges())
                {
                    EdgeModel edge = ProcEdge(edgeObj);
                    bodyModel.DicEdge.Add(edge.StrTag.ToString(), edge);
                }

                bodyModel.JournalIdentifier = body.JournalIdentifier;
                bodyModel.Color = body.Color;
                bodyModel.Density = body.Density;
                bodyModel.IsBlanked = body.IsBlanked;
                bodyModel.IsOccurrence = body.IsOccurrence;
                bodyModel.IsSheetBody = body.IsSheetBody;
                bodyModel.IsSolidBody = body.IsSolidBody;
                bodyModel.Layer = body.Layer;
                bodyModel.LineFont = body.LineFont;
                bodyModel.LineWidth = body.LineWidth;
                bodyModel.Name = body.Name;
                try
                {
                    bodyModel.NameLocation = body.NameLocation;
                }
                catch (Exception)
                {

                }
                bodyModel.NextSink = body.NextSink;
                bodyModel.OwningComponent = body.OwningComponent;
                //bodyModel.OwningPart = body.OwningPart;
                bodyModel.Prototype = body.Prototype;
                bodyModel.StrTag = body.Tag.ToString();
                bodyModel.Tag = body.Tag;

                try
                {
                    FacetedBody facete;
                    bool uptodate;
                    body.GetFacetedBody(out facete, out uptodate);
                    bodyModel.facetBody = facete;
                    bodyModel.upToDate = uptodate;
                }
                catch (Exception)
                {

                }
                bodyModel.Type = body.GetType();

                bodyModel.faceFlag = new FaceFlag();
                string tagTop, tagBotton, tag2, tag3, tag4, tag5;
                InitBll.GetRightFace(bodyModel.FaceList, out tagTop, out tagBotton, out tag2, out tag3, out tag4, out tag5);
                bodyModel.faceFlag.faceTop = tagTop;
                bodyModel.faceFlag.faceBotton = tagBotton;
                bodyModel.faceFlag.face2 = tag2;
                bodyModel.faceFlag.face3 = tag3;
                bodyModel.faceFlag.face4 = tag4;
                bodyModel.faceFlag.face5 = tag5;

                int num_boundaries;
                int[] num_edges;
                Tag[] edge_tags;
                theUFSession.Modl.AskBodyBoundaries(body.Tag, out num_boundaries, out num_edges, out edge_tags);
            }
            catch (Exception ex)
            {
                theUI.NXMessageBox.Show("ProcBody fun", NXMessageBox.DialogType.Error, ex.ToString());
            }

            return bodyModel;
        }

        /// <summary>
        /// 加載面
        /// </summary>
        /// <param name="faceObj"></param>
        /// <returns></returns>
        public FaceModel ProcFace(Face faceObj)
        {
            FaceModel model = new FaceModel();
            model.EdgeList = new List<EdgeModel>();
            model.PointList = new List<Point3d>();
            try
            {
                foreach (Edge edgeObj in faceObj.GetEdges())
                {
                    EdgeModel item = ProcEdge(edgeObj);
                    model.EdgeList.Add(item);
                    if (!model.PointList.Contains(item.Vertex1))
                    {
                        model.PointList.Add(item.Vertex1);
                    }
                    if (!model.PointList.Contains(item.Vertex2))
                    {
                        model.PointList.Add(item.Vertex2);
                    }
                }
                model.Color = faceObj.Color;
                model.IsBlanked = faceObj.IsBlanked;
                model.IsOccurrence = faceObj.IsOccurrence;
                model.JournalIdentifier = faceObj.JournalIdentifier;
                model.Layer = faceObj.Layer;
                model.LineFont = faceObj.LineFont;
                model.LineWidth = faceObj.LineWidth;
                model.Name = faceObj.Name;
                try
                {
                    model.NameLocation = faceObj.NameLocation;
                }
                catch (Exception)
                {

                }
                model.OwningComponent = faceObj.OwningComponent;
                //model.OwningPart = faceObj.OwningPart;
                model.Prototype = faceObj.Prototype;
                model.SolidFaceType = faceObj.SolidFaceType;
                model.StrTag = faceObj.Tag.ToString();
                model.Tag = faceObj.Tag;
                model.fatherBody = faceObj.GetBody();
                model.Attribute = faceObj.GetUserAttributes();
            }
            catch (Exception ex)
            {
                theUI.NXMessageBox.Show("ProcFace fun", NXMessageBox.DialogType.Error, ex.ToString());
            }

            return model;
        }

        /// <summary>
        /// 加載邊
        /// </summary>
        /// <param name="edgeObj"></param>
        /// <returns></returns>
        public EdgeModel ProcEdge(Edge edgeObj)
        {
            EdgeModel model = new EdgeModel();

            try
            {
                model.StrTag = edgeObj.Tag.ToString();
                model.Tag = edgeObj.Tag;
                model.Color = edgeObj.Color;
                model.FatherBody = edgeObj.GetBody();
                model.FatherFaces = edgeObj.GetFaces();
                model.IsBlanked = edgeObj.IsBlanked;
                model.IsOccurrence = edgeObj.IsOccurrence;
                model.IsReference = edgeObj.IsReference;
                model.JournalIdentifier = edgeObj.JournalIdentifier;
                model.Layer = edgeObj.Layer;
                model.Len = edgeObj.GetLength();
                model.LineFont = edgeObj.LineFont;
                model.LineWidth = edgeObj.LineWidth;
                model.Name = edgeObj.Name;
                try
                {
                    model.NameLocation = edgeObj.NameLocation;
                }
                catch (Exception)
                {

                }
                model.OwningComponent = edgeObj.OwningComponent;
                //model.OwningPart = edgeObj.OwningPart;
                model.Prototype = edgeObj.Prototype;
                model.SolidEdgeType = edgeObj.SolidEdgeType;
                model.Type = edgeObj.GetType();
                Point3d temp1, temp2;
                edgeObj.GetVertices(out temp1, out temp2);
                model.Vertex1 = temp1;
                model.Vertex2 = temp2;
            }
            catch (Exception ex)
            {
                theUI.NXMessageBox.Show("ProcEdge fun", NXMessageBox.DialogType.Error, ex.ToString());
            }


            return model;
        }
    }

3、調(diào)用方法

using System;
using NXOpen;
using Auto_Init.Model;
using NXOpen.UF;

public class Program
{
    public static Session theSession;
    public static Part workPart;
    public static Part displayPart;
    public static NXOpen.UF.UFSession theUFSession;
    private static UI theUI = null;
    public static AssembliesUtils assem;


    public static void Main(string[] args)
    {
        try
        {
            theSession = Session.GetSession();
            displayPart = theSession.Parts.Display;
            theUFSession = UFSession.GetUFSession();
            workPart = theSession.Parts.Work;

            Body bodyYZHU = (Body)workPart.Bodies.FindObject("BLOCK(1)");
            Auto_Init.BodyInit init = new Auto_Init.BodyInit(bodyYZHU);
            BodyModel model = init.ProcBody();
            Face topface = (Face)NXOpen.Utilities.NXObjectManager.GetObjectFromUInt(uint.Parse(model.faceFlag.faceTop));
        }
        catch (NXOpen.NXException ex)
        {
            theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
        }
    }
}

4、運(yùn)行結(jié)果如下圖

c#ug遍歷body,二次開發(fā)NXOPEN,c#,開發(fā)語言,ui文章來源地址http://www.zghlxwxcb.cn/news/detail-597569.html

到了這里,關(guān)于UG/NX二次開發(fā)(C#) 一個方法遍歷部件的體、面、邊屬性的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • UG NX二次開發(fā)(C++)-建模-創(chuàng)建基準(zhǔn)坐標(biāo)系(NXOpen方法)

    在UG NX三維建模過程中,創(chuàng)建基準(zhǔn)坐標(biāo)系是很重要的。基準(zhǔn)坐標(biāo)系是對于其他模型建模的一個參考,在UG NX中菜單中是由創(chuàng)建基準(zhǔn)坐標(biāo)系功能的,UG NX二次開發(fā)的創(chuàng)建基準(zhǔn)坐標(biāo)系的方法有兩種,其可以通過UFun函數(shù)創(chuàng)建,也

    2024年02月02日
    瀏覽(45)
  • UG NX二次開發(fā)(C#)-建模-刪除面

    UG NX二次開發(fā)(C#)-建模-刪除面

    ? ? ? ? 在三維建模后,為了仿真的需要,需要對建好的模型進(jìn)行簡化處理,這時候同步建模的功能就非常有必要了。本文主要介紹一個刪除面的操作,這樣可以去掉孔面、倒圓角面、倒斜角面,以用于模型仿真的完整性。 ???????? 采用UG NX的UIStyler創(chuàng)建一個測試界面,如

    2023年04月14日
    瀏覽(32)
  • UG NX二次開發(fā)(C#)-裝配-刪除陣列矩陣

    UG NX二次開發(fā)(C#)-裝配-刪除陣列矩陣

    在外部模式對裝配體進(jìn)行替換或者刪除時,有時遇到部分組件不能替換或者刪除,其中一個原因是陣列主組件,是不允許更改的。下面介紹下采用UG NX二次開發(fā)的方法刪除陣列主組件。 在一個裝配體模型中,刪除某個組件時會出現(xiàn)下面的錯誤: “不能刪除組件圖樣的主組件”

    2024年02月07日
    瀏覽(50)
  • UG\NX二次開發(fā)BlockUI 進(jìn)入NX的BlockUI編輯界面

    UG\NX二次開發(fā)BlockUI 進(jìn)入NX的BlockUI編輯界面

    文章作者:里海 來源網(wǎng)站:王牌飛行員_里海_里海NX二次開發(fā)3000例,里海BlockUI專欄,CC++-CSDN博客 ????????要使用BlockUI,需要先進(jìn)入NX的BlockUI編輯界面。在低版本中,可以在Toolbar工具條中進(jìn)入 開始→所有應(yīng)用模塊→塊UI樣式編輯器 ;在高版本中,可以在Ribbon工具欄中進(jìn)入

    2024年02月02日
    瀏覽(30)
  • UG\NX二次開發(fā) 實(shí)現(xiàn)預(yù)覽和取消預(yù)覽

    文章作者:里海 來源網(wǎng)站: https://blog.csdn.net/WangPaiFeiXingYuan ? ? ? ? 介紹兩種方法。一是先創(chuàng)建特征,記錄創(chuàng)建的特征,取消預(yù)覽時刪除這些特征。另一種方法是在創(chuàng)建特征前Set_mark,取消預(yù)覽就undo_to_mark。 ? ? ??

    2024年02月14日
    瀏覽(26)
  • UG/NX二次開發(fā) 將當(dāng)前視圖截圖到剪切板

    文章作者:里海 來源網(wǎng)站: https://blog.csdn.net/WangPaiFeiXingYuan ? ? ? ? 將當(dāng)前視圖截圖到剪切板,運(yùn)行完程序后,找一個位置(比如PPT) 粘貼。

    2024年02月11日
    瀏覽(68)
  • UG\NX二次開發(fā) 用戶自定義UI塊

    UG\NX二次開發(fā) 用戶自定義UI塊

    1.打開NX軟件,點(diǎn)擊“塊UI樣式編輯器”,進(jìn)入UI編輯界面; ?2.將類型改為“用戶定義 UI 塊”; ?3.設(shè)置名稱、目錄名稱,也可以設(shè)置自定義UI塊的圖標(biāo); ?4.點(diǎn)擊保存,需要注意自定義UI塊會多生成一個目標(biāo)文件“.udx”,如果需要使用自定義的UI塊,則必須把自定義UI塊生成的

    2024年02月16日
    瀏覽(23)
  • UG NX二次開發(fā)(C#)-創(chuàng)建點(diǎn)到曲線(邊)的切線

    提示:文章寫完后,目錄可以自動生成,如何生成可參考右邊的幫助文檔 在UG NX二次開發(fā)時,對于求點(diǎn)到曲線的切線,采用ufun函數(shù)可以實(shí)現(xiàn),即是UF_CURVE_create_line_point_tangent,但是對于C#,這個函數(shù)尚未封裝進(jìn)來,所以沒有直接對應(yīng)的函數(shù)。本文講一下采用C#創(chuàng)建點(diǎn)到曲線的切

    2024年02月09日
    瀏覽(37)
  • UG\NX 二次開發(fā) 相切面、相鄰面的選擇控件

    UG\NX 二次開發(fā) 相切面、相鄰面的選擇控件

    文章作者:里海 來源網(wǎng)站: https://blog.csdn.net/WangPaiFeiXingYuan ? ? ? ? 有群友問“UFUN多選功能過濾面不能選擇相切面或相鄰面之類的嗎?” 這個用Block UI的\\\"面收集器\\\"可以,ufun函數(shù)也可以,請參照這篇:【NX二次開發(fā)】相切面封裝函數(shù)-CSDN博客 ? ? ?? ?? ? ? ? ??

    2024年02月12日
    瀏覽(26)
  • UG NX二次開發(fā)(C#)-機(jī)械管線布置-添加管道路徑

    提示:文章寫完后,目錄可以自動生成,如何生成可參考右邊的幫助文檔 機(jī)械管道布局是UG NX的一個應(yīng)用模塊,以前給客戶做過一個項目,現(xiàn)在分享給大家。這篇文章是講解如何布置管道路徑(創(chuàng)建線性路徑),后面會逐步的講解,如果有需要的可以私信博主,或者加入QQ群

    2024年01月20日
    瀏覽(37)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包