Esempio n. 1
0
        static bool IsSheetMetalPart(IPartDoc swPart)
        {
            try
            {
                var isSheet = false;

                var vBodies = swPart.GetBodies2((int)swBodyType_e.swSolidBody, false);

                foreach (Body2 vBody in vBodies)
                {
                    try
                    {
                        var isSheetMetal = vBody.IsSheetMetal();
                        if (!isSheetMetal) continue;
                        isSheet = true;
                    }
                    catch
                    {
                        isSheet = false;
                    }
                }

                return isSheet;
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.ToString());
                return false;
            }
        }
        public CylinderParams GetCylinderParameters(IPartDoc part, object inputObj, bool concentric, double step, double extraRadius)
        {
            CylinderParams cylParams;
            var            body = GetScopeBody(part, inputObj);

            var dir = GetDirection(inputObj);

            cylParams = m_CylExt.GetStockParameters(new SolidBodyGeometry(body), dir);

            cylParams.Radius = cylParams.Radius + extraRadius;

            if (concentric && (inputObj is IFace2) && (inputObj as IFace2).IGetSurface().IsCylinder())
            {
                var surfCylParams = (inputObj as IFace2).IGetSurface().CylinderParams as double[];
                var pt            = new Point(surfCylParams[0], surfCylParams[1], surfCylParams[2]);
                cylParams = m_CylExt.ReCenter(dir, pt, cylParams);
            }

            if (step > 0)
            {
                cylParams = m_CylExt.FitToStockSizeByStep(cylParams, step);
            }

            return(cylParams);
        }
        private void OnClosed(swPropertyManagerPageCloseReasons_e reason)
        {
            m_Model.HidePreview(m_CurrentPart);

            var isOk = reason == swPropertyManagerPageCloseReasons_e.swPropertyManagerPageClose_Okay;

            if (isOk)
            {
                m_CurrentParameters.ScopeBody = m_Model.GetScopeBody(
                    m_CurrentPart, m_CurrentParameters.Direction);

                m_UserSetts.StoreSettings(m_CurrentParameters, nameof(RoundStockFeatureParameters));
                //m_OptsStore.Save(m_CurrentParameters);
            }

            if (m_EditingFeature != null)
            {
                FeatureEditingCompleted?.Invoke(m_CurrentParameters, m_CurrentPart, m_EditingFeature,
                                                m_EditingFeatureData, isOk);
            }
            else
            {
                FeatureInsertionCompleted?.Invoke(m_CurrentParameters, m_CurrentPart, isOk);
            }

            m_EditingFeature = null;
            m_CurrentPart    = null;
        }
