本帖最后由 DaveChan 于 2016-11-4 19:04 编辑
我来帮你解答第一个问题吧
1.SWDM-API我不能获取到工程图模型的配置,所以只写了获取活动配置,
暂时不知道怎么获取工程图模型引用的配置,以下代码是获取活动配置的属性(一般情况下是"默认"配置)
由于不是专业写代码的,有不对的地方,还望指正
- Sub ReadModelPrpInSlddrw()
- Dim swModel As SwDMDocument12
- Dim dmSearchOpt As SwDMSearchOption
- Set objClassfac = CreateObject("SwDocumentMgr.SwDMClassFactory")
- SWDMLicenseKey = InputBox("輸入許可證密碼")
- If SWDMLicenseKey = "" Then Exit Sub
- Set swDM = objClassfac.GetApplication(SWDMLicenseKey) '啟動SWDM
- HeaderRoll = 2
- RollNumber = HeaderRoll + 1
- PathName = ActiveSheet.Cells(RollNumber, 1) '讀取第一個路徑的值
- While Not (PathName = "" Or PathName = 0 Or IsEmpty(PathName)) '直到讀完路徑欄
- FileName = ActiveSheet.Cells(RollNumber, 2)
- Set swDoc = swDM.GetDocument(PathName & FileName , 3, False, mOpenErrors) '開啟工程圖
- If Not swDoc Is Nothing Then
- RefModelNames = swDoc.GetAllExternalReferences(dmSearchOpt) '獲取參考檔案名稱
- If Not TypeName(RefModelNames) = "Empty" Then '過濾沒有參考檔案
- Cells(RollNumber, 2).Interior.ColorIndex = 8
- RefModelName = RefModelNames(0) '獲取第一個參考檔案的名稱
- If "SLDPRT" = UCase(Left(RefModelName, 6)) Then '分辨參考檔案的類型
- RefModelTYpe = 1 '這是零件
- Else
- RefModelTYpe = 2 '這是組合件
- End If
- Set swModel = swDM.GetDocument(RefModelName, RefModelTYpe, False, mOpenErrors) '開啟
- Set swCfgMgr = swModel.ConfigurationManager
- ColumnNumber = 3
- PropName = Cells(HeaderRoll, ColumnNumber)
- While Not (PropName = "" Or PropName = 0 Or IsEmpty(PropName)) '直到讀完表頭
- swConfigName = swCfgMgr.GetActiveConfigurationName
- Dim swCfg As SwDMConfiguration12
- Set swCfg = swCfgMgr.GetConfigurationByName(swConfigName)
- PropNames = swCfg.GetCustomPropertyNames '獲取模型內所有屬性的名稱
- HasPropName = False
- If Not IsEmpty(PropNames) Then
- For I = 0 To UBound(PropNames) '核對書否存在表單上的屬性名稱
- If UCase(PropNames(I)) = UCase(PropName) Then HasPropName = True
- Next
- End If
- If HasPropName Then
- PropValue = swCfg.GetCustomProperty(PropName, swDmCustomInfoText) '獲取參考檔案的屬性
- Cells(RollNumber, ColumnNumber) = PropValue '寫入屬性到表格
- Else
- Cells(RollNumber, ColumnNumber) = "-----" '寫入代表不存在屬性的字符
- End If
- ColumnNumber = ColumnNumber + 1 '下一欄
- PropName = ActiveSheet.Cells(HeaderRoll, ColumnNumber)
- Wend '回到>直到讀完表頭
- swModel.CloseDoc '關閉參考檔案
- Cells(RollNumber, ColumnNumber) = RefModelName '寫入參考檔案名稱到表格到行末
- End If
- swDoc.CloseDoc '關閉工程圖
- End If
- RollNumber = RollNumber + 1 '下一列
- PathName = ActiveSheet.Cells(RollNumber, 1)
- Wend '回到>直到讀完路徑欄
- End Sub
复制代码
|