SolidWorks机械工程师网——最大的SolidWorks学习平台

 找回密码
 立即注册

QQ登录

只需一步,快速开始

好品数字
好品数字
查看: 452|回复: 6
打印 上一主题 下一主题

请问如何获得特定装配特征中零件的名称,装配面?

[复制链接]

8

主题

206

帖子

26

金币

侠客

Rank: 3Rank: 3Rank: 3

积分
246
QQ
跳转到指定楼层
楼主
发表于 2011-8-26 19:51:26 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
已知条件:
特定装配特征
求:
该特征对应的零件的名称,装配面‘点’线(就是咱们建立装配特征时候的逆向)?
举例:
同心特征R,如何得到建立该特征的两个参考(如:A零件表面的圆柱体,B零件的轴线,这两个建立了同心特征R,求vb得到A零件表面的圆柱体,B零件的轴线)
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 转播转播 分享教程|习题|模型|技巧 点赞点赞20830 拍砖拍砖854
SolidWorks机械工程师网
提示:建议使用谷歌浏览器浏览本网站!如单击这里下载!否则,可能无法下载附件文件!(支持大多数版本的谷歌浏览器,支持360和QQ浏览器的极速模式,即谷歌内核模式,使用IE和Edge浏览器,浏览个别网页以及下载文件时,会误报“***不安全”,此时需要单击“继续访问此不安全站点(不推荐)”才可以继续下载,另外,本网站不含任何不安全的文件,已联系微软公司解决,纯属IE和Edge浏览器误报)
回复

使用道具 举报

14

主题

219

帖子

27

金币

侠客

Rank: 3Rank: 3Rank: 3

积分
263
QQ
沙发
发表于 2011-8-26 20:03:54 | 只看该作者
自己顶一下。
今天试试用录制,查看结果不是自己想要的。用选定配合后选择放大选定范围,出来的是boolstatus = Part.Extension.SelectByID2("平行1", "MATE", 0, 0, 0, False, 0, Nothing, 0)
Part.ViewZoomToSelection对配合中选择一个面进行面颜色,并没有记录。好像对用户输入和颜色不记录有本书上说过。看来要用别的方法了。实在不行就得在设计每个装配的时候起个独特的名字。晕啊。
SolidWorks机械工程师网
提示:建议使用谷歌浏览器浏览本网站!如单击这里下载!否则,可能无法下载附件文件!(支持大多数版本的谷歌浏览器,支持360和QQ浏览器的极速模式,即谷歌内核模式,使用IE和Edge浏览器,浏览个别网页以及下载文件时,会误报“***不安全”,此时需要单击“继续访问此不安全站点(不推荐)”才可以继续下载,另外,本网站不含任何不安全的文件,已联系微软公司解决,纯属IE和Edge浏览器误报)
回复 支持 反对

使用道具 举报

9

主题

231

帖子

22

金币

侠客

Rank: 3Rank: 3Rank: 3

积分
279
QQ
板凳
发表于 2011-8-26 20:12:41 | 只看该作者
  
记录不能实现你的需求,现正消化理解下面内容,看是否能理解到位.
SolidWorks2003 二次开发里面第六章
SW API 第七章
--------------------
SolidWorks机械工程师网
回复 支持 反对

使用道具 举报

15

主题

229

帖子

35

金币

侠客

Rank: 3Rank: 3Rank: 3