Esempio n. 4
0
        static bool IsSheetMetalPart(IPartDoc swPart)
        {
            try
            {
                var isSheet = false;

                var vBodies = swPart.GetBodies2((int)swBodyType_e.swSolidBody, false);

                foreach (Body2 vBody in vBodies)
                {
                    try
                    {
                        var isSheetMetal = vBody.IsSheetMetal();
                        if (!isSheetMetal)
                        {
                            continue;
                        }
                        isSheet = true;
                    }
                    catch
                    {
                        isSheet = false;
                    }
                }

                return(isSheet);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.ToString());
                return(false);
            }
        }
        public void ShowPreview(IPartDoc part, object inputObj, bool concentric, double step, double extraRadius)
        {
            HidePreview(part);

            try
            {
                var cylParams = GetCylinderParameters(part, inputObj, concentric, step, extraRadius);
                m_TempBody = CreateCylindricalStock(cylParams);
            }
            catch
            {
            }

            if (m_TempBody != null)
            {
                const int COLORREF_YELLOW = 65535;

                m_TempBody.Display3(part, COLORREF_YELLOW,
                                    (int)swTempBodySelectOptions_e.swTempBodySelectOptionNone);

                m_TempBody.MaterialPropertyValues2 = new double[] { 1, 1, 0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 };

                (part as IModelDoc2).GraphicsRedraw2();
            }
        }
        /// <summary>
        /// Check is sheet metal part
        /// </summary>
        /// <param name="swPart"></param>
        public static bool IsSheetMetalPart(IPartDoc swPart)
        {
            bool isSheetMetal = false;

            try
            {
                var bodies = swPart.GetBodies2((int)swBodyType_e.swSolidBody, false);
                foreach (Body2 body in bodies)
                {
                    isSheetMetal = body.IsSheetMetal();

                    MessageBox.Show("Check is sheet metal part; returned " + isSheetMetal);

                    if (isSheetMetal)
                    {
                        return(true);
                    }
                }
            }
            catch (System.Exception)
            {
                MessageBox.Show("Failed check is sheet metal part; returned " + false);
                return(false);
            }
            return(isSheetMetal);
        }
        public void ShowPage(RoundStockFeatureParameters parameters, IPartDoc part, IFeature editingFeature, IMacroFeatureData featData)
        {
            m_CurrentParameters  = parameters;
            m_CurrentPart        = part;
            m_EditingFeature     = editingFeature;
            m_EditingFeatureData = featData;

            if (m_ActivePage != null)
            {
                m_ActivePage.Handler.DataChanged -= OnDataChanged;
                m_ActivePage.Handler.Closing     -= OnPageClosing;
                m_ActivePage.Handler.Closed      -= OnClosed;
            }

            m_CurrentViewModel = RoundStockViewModel.FromParameters(parameters);

            m_ActivePage = new RoundStockView(m_CurrentViewModel, m_App);

            m_ActivePage.Handler.DataChanged += OnDataChanged;
            m_ActivePage.Handler.Closing     += OnPageClosing;
            m_ActivePage.Handler.Closed      += OnClosed;

            m_ActivePage.Show();

            m_Model.ShowPreview(part, parameters.Direction, parameters.ConcenticWithCylindricalFace,
                                parameters.StockStep, parameters.ExtraRadius);
        }
Esempio n. 8
0
        private void OnFeatureEditingCompleted(RoundStockFeatureParameters parameters,
                                               IPartDoc part, IFeature feat, IMacroFeatureData featData, bool isOk)
        {
            if (isOk)
            {
                MacroFeatureOutdateState_e state;
                SetParameters(part as IModelDoc2, feat, featData, parameters, out state);

                if (state != MacroFeatureOutdateState_e.UpToDate)
                {
                    if (m_Controller.App.SendMsgToUser2("This features is outdated. It is required to replace it. Do you want to replace this feature?",
                                                        (int)swMessageBoxIcon_e.swMbWarning,
                                                        (int)swMessageBoxBtn_e.swMbYesNo) == (int)swMessageBoxResult_e.swMbHitYes)
                    {
                        feat = (part as IModelDoc2).FeatureManager
                               .ReplaceComFeature <RoundStockMacroFeature, RoundStockFeatureParameters>(
                            feat, parameters);

                        return;
                    }
                }

                feat.ModifyDefinition(featData, part, null);
            }
            else
            {
                featData.ReleaseSelectionAccess();
            }
        }
Esempio n. 9
0
        internal SwPart(IPartDoc part, SwApplication app, IXLogger logger, bool isCreated)
            : base((IModelDoc2)part, app, logger, isCreated)
        {
            m_CutListRebuild = new CutListRebuildEventsHandler(this);

            Bodies = new SwPartBodyCollection(this);
        }
 public void HidePreview(IPartDoc part)
 {
     if (m_TempBody != null)
     {
         m_TempBody.Hide(part);
         m_TempBody = null;
         GC.Collect();
     }
 }
Esempio n. 11
0
        static bool IsSheetMetalPart(IPartDoc swPart)
        {
            var isSheetMetal = false;
            var vBodies      = swPart.GetBodies2((int)swBodyType_e.swSolidBody, false);

            foreach (Body2 vBody in vBodies)
            {
                isSheetMetal = vBody.IsSheetMetal();
            }
            return(isSheetMetal);
        }
