找回密码 注册 QQ登录
一站式解决方案

iCAx开思网

CAD/CAM/CAE/设计/模具 高清视频【积分说明】如何快速获得积分?快速3D打印 手板模型CNC加工服务在线3D打印服务,上传模型,自动报价
查看: 14943|回复: 0
打印 上一主题 下一主题

[讨论] 体积特征宏→如何更改面积+体积特征宏。

[复制链接]
跳转到指定楼层
1
发表于 2012-10-5 15:10:58 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

自定义宏特征-闷人的体积宏解析
https://www.icax.org/forum.php?mod=viewthread&tid=278864&fromuid=1196481
在这个帖的4楼有个国外体积示例,见下面代码

  1. Option Explicit
  2. Dim swApp As SldWorks.SldWorks
  3. Dim Part As SldWorks.ModelDoc2

  4. Sub main()

  5. Dim ThisFile As String
  6. Dim Methods(8) As String
  7. Dim Names As Variant
  8. Dim Types As Variant
  9. Dim Values As Variant
  10. Dim editBody As body2
  11. Dim swmacrofeaturebydefault As Variant

  12. Set swApp = Application.SldWorks
  13. Set Part = swApp.ActiveDoc
  14. Set editBody = Nothing

  15. 'Define the routines to call
  16. ThisFile = swApp.GetCurrentMacroPathName
  17. Methods(0) = ThisFile
  18. Methods(1) = "MacroFeature_Module1"
  19. Methods(2) = "swmRebuild"
  20. Methods(3) = ThisFile
  21. Methods(4) = "MacroFeature_Module1"
  22. Methods(5) = "swmEditDefinition"
  23. Methods(6) = "" 'A security routine is optional
  24. Methods(7) = ""
  25. Methods(8) = ""

  26. Names = Empty
  27. Types = Empty
  28. Values = Empty

  29. 'Insert the macro feature
  30. Part.FeatureManager.InsertMacroFeature "Volume in Feet", "", (Methods), Names, Types, Values, editBody, swmacrofeaturebydefault

  31. End Sub

  32. Function swmRebuild(app As Variant, Part As Variant, feature As Variant) As Variant

  33. Dim Definition As SldWorks.MacroFeatureData
  34. Dim Objects As Variant
  35. Dim ObjTypes As Variant
  36. Dim SelMarks As Variant
  37. Dim DrwViews As Variant

  38. Set swApp = Application.SldWorks
  39. Set Part = swApp.ActiveDoc
  40. Set Definition = feature.GetDefinition

  41. Definition.GetSelections2 Objects, ObjTypes, SelMarks, DrwViews

  42. Dim vol As Variant
  43. Dim conv As Variant
  44. Dim convRounded As String
  45. Dim prop As Boolean
  46. Dim mass As SldWorks.MassProperty

  47. Set mass = Part.Extension.CreateMassProperty

  48. vol = mass.volume

  49. conv = vol * 35.31466672

  50. convRounded = Round(conv, 3)

  51. prop = Part.DeleteCustomInfo2("", "Volume")

  52. prop = Part.AddCustomInfo3("", "Volume", 30, convRounded + " Cubic Feet")
  53. Debug.Print " Volume = " & mass.volume

  54. End Function

  55. Function swmEditDefinition(app As Variant, Part As Variant, feature As Variant) As Variant
  56. End Function
复制代码
目标需求:如何将国外的体积宏示例,转换为体积+面积的特征宏。






本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏2 分享淘帖 赞一下!赞一下!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

3D打印手板模型快速制作服务,在线报价下单!

QQ 咨询|手机版|联系我们|iCAx开思网  

GMT+8, 2024-11-15 14:27 , Processed in 0.024733 second(s), 12 queries , Gzip On, Redis On.

Powered by Discuz! X3.3

© 2002-2024 www.iCAx.org

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