QQ登录

只需一步,快速开始

登录 | 注册 | 找回密码

三维网

 找回密码
 注册

QQ登录

只需一步,快速开始

展开

通知     

查看: 3586|回复: 9
收起左侧

[分享] 关于SW二次开发常用代码

[复制链接]
发表于 2015-1-9 16:54:19 | 显示全部楼层 |阅读模式 来自: 中国广东深圳

马上注册,结识高手,享用更多资源,轻松玩转三维网社区。

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

x
本帖最后由 steve_suich 于 2015-1-9 17:00 编辑
0 z. o: c$ K* O+ l+ q0 L  }/ s; n5 ~4 d8 `1 X; \
VB.NET代码- e- o8 }$ s1 ?8 X: ~! g
引用SW库 : SolidWorks.Interop.sldworks.dll,SolidWorks.Interop.swconst.dll% [" C" r, n# d: e. L' u+ L
连接SW,打开文件  :
  1. Dim swapp As SldWorks
    / }" o$ P# e" F* @
  2. Dim swdoc As ModelDoc2
    # B) p6 d0 ?% }$ s
  3. swapp = GetObject(, "SldWorks.Application")
    * X. [$ ^2 p) G! S) f
  4. With OpenFileDialog1
    1 ~% Q, {0 U) L) {8 S
  5.             .Filter = "SW文件(*.sldprt;*.sldasm)|*.sldprt;*.sldasm"
    6 o, U) A4 u0 U- ]2 t5 j
  6.             .FilterIndex = 1
    . v% }+ v. x! ^; M$ x" o) x& q
  7.             .Title = "选择零件或者装配件(Ctrl可多选)"
    1 k4 L+ [& |9 N* F1 ~) Q
  8.         End With
    4 B/ ?. D$ Q5 U1 W. A- v8 ]1 x, u1 D
  9.         If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
    ( S/ A9 A0 o) E9 F( y
  10.             Dim stname As String- S" Z, G% H1 ?9 Z. _
  11.             For Each stname In OpenFileDialog1.FileNames- y7 o2 Y" _$ Z. l( V% B
  12.                 If Mid(stname, Len(stname) - 6) = ".SLDPRT" Then
    8 D) v9 c5 Z7 L. ^1 o
  13.                     swapp.OpenDoc(stname, 1)
    ; ]5 D. c- w" k( j  I3 [) N# p
  14.                 ElseIf Mid(stname, Len(stname) - 6) = ".SLDASM" Then2 l3 |1 B7 O+ j* ~) i5 M9 }
  15.                     swapp.OpenDoc(stname, 2)
    6 y$ x1 M7 p, a& q# r' Q. G" H
  16.                 End If  b9 ^3 O+ ]- j+ p7 }# o1 X$ Z# P
  17.                 swdoc = swapp.ActiveDoc
复制代码

评分

参与人数 1三维币 +10 收起 理由
阿帕奇 + 10

查看全部评分

 楼主| 发表于 2015-1-9 17:01:45 | 显示全部楼层 来自: 中国广东深圳
只学了点皮毛。抛钻引玉!!
 楼主| 发表于 2015-1-9 17:03:51 | 显示全部楼层 来自: 中国广东深圳
本帖最后由 steve_suich 于 2015-1-9 17:05 编辑
! o7 ], j) t' }. n+ D/ k* A# w2 h* T9 G, O) a0 t8 a
添加自定义属性:swdoc.AddCustomInfo2(“自定义属性名称”, swCustomInfoType_e.swCustomInfoText, "内容")" i6 K& p- Q9 [( z; n0 v
还可以这样:
! `- z5 ~5 z9 l, ~1 Y7 t! b' C8 Hswdoc.AddCustomInfo2(“Weight”, swCustomInfoType_e.swCustomInfoText,  """" & "SW-Mass@" & swdoc.GetTitle & """")
发表于 2015-1-9 19:08:16 | 显示全部楼层 来自: 中国浙江宁波
退出并保留草图绘制,代码怎么写
发表于 2015-1-9 19:47:02 | 显示全部楼层 来自: 中国安徽芜湖
3d草图每两条线倒R角怎样选择直线?楼主会吗?
 楼主| 发表于 2015-1-10 14:05:17 | 显示全部楼层 来自: 中国广东深圳