Esempio n. 12
0
        /// <summary>
        /// Convert to dxf input configuration of document
        /// </summary>
        /// <param name="configuration">Building configuration</param>
        /// <param name="swModel">Building document</param>
        /// <param name="dxfFilePath">Output path to file</param>
        /// <param name="isSheetmetal">Enable or disable well whether build no sheet metal parts</param>
        /// <returns></returns>
        public bool ConvertToDXF(string configuration, IModelDoc2 swModel, out byte[] dxfByteCode, bool isSheetmetal)
        {
            dxfByteCode = null;
            string dxfFilePath = string.Empty;

            try
            {
                string sDxfName = DxfNameBuild(swModel.GetTitle(), configuration) + ".dxf";
                dxfFilePath = Path.Combine(FolderToSaveDxf, sDxfName);
                if (!Directory.Exists(FolderToSaveDxf))
                {
                    Directory.CreateDirectory(FolderToSaveDxf);
                }

                double[] dataAlignment = new double[12];

                dataAlignment[0]  = 0.0;
                dataAlignment[1]  = 0.0;
                dataAlignment[2]  = 0.0;
                dataAlignment[3]  = 1.0;
                dataAlignment[4]  = 0.0;
                dataAlignment[5]  = 0.0;
                dataAlignment[6]  = 0.0;
                dataAlignment[7]  = 1.0;
                dataAlignment[8]  = 0.0;
                dataAlignment[9]  = 0.0;
                dataAlignment[10] = 0.0;
                dataAlignment[11] = 1.0;
                object varAlignment = dataAlignment;

                IPartDoc swPart = (IPartDoc)swModel;

                int  sheetmetalOptions = SheetMetalOptions(true, false, false, false, false, true, false);
                bool isExportToDWG2    = swPart.ExportToDWG2(dxfFilePath, swModel.GetPathName(), isSheetmetal ? (int)swExportToDWG_e.swExportToDWG_ExportSheetMetal : (int)swExportToDWG_e.swExportToDWG_ExportSelectedFacesOrLoops,
                                                             true, varAlignment, false, false, sheetmetalOptions, isSheetmetal ? 0 : (int)swExportToDWG_e.swExportToDWG_ExportAnnotationViews);

                MessageObserver.Instance.SetMessage("\tCompleted building " + " with configuration \"" + configuration + "\"", MessageType.System);

                if (isExportToDWG2)
                {
                    dxfByteCode = DxfToByteCode(dxfFilePath);
                }

                return(isExportToDWG2);
            }
            catch (Exception exception)
            {
                string message = "\tFailed build dxf  " + swModel?.GetTitle() + " with configuration \"" + configuration + "\"" + exception.ToString();
                MessageObserver.Instance.SetMessage(message, MessageType.Error);
                return(false);
            }
        }
Esempio n. 13
0
        public static IEnumerable <IBody2> GetBodiesEx(this IPartDoc doc, swBodyType_e bodyType = swBodyType_e.swSolidBody, bool withInvisbleBody = false)
        {
            object[] bodies = doc.GetBodies2((int)bodyType, !withInvisbleBody) as object[];

            if (bodies == null)
            {
                yield break;
            }

            foreach (var item in bodies)
            {
                yield return(item as IBody2);
            }
        }
Esempio n. 14
0
        private void CreateCylindricalBody(IPartDoc part, CylinderParams cylParams)
        {
            IBody2 cylTempBody = swApp.IGetModeler().CreateBodyFromCyl(new double[]
            {
                cylParams.Origin[0], cylParams.Origin[1], cylParams.Origin[2],
                cylParams.Direction[0], cylParams.Direction[1], cylParams.Direction[2],
                cylParams.Radius, cylParams.Height
            }) as IBody2;

            IFeature feat = part.CreateFeatureFromBody3(cylTempBody, false,
                                                        (int)swCreateFeatureBodyOpts_e.swCreateFeatureBodySimplify) as IFeature;

            IBody2 body = feat.GetBody() as IBody2;

            body.MaterialPropertyValues2 = new double[] { 1, 1, 0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 };
        }
