C # API de desarrollo secundario de SolidWorks --- recorra todas las dimensiones editables de las piezas

Recientemente, un estudiante universitario hizo una pregunta sobre cómo obtener toda la información de tamaño editable en una pieza. Incluidas todas las características y dimensiones del boceto.
El blog anterior solo escribió sobre cómo atravesar las características y las dimensiones en los dibujos.
Al verificar la api, se encuentra que este es el mismo que el tamaño marcado en el dibujo. Úselo directamente:
primero mire el resultado:
partes:
Inserte la descripción de la imagen aquí

Inserte la descripción de la imagen aquí

        /// <summary>
        /// 遍历特征
        /// </summary>
        /// <param name="thisFeat"></param>
        /// <param name="isTopLevel"></param>
        public static void TraverseFeatures(Feature thisFeat, bool isTopLevel, bool isShowDimension = false)
        {
    
    
            Feature curFeat = default(Feature);
            curFeat = thisFeat;

            while ((curFeat != null))
            {
    
    
                //输出特征名称
                Debug.Print(curFeat.Name);
                if (isShowDimension == true) ShowDimensionForFeature(curFeat);

                Feature subfeat = default(Feature);
                subfeat = (Feature)curFeat.GetFirstSubFeature();

                while ((subfeat != null))
                {
    
    
                    //if (isShowDimension == true) ShowDimensionForFeature(subfeat);
                    TraverseFeatures(subfeat, false);
                    Feature nextSubFeat = default(Feature);
                    nextSubFeat = (Feature)subfeat.GetNextSubFeature();
                    subfeat = nextSubFeat;
                    nextSubFeat = null;
                }

                subfeat = null;

                Feature nextFeat = default(Feature);

                if (isTopLevel)
                {
    
    
                    nextFeat = (Feature)curFeat.GetNextFeature();
                }
                else
                {
    
    
                    nextFeat = null;
                }

                curFeat = nextFeat;
                nextFeat = null;
            }
        }

        /// <summary>
        /// 遍历零件中的所有特征
        /// </summary>
        /// <param name="feature"></param>
        public static void ShowDimensionForFeature(Feature feature)
        {
    
    
            var thisDisplayDim = (DisplayDimension)feature.GetFirstDisplayDimension();

            while (thisDisplayDim != null)
            {
    
    
                var dimen = (Dimension)thisDisplayDim.GetDimension();

                Debug.Print($"---特征 {feature.Name} 尺寸-->" + dimen.GetNameForSelection() + "-->" + dimen.Value);

                thisDisplayDim = (DisplayDimension)feature.GetNextDisplayDimension(thisDisplayDim);
            }
        }

El código se ha cargado, recójalo.
Inserte la descripción de la imagen aquí

Supongo que te gusta

Origin blog.csdn.net/zengqh0314/article/details/107683013
Recomendado
Clasificación