예제 #1
0
        //[Obsolete]
        /// <summary>
        /// Assign to each face by it's identificator a color or materials by boolean.
        /// </summary>
        /// <param name="doc_dyn">Current document</param>
        /// <param name="solids_id_list">List with solid3d ObjectId</param>
        /// <param name="faces_info_list">List with Dictionaries for each solid (created in Python script).</param>
        /// <param name="MaterialsByName">Dictionary with materials for names</param>
        /// <param name="ColorsByNames">Dictionary with colors for names</param>
        /// <param name="UseColors">If true - using colors; else -- materials</param>
        public static void SetMaterialByFacesCentroids(Autodesk.AutoCAD.DynamoNodes.Document doc_dyn, List <ObjectId> solids_id_list, List <Dictionary <string, string> > faces_info_list,
                                                       Dictionary <string, ObjectId> MaterialsByName, Dictionary <string, Autodesk.AutoCAD.Colors.Color> ColorsByNames, bool UseColors = false)
        {
            Document doc = doc_dyn.AcDocument;
            //Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;

            for (int i2 = 0; i2 < solids_id_list.Count; i2++)
            {
                ObjectId OneSolidId = solids_id_list[i2];
                Dictionary <string, string> faces_info = faces_info_list[i2];


                using (Solid3d OneSolid = OneSolidId.Open(OpenMode.ForWrite) as Solid3d)
                {
                    FullSubentityPath path = new FullSubentityPath(new ObjectId[1] {
                        OneSolidId
                    }, new SubentityId(SubentityType.Null, IntPtr.Zero));
                    List <FacesProps> faces = new List <FacesProps>();
                    using (Brep brep = new Brep(path))
                    {
                        //List<Autodesk.AutoCAD.BoundaryRepresentation.Face> solid_faces = brep.Faces.ToList();
                        //foreach (KeyValuePair<string, string> face_info in faces_info)
                        foreach (Autodesk.AutoCAD.BoundaryRepresentation.Face face in brep.Faces)
                        {
                            //int FaceNumber = Convert.ToInt32(face_info.Key.Split('_')[1]);
                            //long FaceNumber = Convert.ToInt64(face_info.Key.Split('_')[1]);
                            //IntPtr face_IntPtr = (IntPtr)FaceNumber;
                            //FullSubentityPath path2 = new FullSubentityPath(new ObjectId[1] { OneSolidId }, new SubentityId(SubentityType.Null, face_IntPtr));
                            //Autodesk.AutoCAD.BoundaryRepresentation.Face face = solid_faces[FaceNumber];
                            string Face_Id = $"{OneSolidId.Handle}_{face.SubentityPath.SubentId.IndexPtr.ToInt64()}";
                            if (faces_info.ContainsKey(Face_Id))
                            {
                                SubentityId face_id = face.SubentityPath.SubentId;
                                var         face_info_material_name = faces_info[Face_Id];

                                FacesProps face_data = new FacesProps();
                                if (UseColors == true)
                                {
                                    face_data.color = ColorsByNames[face_info_material_name];
                                }
                                else
                                {
                                    face_data.material = MaterialsByName[face_info_material_name];
                                }
                                face_data.id = face_id;
                                faces.Add(face_data);
                            }
                        }
                    }
                    if (UseColors == true)
                    {
                        foreach (FacesProps face_one in faces)
                        {
                            OneSolid.SetSubentityColor(face_one.id, face_one.color);
                            //doc.Editor.WriteMessage($"Color {face_one.color} was assigned for {face_one.id}");
                        }
                    }
                    else
                    {
                        foreach (FacesProps face_one in faces)
                        {
                            OneSolid.SetSubentityMaterial(face_one.id, face_one.material);
                            //doc.Editor.WriteMessage($"Material was assigned for {face_one.id}");
                        }
                    }
                }
            }
        }