Esempio n. 15
0
        private IBody2 GetBodyToProcess(IPartDoc part, object inputObj)
        {
            if (inputObj is IFace2)
            {
                return((inputObj as IFace2).GetBody() as IBody2);
            }
            else
            {
                object[] solidBodies = part.GetBodies2((int)swBodyType_e.swSolidBody, true) as object[];

                if (solidBodies != null && solidBodies.Length == 1)
                {
                    return(solidBodies[0] as IBody2);
                }
            }

            throw new NullReferenceException("Failed to find the input body. Either select cylindrical face or use single body part");
        }
Esempio n. 16
0
        public static MaterialBuilder GetMaterialBuilder(this IPartDoc doc)
        {
            var matBuilder = default(MaterialBuilder);
            var mdlDoc     = (IModelDoc2)doc;

            var materialValue = doc.MaterialPropertyValues as double[];

            if (materialValue == null || materialValue.Length < 7)
            {
                matBuilder = MaterialUtility.DefuatMaterial;
            }
            else
            {
                matBuilder = MaterialUtility.MaterialValueToMaterialBuilder(materialValue);
            }

            return(matBuilder);
        }
Esempio n. 17
0
        public static bool IsSheetMetalPart(IPartDoc swPart)
        {
            var isSheetMetal = false;

            try
            {
                var vBodies = swPart.GetBodies2((int)swBodyType_e.swSolidBody, false);

                foreach (Body2 vBody in vBodies)
                {
                    isSheetMetal = vBody.IsSheetMetal();
                    if (isSheetMetal)
                    {
                        return(true);
                    }
                }
            }
            catch (Exception)
            {
                return(false);
            }
            return(isSheetMetal);
        }
Esempio n. 18
0
        /// <summary>
        /// Check is sheet metal part
        /// </summary>
        /// <param name="swPart"></param>
        /// <returns></returns>
        public static bool IsSheetMetalPart(IPartDoc swPart)
        {
            var isSheetMetal = false;

            try
            {
                var bodies = swPart.GetBodies2((int)swBodyType_e.swSolidBody, false);
                foreach (Body2 body in bodies)
                {
                    isSheetMetal = body.IsSheetMetal();
                    if (isSheetMetal)
                    {
                        MessageObserver.Instance.SetMessage("Check is sheet metal part; returned " + isSheetMetal, MessageType.Success);
                        return(true);
                    }
                }
            }
            catch (Exception)
            {
                MessageObserver.Instance.SetMessage("Failed check is sheet metal part; returned " + false, MessageType.Success);
                return(false);
            }
            return(isSheetMetal);
        }
        private void OnFeatureInsertionCompleted(RoundStockFeatureParameters parameters, IPartDoc part, bool isOk)
        {
            if (isOk)
            {
                var feat = (part as IModelDoc2).FeatureManager
                           .InsertComFeature <RoundStockMacroFeature, RoundStockFeatureParameters>(parameters);

                Debug.Assert(feat != null);

                //swpuc only
                if (feat != null)
                {
                    int index        = 1;
                    var featNameBase = $"Stock Block Round for config {(part as IModelDoc2).IGetActiveConfiguration().Name}";
                    var featName     = featNameBase;
                    while ((part as IModelDoc2).FeatureManager.IsNameUsed(
                               (int)swNameType_e.swFeatureName, featName))
                    {
                        featName = featNameBase + index++;
                    }

                    feat.Name = featName;
                }
            }
        }
Esempio n. 20
0
 private void GetTesselationDataFromPart(IPartDoc part, out float[] tessTriangs, out float[] tessNorms)
 {
     tessTriangs = part.GetTessTriangles(true) as float[];
     tessNorms   = part.GetTessNorms() as float[];
 }
