Beispiel #1
0
        private ObservableCollection <SelectPartFamilyModel> GetPartFams(Document doc, PartsList partsList,
                                                                         ObjectId defPartFamIfExists, ObjectId defPartSizeIfExists)
        {
            ObservableCollection <SelectPartFamilyModel> partfams = new ObservableCollection <SelectPartFamilyModel>();
            Database db = doc.Database;

            pfStartSelection = null;
            psStartSelection = null;


            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                for (int i = 0; i < partsList.PartFamilyCount; i++)
                {
                    ObjectId   plFamId = partsList[i];
                    PartFamily pf      = (PartFamily)tr.GetObject(plFamId, OpenMode.ForRead);



                    if (partType.HasFlag(pf.PartType))
                    {
                        ObservableCollection <PartSize> partSizes = new ObservableCollection <PartSize>();
                        PartSize startSelSizeCandidate            = null;
                        for (int j = 0; j < pf.PartSizeCount; j++)
                        {
                            ObjectId psId = pf[j];
                            PartSize ps   = (PartSize)psId.GetObject(OpenMode.ForRead);
                            if (defPartSizeIfExists.Equals(psId))
                            {
                                startSelSizeCandidate = ps;
                            }
                            partSizes.Add(ps);
                        }

                        SelectPartFamilyModel spfm = new SelectPartFamilyModel(pf, partSizes);
                        if (defPartFamIfExists.Equals(plFamId))
                        {
                            pfStartSelection = spfm;
                            if (startSelSizeCandidate != null)
                            {
                                psStartSelection = startSelSizeCandidate;
                            }
                        }
                        partfams.Add(spfm);
                    }
                }


                tr.Commit();
            }

            return(partfams);
        }