|
自定义宏特征-闷人的体积宏解析
https://www.icax.org/forum.php?mod=viewthread&tid=278864&fromuid=1196481
在这个帖的4楼有个国外体积示例,见下面代码
- Option Explicit
- Dim swApp As SldWorks.SldWorks
- Dim Part As SldWorks.ModelDoc2
- Sub main()
- Dim ThisFile As String
- Dim Methods(8) As String
- Dim Names As Variant
- Dim Types As Variant
- Dim Values As Variant
- Dim editBody As body2
- Dim swmacrofeaturebydefault As Variant
- Set swApp = Application.SldWorks
- Set Part = swApp.ActiveDoc
- Set editBody = Nothing
- 'Define the routines to call
- ThisFile = swApp.GetCurrentMacroPathName
- Methods(0) = ThisFile
- Methods(1) = "MacroFeature_Module1"
- Methods(2) = "swmRebuild"
- Methods(3) = ThisFile
- Methods(4) = "MacroFeature_Module1"
- Methods(5) = "swmEditDefinition"
- Methods(6) = "" 'A security routine is optional
- Methods(7) = ""
- Methods(8) = ""
- Names = Empty
- Types = Empty
- Values = Empty
- 'Insert the macro feature
- Part.FeatureManager.InsertMacroFeature "Volume in Feet", "", (Methods), Names, Types, Values, editBody, swmacrofeaturebydefault
- End Sub
- Function swmRebuild(app As Variant, Part As Variant, feature As Variant) As Variant
- Dim Definition As SldWorks.MacroFeatureData
- Dim Objects As Variant
- Dim ObjTypes As Variant
- Dim SelMarks As Variant
- Dim DrwViews As Variant
- Set swApp = Application.SldWorks
- Set Part = swApp.ActiveDoc
- Set Definition = feature.GetDefinition
- Definition.GetSelections2 Objects, ObjTypes, SelMarks, DrwViews
- Dim vol As Variant
- Dim conv As Variant
- Dim convRounded As String
- Dim prop As Boolean
- Dim mass As SldWorks.MassProperty
- Set mass = Part.Extension.CreateMassProperty
- vol = mass.volume
- conv = vol * 35.31466672
- convRounded = Round(conv, 3)
- prop = Part.DeleteCustomInfo2("", "Volume")
- prop = Part.AddCustomInfo3("", "Volume", 30, convRounded + " Cubic Feet")
- Debug.Print " Volume = " & mass.volume
- End Function
- Function swmEditDefinition(app As Variant, Part As Variant, feature As Variant) As Variant
- End Function
复制代码 目标需求:如何将国外的体积宏示例,转换为体积+面积的特征宏。
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|