Esempio n. 21
0
        //public static bool IsSheetMetal(string swPartPath)
        //{
        //    return new SheetMetal(swPartPath).ExistSheetMetalDM();
        //}

        public static bool IsSheetMetal(IPartDoc swPart)
        {
            return(Dxf.IsSheetMetalPart(swPart));
        }
Esempio n. 22
0
        private void FixOneBand(string config)
        {
            try
            {
                IPartDoc swPart = (IPartDoc)modelDoc;

                _swFeat = (Feature)modelDoc.FirstFeature();
                Feature flatPattern = null;

                while ((_swFeat != null))
                {
                    if (_swFeat.GetTypeName() == "FlatPattern")
                    {
                        flatPattern = _swFeat;
                        flatPattern.Select(true);
                        swPart.EditUnsuppress();
                        flatPattern.DeSelect();

                        _swSubFeat = (Feature)flatPattern.GetFirstSubFeature();

                        while ((_swSubFeat != null))
                        {
                            if (_swSubFeat.GetTypeName() == "UiBend")
                            {
                                object[] fisrtParent = _swSubFeat.GetParents();
                                if (fisrtParent != null)
                                {
                                    foreach (var item in fisrtParent)
                                    {
                                        Feature swFirstParentFeat    = (Feature)item;
                                        bool    SuppressedEdgeFlange = IsSuppressedEdgeFlange(swFirstParentFeat.GetOwnerFeature().Name);

                                        PartBendInfos.Add
                                        (
                                            new PartBendInfo
                                        {
                                            EdgeFlange  = _swSubFeat.Name,
                                            OneBend     = swFirstParentFeat.GetOwnerFeature().Name,
                                            IsSupressed = SuppressedEdgeFlange,
                                            Config      = config
                                        }
                                        );
                                    }
                                }
                            }
                            _swSubFeat = (Feature)_swSubFeat.GetNextSubFeature();
                        }
                    }

                    _swFeat = (Feature)_swFeat.GetNextFeature();

                    foreach (var item in PartBendInfos)
                    {
                        if (!item.IsSupressed)
                        {
                            modelDoc.Extension.SelectByID2(item.EdgeFlange, "BODYFEATURE", 0, 0, 0, false, 0, null, 0);
                            SelectionMgr swSelMgr = (SelectionMgr)modelDoc.SelectionManager;
                            Feature      swFeat   = (Feature)swSelMgr.GetSelectedObject6(1, -1);
                            swPart.EditUnsuppress();
                        }
                    }
                }
                //modelDoc.EditRebuild3();
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message + "\t StackTrace " + ex.StackTrace);
            }
        }
Esempio n. 23
0
        private IEnumerable <IBody2> ConvertBodiesContext(IEnumerable <IBody2> inputBodies, IPartDoc context)
        {
            var partBodies = (context.GetBodies2((int)swBodyType_e.swAllBodies, false) as object[]).Cast <IBody2>();

            return(inputBodies.Select(b =>
            {
                var corrBody = partBodies.FirstOrDefault(
                    pb => pb.Name.Equals(b.Name, StringComparison.CurrentCultureIgnoreCase));

                if (corrBody == null)
                {
                    throw new NullReferenceException(string.Format("Failed to find the corresponding body of {0}", b.Name));
                }

                return corrBody;
            }).ToArray());
        }
Esempio n. 24
0
 public Part(IPartDoc swPart, IFeature relatedFeature) : base(relatedFeature)
 {
     this.swPart = swPart;
 }
Esempio n. 25
0
 public Part(IPartDoc part) : this(part, null)
 {
 }
Esempio n. 26
0
 internal SwPart(IPartDoc part, ISldWorks app, ILogger logger)
     : base((IModelDoc2)part, app, logger)
 {
     Part = part;
 }