积分
278
QQ
地板
发表于 2011-8-26 20:13:10 | 只看该作者
把这段程序消化理解了,问题会解决.
    '------------------------------------------------'
    ' Preconditions: Assembly is open and an assembly mate is selected.
    '
    ' Postconditions: Selected assembly mate is edited.
    '-----------------------------------------------
    Option Explicit
    Public Enum swMateType_e
        swMateCOINCIDENT = 0
        swMateCONCENTRIC = 1
        swMatePERPENDICULAR = 2
        swMatePARALLEL = 3
        swMateTANGENT = 4
        swMateDISTANCE = 5
        swMateANGLE = 6
        swMateUNKNOWN = 7
        swMateSYMMETRIC = 8
        swMateCAMFOLLOWER = 9
        swMateGEAR = 10
    End Enum
    Public Enum swMateAlign_e
        swMateAlignALIGNED = 0
        swMateAlignANTI_ALIGNED = 1
        swMateAlignCLOSEST = 2
    End Enum
    Public Enum swMateEntity2ReferenceType_e
        swMateEntity2ReferenceType_Point = 0
        swMateEntity2ReferenceType_Line = 1
        swMateEntity2ReferenceType_Circle = 2
        swMateEntity2ReferenceType_Plane = 3
        swMateEntity2ReferenceType_Cylinder = 4
        swMateEntity2ReferenceType_Sphere = 5
        swMateEntity2ReferenceType_Set = 6
        swMateEntity2ReferenceType_Cone = 7
        swMateEntity2ReferenceType_SweptSurface = 8
        swMateEntity2ReferenceType_MultipleSurface = 9
        swMateEntity2ReferenceType_GenSurface = 10
        swMateEntity2ReferenceType_Ellipse = 11
        swMateEntity2ReferenceType_GeneralCurve = 12
        swMateEntity2ReferenceType_UNKNOWN = 13
    End Enum
    Public Enum swAddMateError_e
        swAddMateError_ErrorUknown = 0
        swAddMateError_NoError = 1
        swAddMateError_IncorrectMateType = 2
        swAddMateError_IncorrectAlignment = 3
        swAddMateError_IncorrectSelections = 4
        swAddMateError_OverDefinedAssembly = 5
    End Enum
    Function SelectMateEntity( _
        swApp As SldWorks.SldWorks, _
        swModel As SldWorks.ModelDoc2, _
        swMateEnt As SldWorks.MateEntity2, _
        nMark As Long) As Boolean
        Dim swEnt                   As SldWorks.Entity
        Dim swSelMgr                As SldWorks.SelectionMgr
        Dim swSelData               As SldWorks.SelectData
        Dim bRet                    As Boolean
        Select Case swMateEnt.ReferenceType
            Case swMateEntity2ReferenceType_Point, _
                    swMateEntity2ReferenceType_Line, _
                    swMateEntity2ReferenceType_Circle, _
                    swMateEntity2ReferenceType_Plane, _
                    swMateEntity2ReferenceType_Cylinder, _
                    swMateEntity2ReferenceType_Sphere, _
                    swMateEntity2ReferenceType_Cone, _
                    swMateEntity2ReferenceType_SweptSurface
                Set swSelMgr = swModel.SelectionManager
                Set swSelData = swSelMgr.CreateSelectData
                Set swEnt = swMateEnt.Reference: Debug.Assert Not swEnt Is Nothing
                swSelData.Mark = nMark
                bRet = swEnt.Select4(True, swSelData): Debug.Assert bRet
                SelectMateEntity = bRet
                Exit Function
            Case swMateEntity2ReferenceType_Set, _
                    swMateEntity2ReferenceType_MultipleSurface, _
                    swMateEntity2ReferenceType_GenSurface, _
                    swMateEntity2ReferenceType_Ellipse, _
                    swMateEntity2ReferenceType_GeneralCurve, _
                    swMateEntity2ReferenceType_UNKNOWN
                Debug.Print False
            Case Else
                Debug.Print False
        End Select
        SelectMateEntity = False
    End Function
    Sub main()
        Dim swApp                   As SldWorks.SldWorks
        Dim swModel                 As SldWorks.ModelDoc2
        Dim swAssy                  As SldWorks.AssemblyDoc
        Dim swSelMgr                As SldWorks.SelectionMgr
        Dim swFeat                  As SldWorks.Feature
        Dim swMate                  As SldWorks.Mate2
        Dim swDispDim               As SldWorks.DisplayDimension
        Dim swDim                   As SldWorks.Dimension
        Dim sVarType                As String
        Dim nVarFactor              As Double
        Dim nMateDist               As Double
        Dim nNumMateEnt             As Long
        Dim swMateEnt()             As SldWorks.MateEntity2
        Dim vMateEntPar             As Variant
        Dim swComp                  As SldWorks.Component2
        Dim nNewMateAlign           As Long
        Dim nRetVal                 As Long
        Dim i                       As Long
        Dim bRet                    As Boolean
        Dim vDimValueArr            As Variant
       
        Set swApp = Application.SldWorks
        Set swModel = swApp.ActiveDoc
        Set swAssy = swModel
        Set swSelMgr = swModel.SelectionManager
        Set swFeat = swSelMgr.GetSelectedObject5(1)
        Set swMate = swFeat.GetSpecificFeature2
        Set swDispDim = swMate.DisplayDimension2(0)
        Debug.Print "File = " & swModel.GetPathName
        Debug.Print "  " & swFeat.Name
        Debug.Print "    Type           = " & swMate.Type
        Debug.Print "    Alignment      = " & swMate.Alignment
        Debug.Print "    CanBeFlipped   = " & swMate.CanBeFlipped
       
        Select Case swMate.Type
            Case swMateANGLE
                sVarType = " deg"
                nVarFactor = 57.3
            Case swMateDISTANCE
                sVarType = " mm"
                nVarFactor = 1000#
            Case swMateGEAR
                sVarType = " ratio"
                nVarFactor = 1#
        End Select
        If swMateANGLE = swMate.Type Or swMateDISTANCE = swMate.Type Then
            Debug.Print "    MaxVar         = " & swMate.MaximumVariation * nVarFactor & sVarType
            Debug.Print "    MinVar         = " & swMate.MinimumVariation * nVarFactor & sVarType
        End If
        If Not swDispDim Is Nothing Then
            Set swDim = swDispDim.GetDimension
            vDimValueArr = swDim.GetSystemValue3(swThisConfiguration, Empty)
            Debug.Print "    Dim Value      = " & vDimValueArr(0) * nVarFactor & sVarType
        End If
        nNumMateEnt = swMate.GetMateEntityCount
        ReDim swMateEnt(nNumMateEnt)
        For i = 0 To nNumMateEnt - 1
            Set swMateEnt(i) = swMate.MateEntity(i)
            Set swComp = swMateEnt(i).ReferenceComponent
            vMateEntPar = swMateEnt(i).EntityParams
            Debug.Print "      RefType(" & i & ")   = " & swMateEnt(i).ReferenceType
            Debug.Print "        Component          = " & swComp.Name2 & " (" & swComp.ReferencedConfiguration & ") --> " & swComp.GetPathName
            Debug.Print "        Point              = (" & vMateEntPar(0) * 1000# & ", " & vMateEntPar(1) * 1000# & ", " & vMateEntPar(2) * 1000# & ") mm"
            Debug.Print "        Vector             = (" & vMateEntPar(3) & ", " & vMateEntPar(4) & ", " & vMateEntPar(5) & ")"
            Debug.Print "        Radius 1           = " & vMateEntPar(6) * 1000# & " mm"
            Debug.Print "        Radius 2           = " & vMateEntPar(7) * 1000# & " mm"
        Next i
        Select Case swMate.Type
            ' Cannot change alignment on these mate types
            Case swMateGEAR
                Exit Sub
        End Select
        If swMateAlignALIGNED = swMate.Alignment Then
            nNewMateAlign = swMateAlignANTI_ALIGNED
        Else
            If swMateAlignANTI_ALIGNED = swMate.Alignment Then
                nNewMateAlign = swMateAlignALIGNED
            Else
                ' Closest alignment, so changing alignment does not make sense
                Debug.Assert swMateAlignCLOSEST = swMate.Alignment
                Exit Sub
            End If
        End If
        swModel.ClearSelection2 True
        For i = 0 To nNumMateEnt - 1
            '   AssemblyDoc::EditMate2 requires mate entities
            '   to be selected with mark of 1 except for:
            '       swMateCAMFOLLOWER
            '           cam face              --> 1
            '           cam follower face     --> 8
            '       swMateSYMMETRIC
            '           symmetry faces        --> 1
            '           symmetry plane        --> 4
            bRet = SelectMateEntity(swApp, swModel, swMateEnt(i), 1): Debug.Assert bRet
        Next i
        ' AssemblyDoc::EditMate2 requires mate feature to be last selected object
        ' mark is ignored
        bRet = swFeat.Select2(True, 0): Debug.Assert bRet
        swAssy.EditMate2 _
            swMate.Type, _
            nNewMateAlign, _
            True, _
            nMateDist, _
            swMate.MaximumVariation, _
            swMate.MinimumVariation, _
            0#, _
            0#, _
            nMateDist, _
            swMate.MaximumVariation, _
            swMate.MinimumVariation, nRetVal
        ' Do not assert because may overdefine assembly or other error
        'Debug.Assert swAddMateError_NoError = nRetVal
        ' Do not assert because assemlby may have rebuild errors
        ' due to changing mate alignment
        bRet = swModel.EditRebuild3: 'Debug.Assert bRet
    End Sub
    '------------------------------------------------