steve_suich 发表于 2015-1-9 17:01 static/image/common/back.gif& b( P4 a8 h' W% Z0 {8 n$ c2 ?: ^
只学了点皮毛。抛钻引玉!!

7 u' ~8 k; F8 t& r) k, S  g我想应该是这个吧。& @4 j( z( J* i+ R8 c; ^' ]
swmodel.SketchManager.InsertSketch(True)
 楼主| 发表于 2015-1-10 14:06:05 | 显示全部楼层 来自: 中国广东深圳
foxjinlin 发表于 2015-1-9 19:08 static/image/common/back.gif( \& K! t* n9 D" X# o
退出并保留草图绘制,代码怎么写
8 D7 k- A! ]- T7 ?6 g$ X
我想应该是这个吧。. J( V) S2 i4 W$ X* c
swmodel.SketchManager.InsertSketch(True)
 楼主| 发表于 2015-1-10 14:07:11 | 显示全部楼层 来自: 中国广东深圳
ss988 发表于 2015-1-9 19:47 static/image/common/back.gif
  Z; ?4 P& y* L7 N7 q6 c3d草图每两条线倒R角怎样选择直线?楼主会吗?

0 c2 ^: K" s& x: M: Z这个不会,期待高手解答。
 楼主| 发表于 2015-1-10 14:27:26 | 显示全部楼层 来自: 中国广东深圳
Mid(stname, Len(stname) - 6) = ".SLDPRT"
3 V# n: |" R! v# V% b+ E& D/ @改为 Path.GetExtension(stname) = ".SLDPRT" 更合理。
 楼主| 发表于 2015-1-14 08:57:07 | 显示全部楼层 来自: 中国广东深圳
单位设置:
  1. swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitSystem, 0, swUnitSystem_e.swUnitSystem_Custom)# Q+ M) A5 Q# f/ l
  2.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsLinear, 0, swLengthUnit_e.swMM)5 }# p& Q' y$ A: y6 o
  3.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsDualLinear, 0, swLengthUnit_e.swINCHES)4 b4 h, ]( X+ q9 f6 q* g3 e0 ~
  4.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropMass, 0, swUnitsMassPropMass_e.swUnitsMassPropMass_Kilograms)  R3 I7 }2 i6 @) c/ k, P
  5.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropLength, 0, swLengthUnit_e.swMM)
    - E# r# b  a* H3 `6 R2 H6 s$ q
  6.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropVolume, 0, swUnitsMassPropVolume_e.swUnitsMassPropVolume_Millimeters3)
    8 Y) b% }! z9 r" s( }
  7.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsPowerUnits, 0, swUnitsPowerUnit_e.swUnitsPowerUnit_Watt)8 {. x2 Z, z/ I3 \: U+ ^
  8.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsForce, 0, swUnitsForce_e.swUnitsForce_Newtons)
    + Y8 o; y/ l$ @3 D1 r  r
  9.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropVolume, 0, swUnitsMassPropVolume_e.swUnitsMassPropVolume_Millimeters3)( }3 s9 _( o7 s! Z! h6 |* W
  10.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsTimeUnits, 0, swUnitsTimeUnit_e.swUnitsTimeUnit_Second)
    # l2 \$ ]0 }; B8 G) k4 ]
复制代码
发表回复
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Licensed Copyright © 2016-2020 http://www.3dportal.cn/ All Rights Reserved 京 ICP备13008828号

小黑屋|手机版|Archiver|三维网 ( 京ICP备2023026364号-1 )

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