Esempio n. 27
0
        /// <summary>
        ///  Method which the encapsulates proccess building dxf view on based SolidWorks part.
        /// </summary>
        /// <param name="partPath">path to sorce part file</param>
        /// <param name="idPdm">id in pdm system</param>
        /// <param name="version">current or last version build file</param>
        /// <param name="includeNonSheetParts">set whether you want build dxf views from non sheet parts</param>
        /// <returns></returns>
        private bool Build(string partPath, int idPdm, int version, bool includeNonSheetParts)
        {
            // callback message code from solidWorks
            // int error = 0, warnings = 0;

            MessageObserver.Instance.SetMessage("Start build Dxf file", MessageType.System);

            bool isSave = false;

            try
            {
                ModelDoc2 modelDoc = null;
                if (!string.IsNullOrEmpty(partPath))
                {
                    try
                    {
                        modelDoc = SolidWorksAdapter.OpenDocument(partPath, swDocumentTypes_e.swDocPART);// SolidWorksAdapter.SldWoksAppExemplare.OpenDoc6(partPath, (int)  swDocumentTypes_e.swDocPART , (int)swOpenDocOptions_e.swOpenDocOptions_Silent, emptyConfigyration, error, warnings);

                        //modelDoc = SolidWorksAdapter.SldWoksAppExemplare.IActiveDoc2;

                        MessageObserver.Instance.SetMessage("\tOpened document " + Path.GetFileName(partPath), MessageType.System);
                        // Проверяет наличие дерева постоения в моделе.
                        if (modelDoc == null)
                        {
                            return(isSave);
                        }
                    }
                    catch (Exception exception)
                    {
                        MessageObserver.Instance.SetMessage("\tFailed open SolidWorks document; message exception {" + exception.ToString() + " }", MessageType.Error);
                        throw exception;
                    }
                }
                bool isSheetmetal = true;
                //modelDoc.ForceRebuild3(false);

                IPartDoc part = (IPartDoc)modelDoc;
                if (!SolidWorksAdapter.IsSheetMetalPart(part))
                {
                    isSheetmetal = false;
                    if (!includeNonSheetParts) // disable build  no sheet metal parts if IsSheetMetalPart = false, and return
                    {
                        try
                        {
                            //SolidWorksAdapter.SldWoksAppExemplare.CloseDoc(modelDoc.GetTitle().ToLower().Contains(".sldprt") ? modelDoc.GetTitle() : modelDoc.GetTitle() + ".sldprt");
                            if (modelDoc != null)
                            {
                                SolidWorksAdapter.SldWoksAppExemplare.CloseDoc(modelDoc.GetTitle());
                            }
                            //SolidWorksAdapter.SldWoksAppExemplare.ExitApp();
                        }
                        catch (Exception ex)
                        {
                            MessageObserver.Instance.SetMessage("Неудалось закрыть файл " + ex.Message);
                        }
                        return(isSave);
                    }
                }
                string[] swModelConfNames2 = (string[])modelDoc.GetConfigurationNames();


                var configurations = from name in swModelConfNames2
                                     let config = (Configuration)modelDoc.GetConfigurationByName(name)
                                                  where !config.IsDerived()
                                                  select name;

                MessageObserver.Instance.SetMessage("\t got configuration " + configurations.Count() + " for opened document. Statrt bust configurations", MessageType.System);

                foreach (var eachConfiguration in configurations)
                {
                    modelDoc.ShowConfiguration2(eachConfiguration);
                    //modelDoc.Visible = true;
                    //modelDoc.EditRebuild3();

                    MessageObserver.Instance.SetMessage("\t Show configuration " + eachConfiguration, MessageType.System);
                    if (isSheetmetal)
                    {
                        Bends bends = Bends.Create(modelDoc, eachConfiguration);
                        bends.Fix();

                        MessageObserver.Instance.SetMessage("\t Fix bends " + eachConfiguration, MessageType.System);
                    }

                    byte[] dxfByteCode;
                    DXF    dxf;

                    if (!Directory.Exists(DxfFolder))
                    {
                        Directory.CreateDirectory(DxfFolder);
                    }

                    if (DxfFolder != null && DxfFolder != string.Empty)
                    {
                        dxf = new DXF(DxfFolder);
                    }
                    else
                    {
                        dxf = new DXF();
                    }

                    isSave = dxf.ConvertToDXF(eachConfiguration, modelDoc, out dxfByteCode, isSheetmetal);

                    var dataToExport = CutList.GetDataToExport(modelDoc);

                    if (isSave)
                    {
                        MessageObserver.Instance.SetMessage("\t" + eachConfiguration + " succsess building. Add to result list", MessageType.Success);
                        // конфигурация получена при выполнении GetDataToExport
                        try
                        {
                            dataToExport.DXFByte       = dxfByteCode;
                            dataToExport.Configuration = eachConfiguration;
                            dataToExport.IdPdm         = idPdm;
                            dataToExport.Version       = version;
                            if (FinishedBuilding != null)
                            {
                                FinishedBuilding(dataToExport);
                            }
                        }
                        catch (Exception exception)
                        {
                            MessageObserver.Instance.SetMessage("\tFailed at notification about finished; message exception {" + exception.ToString() + " }", MessageType.Error);
                        }
                    }
                }
                SolidWorksAdapter.SldWoksAppExemplare.CloseDoc(modelDoc.GetTitle().ToLower().Contains(".sldprt") ? modelDoc.GetTitle() : modelDoc.GetTitle() + ".sldprt"); // out in func...
                //SolidWorksAdapter.SldWoksAppExemplare.ExitApp( );
            }

            catch (Exception ex)
            {
                MessageObserver.Instance.SetMessage("\tFailed build dxf; message exception {" + ex.ToString() + " }", MessageType.Error);
                throw ex;
            }
            return(isSave);
        }
