|
马上注册,查询更多机械资源,享用更多功能,轻松畅享机械设计招标网。
您需要 登录 才可以下载或查看,没有账号?注册
×
用Sw2014编制的零件、装配休和工程图,绝对不可能在低版本的SW中应用。
而在高版本solidworks中编制的API文件,90%代码能在低版本的SolidWorks中得到应用。
************************************
看了n个版本的Api帮助文件,90%以上的语句,适合SolidWorks所有版本。
只是高版本有些语句在低版本不可用。如CustomProperties和measure语句,只能在Sw2007-Sw2012版本应用。
绝大多数Api代码,不但能在Sw2007-Sw2012应用,还且还能在Sw2006应用。只不过遇到CustomProperties和measure语句时,会提示出错,需要编写几条代码实现CustomProperties和measure语句的功能。
例如:SolidWorks任何版本的网上帮助文件,在介绍CustomProperties时,对Sw2006和Sw2007进行了比较。
2010 Solidworks api Help - Obsolete and New Custom Properties Methods and Properties
http://help.SolidWorks.com/2010/English/api/sldworksapiprogguide/miscellaneous/obsolete_and_new_custom_properties_methods_and_properties.htm
*****************************************************************************************
SolidWorks 2006以下版本用CustomInfo代码
- Function CustInfoName(SwModel As ModelDoc2)
- Dim SwConfig As Configuration, ConfArr, ConfName, CustArr
- Dim Str, kk
- kk = 2
- ConfArr = SwModel.GetConfigurationNames
- For ii = 0 To UBound(ConfArr)
- Set SwConfig = SwModel.GetConfigurationByName(ConfArr(ii))
- ConfName = SwConfig.Name
- With SwModel
- Str = Chr(34) & "SW-Mass@@" & ConfName & "@" & .GetTitle & Chr(34)
- .AddCustomInfo3 ConfName, "质量", 30, "12"
- .CustomInfo2(ConfName, "质量") = Str '"""" & Str & """"
- Str = Chr(34) & "SW-Material@@" & ConfName & "@" & .GetTitle & Chr(34)
- CustArr = .GetCustomInfoNames2(ConfName)
- .ShowConfiguration ConfName
- End With
- Next ii
- End Function
复制代码
*************************************
SolidWorks 2007以下版本用CustomPropertyManager
代码
- Sub ll()
- Dim SwModel As ModelDoc2
- Set SwModel = Application.SldWorks.ActiveDoc
- Dim swCustProp As CustomPropertyManager
- Set swCustProp = SwModel.Extension.CustomPropertyManager("A1")
- swCustProp.Add "Mass", swCustomInfoType_e.swCustomInfoText, "MyValue"
- swCustProp.Set "Mass", "MyValue"
- End Sub
复制代码
*************************************
UseNamedConfiguration在SolidWorks 2006以下版本没有,在SolidWorks2008以上版本能够使用。
swComp.UseNamedConfiguration = True 'Use named
swComp.UseNamedConfiguration = False
******************************************************************
Sw2006没有测量(Measure)语句, 要实现Measure语句功能,需要多几个代码。
Sw2008以后版本有Measure功能。省去几行代码,提高了编程的可读性。
- Function MeasureLen(SwFeat As Feature, SwMeasure As Measure)
- Dim SwSketch As Sketch, SkSegArr, SkSeg As SketchSegment
- Set SwSketch = SwFeat.GetSpecificFeature
- SkSegArr = SwSketch.GetSketchSegments
- For ii = 0 To UBound(SkSegArr)
- Set SkSeg = SkSegArr(ii)
- Debug.Print SkSeg.GetType, Round(SkSeg.GetLength * 1000, 1)
- SkSeg.Select2 True, 1
- Next
- ''
- With SwMeasure
- boolstatus = .Calculate(Nothing)
- If boolstatus Then
- MeasureLen = Round(.TotalLength * 1000, 1)
- Else
- MsgBox "No Measure "
- End If
- End With
- End Function
- Private Sub ll()
- Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2
- Set SwApp = Application.SldWorks
- Set SwModel = SwApp.ActiveDoc
- Dim SwMeasure As Measure, SwFeat As Feature, Str
- Set SwMeasure = SwModel.Extension.CreateMeasure
- Str = "测量长度"
- Set SwFeat = SwModel.FeatureByName(Str)
- Debug.Print MeasureLen(SwFeat, SwMeasure)
- End Sub
复制代码
|
|