QQ登录

只需一步,快速开始

登录 立即注册

如何遍历零件→草图→尺寸.

[复制链接]
查看: 4380|回复: 17
ning58 发表于 2011-8-11 13:24:53
Api论坛人气不够,在这里看是否能解决问题?

Sokidowrks API 二次开发的书中,给出的是遍历特征树的示例.
Set swFeat = swPart.FirstFeature

    Do While Not swFeat Is Nothing
        FeatTypeName = swFeat.GetTypeName
        Debug.Print FeatTypeName
       ......
  Loop
零件什么都没画时其结果是
DetailCabinet
CommentsFolder
DocsFolder
SurfaceBodyFolder
SolidBodyFolder
MaterialFolder
EnvFolder
RefPlane
RefPlane
RefPlane
OriginProfileFeature
----------------------
添加了两个蓝图后.增加了两项
ProfileFeature
ProfileFeature
----------------------------------------------
由此可以判断
Set swFeat = swPart.FirstFeature→如何改就能遍历草图的内容.
谢谢.
楼主  ning58 发表于 2011-8-11 14:17:43
这是SW帮助文件中的一个草图示例
草图→Set swSketch = swModel.GetActiveSketch2

    Dim swApp As SldWorks.SldWorks
    Dim swModel As SldWorks.ModelDoc2
    Dim swSketch As SldWorks.Sketch
    Dim swFeat                  As SldWorks.Feature
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    ' Get the open sketch
    Set swSketch = swModel.GetActiveSketch2
    Set swFeat = swSketch
    ' Change the name of the open sketch to CircleSketch
    swFeat.Name = "CircleSketch"
楼主  ning58 发表于 2011-8-11 14:28:40
本帖最后由 ning58 于 2011-8-29 15:05 编辑

帮助文件又一例
Public Enum swLineTypes_e
    swLF_VISIBLE = 0
    swLF_HIDDEN = 1
    swLF_SKETCH = 2
    swLF_DETAIL = 3
    swLF_SECTION = 4
    swLF_DIMENSION = 5
    swLF_CENTER = 6
    swLF_HATCH = 7
    swLF_TANGENT = 8
End Enum
Sub main()
    Dim swApp                   As SldWorks.SldWorks
    Dim swModel                 As SldWorks.ModelDoc2
    Dim swPart                  As SldWorks.PartDoc
    Dim swSelMgr                As SldWorks.SelectionMgr
    Dim swFeat                  As SldWorks.Feature
    Dim swSketch                As SldWorks.Sketch
    Dim NumArcs                 As Long
    Dim vArcs                   As Variant
    Dim i                       As Variant
    Dim bRet                    As Boolean
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swPart = swModel
    Set swSelMgr = swModel.SelectionManager
    Set swFeat = swSelMgr.GetSelectedObject5(1)
    Set swSketch = swFeat.GetSpecificFeature
    NumArcs = swSketch.GetArcCount
    Debug.Print "Feature = " & swFeat.GetTypeName
    Debug.Print "  NumArcs = " & NumArcs
    Debug.Print ""
    vArcs = swSketch.GetArcs2
    If IsEmpty(vArcs) Then Exit Sub
    Debug.Assert UBound(vArcs) + 1 = 16 * NumArcs
    For i = 0 To NumArcs - 1
        Debug.Print "    Arc(" & i & ")"
        Debug.Print "      colour         = " & vArcs(16 * i + 0)
        Debug.Print "      type           = " & vArcs(16 * i + 1)
        Debug.Print "      font           = " & vArcs(16 * i + 2)
        Debug.Print "      width          = " & vArcs(16 * i + 3)
        Debug.Print "      layerID        = " & vArcs(16 * i + 4)
        Debug.Print "      layer override = " & vArcs(16 * i + 5)
        Debug.Print "      start          = (" & _
            vArcs(16 * i + 6) * 1000# & ", " & _
            vArcs(16 * i + 7) * 1000# & ", " & _
            vArcs(16 * i + 8) * 1000# & ") mm"
        Debug.Print "      end            = (" & _
            vArcs(16 * i + 9) * 1000# & ", " & _
            vArcs(16 * i + 10) * 1000# & ", " & _
            vArcs(16 * i + 11) * 1000# & ") mm"
        Debug.Print "      ctr            = (" & _
            vArcs(16 * i + 12) * 1000# & ", " & _
            vArcs(16 * i + 13) * 1000# & ", " & _
            vArcs(16 * i + 14) * 1000# & ") mm"
        Debug.Print "      RotDir         = " & _
            vArcs(16 * i + 15)
    Next i
End Sub

-------------------------
  1. Dim swApp As Object
  2. Dim Part As Object
  3. Dim SelMgr As Object
  4. Dim boolstatus As Boolean
  5. Dim longstatus As Long, longwarnings As Long
  6. Dim Feature As Object
  7. Sub main()

  8. Set swApp = Application.SldWorks
  9. Dim SwSketch As SldWorks.Sketch

  10. Set Part = swApp.ActiveDoc
  11. Set SelMgr = Part.SelectionManager
  12. boolstatus = Part.Extension.SelectByID2("草图1", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)
  13. 'boolstatus = Part.Extension.SelectByID2("草图2", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)
  14. 'boolstatus = Part.Extension.SelectByID2("草图3", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)
  15. Set swFeat = SelMgr.GetSelectedObject5(1)
  16.     Set SwSketch = swFeat.GetSpecificFeature
  17.     'NumArcs = SwSketch.GetArcCount
  18.     With SwSketch
  19.       'nn = .GetArcCount
  20.       nn = .GetLineCount
  21.       nn = .GetUserPointsCount
  22.       Debug.Print "Feature = " & swFeat.GetTypeName
  23. vArcs = SwSketch.GetUserPoints2

  24.     End With

  25. End Sub
复制代码
zangyou 发表于 2011-8-12 01:05:50
强力不懂!!!不过今后貌似要用到……
Gary 发表于 2011-8-15 00:25:26
高手
智诚科技——为客户提供一流的三维解决方案,更短的时间内, 设计更好的产品。
tianma 发表于 2011-8-15 08:23:35
支持一下
http://fans.SolidWorks.com.cn/blog/?387
花中禽兽 发表于 2011-8-15 10:45:44
估计这要学数据结构呢不然谁会啊!树这这种结构就比图简单点1
shelwin 发表于 2011-9-14 17:15:37
{:soso_e134:}强势围观
黑云飘絮 发表于 2011-9-18 15:45:17
直接秒杀我等普通用户,你是何居心啊。。
zaneyoung 发表于 2011-9-19 14:09:43
宏的运用。。看的头晕。。。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|京ICP备11009482号-2  

400 - 818 - 3535 (中国地区咨询电话) | 达索析统(上海)信息技术有限公司北京分公司

京ICP备11009482号-2 | 电话:01065362288

北京市朝阳区建国路79号华贸中心2号写字楼707-709室,邮编:100025

GMT+8, 2020-4-3 06:40 , Processed in 0.135585 second(s), 37 queries .

Copyright © 2002-2018 Dassault Systèmes - All rights reserved

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