Esempio n. 28
0
                static bool IsSheetMetalPart(IPartDoc swPart)
                {
                    var isSheet = false;

                    //var mod = (IModelDoc2)swPart;

                    var vBodies = swPart.GetBodies2((int)swBodyType_e.swSolidBody, false);

                    foreach (Body2 vBody in vBodies)
                    {
                        try
                        {
                            var isSheetMetal = vBody.IsSheetMetal();
                            if (!isSheetMetal) continue;
                            isSheet = true;
                        }
                        catch
                        {
                            isSheet = false;
                        }
                    }

                    return isSheet;
                }
Esempio n. 29
0
        private static BodyTessellation GetBodyMesh(IBody2 body, IPartDoc partDoc, ITessellation tessellation, long?overrideColor)
        {
            var bodyTessellation = new BodyTessellation();

            if (overrideColor.HasValue)
            {
                bodyTessellation.FaceColors.Add(overrideColor.Value);
            }
            else
            {
                double[] bodyColorArray = null;
                var      features       = (object[])body.GetFeatures();
                if (features != null)
                {
                    foreach (IFeature feature in features.Reverse())
                    {
                        bodyColorArray =
                            (double[])feature.GetMaterialPropertyValues2(
                                (int)swInConfigurationOpts_e.swThisConfiguration, null);
                        if (bodyColorArray[0] == -1
                            ) // All -1s are returned by features that don't assign color.
                        {
                            bodyColorArray = null;
                        }

                        if (bodyColorArray != null)
                        {
                            break;
                        }
                    }
                }

                if (bodyColorArray == null)
                {
                    bodyColorArray = (double[])body.MaterialPropertyValues2;
                }

                if (bodyColorArray == null)
                {
                    bodyColorArray = (double[])partDoc.MaterialPropertyValues;
                }

                var bodyColor = ColorArrayToColor(bodyColorArray);

                bodyTessellation.FaceColors.Add(bodyColor);
            }

            var coloredFaces = new Dictionary <IFace2, long>();
            var faceCount    = 0;

            foreach (IFace2 face in (object[])body.GetFaces())
            {
                faceCount++;
                var colorArray = (double[])face.MaterialPropertyValues;
                if (colorArray != null)
                {
                    coloredFaces[face] = ColorArrayToColor(colorArray);
                }
            }

            if (coloredFaces.Count < faceCount)
            {
                for (var i = 0; i < tessellation.GetVertexCount(); i++)
                {
                    bodyTessellation.VertexPositions.Add((double[])tessellation.GetVertexPoint(i));
                    bodyTessellation.VertexNormals.Add((double[])tessellation.GetVertexNormal(i));
                }

                foreach (IFace2 face in (object[])body.GetFaces())
                {
                    if (coloredFaces.ContainsKey(face))
                    {
                        continue;
                    }

                    foreach (var facet in (int[])tessellation.GetFaceFacets(face))
                    {
                        var vertexIndices = new List <int>();
                        foreach (var fin in (int[])tessellation.GetFacetFins(facet))
                        {
                            vertexIndices.Add(((int[])tessellation.GetFinVertices(fin))[0]);
                        }

                        bodyTessellation.Faces.Add(new FaceStruct {
                            Color   = 0,
                            Vertex1 = vertexIndices[0],
                            Vertex2 = vertexIndices[1],
                            Vertex3 = vertexIndices[2],
                        });
                    }
                }
            }

            foreach (var pair in coloredFaces)
            {
                var colorIndex = bodyTessellation.FaceColors.IndexOf(pair.Value);
                if (colorIndex == -1)
                {
                    bodyTessellation.FaceColors.Add(pair.Value);
                    colorIndex = bodyTessellation.FaceColors.Count - 1;
                }

                foreach (var facet in (int[])tessellation.GetFaceFacets(pair.Key))
                {
                    var vertexIndices = new List <int>();
                    foreach (var fin in (int[])tessellation.GetFacetFins(facet))
                    {
                        vertexIndices.Add(((int[])tessellation.GetFinVertices(fin))[0]);
                    }

                    bodyTessellation.Faces.Add(
                        new FaceStruct {
                        Color   = colorIndex,
                        Vertex1 = bodyTessellation.VertexPositions.Count,
                        Vertex2 = bodyTessellation.VertexPositions.Count + 1,
                        Vertex3 = bodyTessellation.VertexPositions.Count + 2
                    });

                    bodyTessellation.VertexPositions.Add(
                        (double[])tessellation.GetVertexPoint(vertexIndices[0]));
                    bodyTessellation.VertexPositions.Add(
                        (double[])tessellation.GetVertexPoint(vertexIndices[1]));
                    bodyTessellation.VertexPositions.Add(
                        (double[])tessellation.GetVertexPoint(vertexIndices[2]));

                    bodyTessellation.VertexNormals.Add(
                        (double[])tessellation.GetVertexNormal(vertexIndices[0]));
                    bodyTessellation.VertexNormals.Add(
                        (double[])tessellation.GetVertexNormal(vertexIndices[1]));
                    bodyTessellation.VertexNormals.Add(
                        (double[])tessellation.GetVertexNormal(vertexIndices[2]));
                }
            }
            return(bodyTessellation);
        }
Esempio n. 30
0
 public IPartDocObject(IPartDoc IPartDocinstance)
 {
     IPartDocInstance = IPartDocinstance;
 }
 internal DistanceColorContour(IPartDoc part)
 {
     m_Part = part;
 }
Esempio n. 32
0
        private static bool IsSheetMetalPart(IPartDoc swPart)
        {
            var isSheetMetal = false;
            try
            {
                var vBodies = swPart.GetBodies2((int) swBodyType_e.swSolidBody, false);

                foreach (Body2 vBody in vBodies)
                {
                    isSheetMetal = vBody.IsSheetMetal();
                }
                return isSheetMetal;
            }
            catch (Exception)
            {
                //  
            }
            return isSheetMetal;
        }