复制代码
SolidWorks机械工程师网
回复 支持 反对

使用道具 举报

8

主题

231

帖子

21

金币

侠客

Rank: 3Rank: 3Rank: 3

积分
272
QQ
5#
发表于 2011-8-26 20:13:18 | 只看该作者

   经典案例图书

先mark一下。
最近老是稀里糊涂。
SolidWorks机械工程师网
回复 支持 反对

使用道具 举报

5

主题

229

帖子

13

金币

侠客

Rank: 3Rank: 3Rank: 3

积分
248
QQ
6#
发表于 2011-8-26 20:15:26 | 只看该作者
    http://help.SolidWorks.com/2011/English/api/sldworksapi/Get_Mate_Reference_Properties_Example_CSharp.htm

    Get Mate Reference Properties Example (C#)
    This example shows how to get mate reference properties.
    //----------------------------------------------------------------------------
    // Preconditions:
    // 1. Open a part or assembly document that contains a mate reference named
    // Default-<1>.
    // 2. Rename the namespace to match the name of your C# project.
    //
    // Postconditions: Inspect the Immediate window.
    // ---------------------------------------------------------------------------
    using SolidWorks.Interop.sldworks;
    using SolidWorks.Interop.swconst;
    using System;
    using System.Diagnostics;
    namespace MateReferences_CSharp.csproj
    {
    partial class SolidWorksMacro
    {
    public void Main()
    {
    MateReference swMateReference = default(MateReference);
    Feature swFeature = default(Feature);
    object mateRefObj = null;
    int mateRefEntityType = 0;
    ModelDoc2 swModel = default(ModelDoc2);
    ModelDocExtension swModelDocExt = default(ModelDocExtension);
    SelectionMgr swSelMgr = default(SelectionMgr);
    string strMateReferencename = null;
    int nCount = 0;
    int refEntType = 0;
    int mateRefAlignment = 0;
    bool boolstatus = false;
    swModel = (ModelDoc2)swApp.ActiveDoc;
    swModelDocExt = swModel.Extension;
    swSelMgr = (SelectionMgr)swModel.SelectionManager;
    swModel.ClearSelection2(true);
    boolstatus = swModelDocExt.SelectByID2(&quot;Default-<1>&quot;, &quot;POSGROUP&quot;, 0, 0, 0, false, 0, null, 0);
    swFeature = (Feature)swSelMgr.GetSelectedObject6(1, -1);
    swMateReference = (MateReference)swFeature.GetSpecificFeature2();
    swModel.ClearSelection2(true);
    // Get the name of the mate reference
    strMateReferencename = swMateReference.Name;
    Debug.Print(&quot;Name of mate reference is &quot; + strMateReferencename);
    // Get the number of reference entities in the mate reference
    nCount = swMateReference.ReferenceEntityCount;
    Debug.Print(&quot;Number of mate reference entities is &quot; + nCount);
    // Get the mate reference type for the primary mate
    // entity in the selected mate reference
    refEntType = swMateReference.get_ReferenceType(0);
    Debug.Print(&quot;Mating type of primary mate entity is &quot; + refEntType);
    // Get the mate reference alignment for the
    // mate reference entity in the selected mate reference
    mateRefAlignment = swMateReference.get_ReferenceAlignment(0);
    Debug.Print(&quot;Alignment of primary mate entity is &quot; + mateRefAlignment);
    // Get the mate reference entity in the mate reference
    mateRefObj = swMateReference.get_ReferenceEntity2(0);
    // Get the mate reference entity type
    mateRefEntityType = swMateReference.get_ReferenceEntityType(0);
    Debug.Print(&quot;Entity type of primary mate entity is &quot; + mateRefEntityType);
    // QueryInterface the returned object as a Face, if a face
    if (mateRefEntityType == (int)swSelectType_e.swSelFACES)
    {
    Face2 mateRefFace = default(Face2);
    mateRefFace = (Face2)mateRefObj;
    Debug.Print(&quot;Primary mate entity is a face with area = &quot; + mateRefFace.GetArea());
    }
    swModel.ClearSelection2(true);
    }
    public SldWorks swApp;
    }
    }
    c的还要弄成vb的。晕了。还是cad的lisp比较学。

复制代码
SolidWorks机械工程师网
回复 支持 反对

使用道具 举报

9

主题

227

帖子

15

金币

侠客

Rank: 3Rank: 3Rank: 3

积分
243
7#
发表于 2011-8-26 20:15:51 | 只看该作者

   经典案例图书

http://help.SolidWorks.com/2011/English/api/sldworksapi/Get_Mate_Reference_Properties_Example_VB.htm
vb 来也。哈哈。
SolidWorks机械工程师网
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭 卷起
关闭 卷起

手机版|小黑屋| GMT+8, 2024-5-21 18:00 , Processed in 0.244056 second(s), 41 queries .

SolidWorks机械工程师网 ( 鲁ICP备14025122号-2 ) 鲁公网安备 37028502190335号

声明:本网言论纯属发表者个人意见,与本网立场无关。
如涉版权,可发邮件: admin@swbbsc.com

快速回复 返回顶部 返回列表