solidworks二次開發--10--從example中尋找

來源:互聯網
上載者:User

solidworks的api協助還是很全面的,裡面有好多見簡單而有效程式,成天在api協助裡泡著,現在做程式的速度是越來越快。好像當年成天在excel中錄製宏看代碼的感覺。下面的程式是api協助裡的,它用來顯示裝配體的所有零組件。我給我的同事們用,他們覺得不錯 :)。程式使用了一個簡單的遞迴方法遍曆了裝配體。
Make All Assembly Components Visible Example (VB)
This example shows how to make all assembly components visible.

 

'---------------------------------------

'

' Preconditions: An assembly document is open.

'

' Postconditions: Any hidden assembly components are made visible.

'

'---------------------------------------

Option Explicit

Public Enum swComponentVisibilityState_e

}}-->    }}-->swComponentHidden = 0

}}-->    }}-->swComponentVisible = 1

End Enum

 

Sub TraverseComponent _

( _

}}-->    }}-->swComp As SldWorks.Component2, _

}}-->    }}-->nLevel As Long _

)

}}-->    }}-->Dim vChildCompArr }}-->              }}-->As Variant

}}-->    }}-->Dim vChildComp }}-->                 }}-->As Variant

}}-->    }}-->Dim swChildComp }}-->                }}-->As SldWorks.Component2

}}-->    }}-->Dim swCompConfig }}-->               }}-->As SldWorks.Configuration

}}-->    }}-->Dim sPadStr }}-->                    }}-->As String

}}-->    }}-->Dim i }}-->                          }}-->As Long

}}-->    }}-->

}}-->    }}-->For i = 0 To nLevel - 1

}}-->        }}-->sPadStr = sPadStr + " }}--> }}-->"

}}-->    }}-->Next i

}}-->    }}-->

}}-->    }}-->vChildCompArr = swComp.GetChildren

}}-->    }}-->For Each vChildComp In vChildCompArr

}}-->        }}-->Set swChildComp = vChildComp

}}-->        }}-->

}}-->        }}-->Debug.Print sPadStr & swChildComp.Name2 & " <" & swChildComp.ReferencedConfiguration & ">"

}}-->        }}-->

}}-->        }}-->If swComponentHidden = swChildComp.Visible Then

}}-->            }}-->swChildComp.Visible = swComponentVisible

}}-->        }}-->End If

}}-->        }}-->

}}-->        }}-->TraverseComponent swChildComp, nLevel + 1

}}-->    }}-->Next

End Sub

 

Sub main()

}}-->    }}-->Dim swApp }}-->                      }}-->As SldWorks.SldWorks

}}-->    }}-->Dim swModel }}-->                    }}-->As SldWorks.ModelDoc2

}}-->    }}-->Dim swAssy }}-->                     }}-->As SldWorks.AssemblyDoc

}}-->    }}-->Dim swConf }}-->                     }}-->As SldWorks.Configuration

}}-->    }}-->Dim swRootComp }}-->                 }}-->As SldWorks.Component2

}}-->    }}-->Dim bRet }}-->                       }}-->As Boolean

}}-->    Set swApp = Application.SldWorks

}}-->    }}-->Set swModel = swApp.ActiveDoc

}}-->    }}-->Set swConf = swModel.GetActiveConfiguration

}}-->    }}-->Set swRootComp = swConf.GetRootComponent}}-->}}-->

}}-->    }}-->Debug.Print "File = " & swModel.GetPathName

}}-->    TraverseComponent swRootComp, 1

End Sub


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.