QQ登录

只需一步,快速开始

登录 | 注册 | 找回密码

三维网

 找回密码
 注册

QQ登录

只需一步,快速开始

展开

通知     

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

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

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

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

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

x
本帖最后由 steve_suich 于 2015-1-9 17:00 编辑 0 q- y% H5 k; }7 m8 P' z7 @

$ u* I1 D& b' f2 fVB.NET代码
6 `& m+ i1 e' w* H$ r! ?) @1 r引用SW库 : SolidWorks.Interop.sldworks.dll,SolidWorks.Interop.swconst.dll
9 m$ {' T/ s7 w6 S! t* E连接SW,打开文件  :
  1. Dim swapp As SldWorks% d8 h, }2 Y0 W: h$ {/ U  x2 K5 r
  2. Dim swdoc As ModelDoc29 p: h, ?8 \' U6 A0 t/ {
  3. swapp = GetObject(, "SldWorks.Application")
    / a% G* u  G2 V4 Y* M! z  X
  4. With OpenFileDialog1
    ( m* a( `7 L1 _/ ~2 X7 d" S
  5.             .Filter = "SW文件(*.sldprt;*.sldasm)|*.sldprt;*.sldasm"
    4 ]. g- D0 w  J$ E
  6.             .FilterIndex = 1
    # {9 }# h5 x: k, y. f* v
  7.             .Title = "选择零件或者装配件(Ctrl可多选)"! X3 K) b7 a1 P, [5 a5 S
  8.         End With- P' T! P1 D; ~* J2 l* X& E1 Q6 R: A
  9.         If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
    $ X9 m6 D$ v2 V2 B
  10.             Dim stname As String
    . k2 z6 R' O3 ~; J, L7 p$ P4 Y
  11.             For Each stname In OpenFileDialog1.FileNames4 Z2 {3 I. |6 S7 K; O4 I8 e
  12.                 If Mid(stname, Len(stname) - 6) = ".SLDPRT" Then2 L- V7 e& [$ n$ |
  13.                     swapp.OpenDoc(stname, 1)
    ) `5 C! O" g' D! ?6 u
  14.                 ElseIf Mid(stname, Len(stname) - 6) = ".SLDASM" Then2 E! }5 W0 p6 Z3 c* G$ ~
  15.                     swapp.OpenDoc(stname, 2)/ F: V4 D' I# @6 w6 e
  16.                 End If+ v5 X+ Z0 p8 a7 ]+ I
  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 编辑 7 h" l# B7 P: a5 p

4 g, S, M! B+ M, P添加自定义属性:swdoc.AddCustomInfo2(“自定义属性名称”, swCustomInfoType_e.swCustomInfoText, "内容")7 e9 p4 d+ K4 P% F! ~& v
还可以这样:
( J* M0 F' J/ Jswdoc.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
7 T- p' S) P$ g% z+ `* L4 c只学了点皮毛。抛钻引玉!!
  @7 w' Q2 ~# p: P5 P
我想应该是这个吧。( X1 A! x0 c- P: r$ v* d" l1 n
swmodel.SketchManager.InsertSketch(True)
 楼主| 发表于 2015-1-10 14:06:05 | 显示全部楼层 来自: 中国广东深圳
foxjinlin 发表于 2015-1-9 19:08 static/image/common/back.gif
" \7 t& o4 \% ^) o; e1 c退出并保留草图绘制,代码怎么写

/ r( H1 [1 f2 \$ C1 i- N0 B6 |" A我想应该是这个吧。
3 W& l' b' m1 {. }swmodel.SketchManager.InsertSketch(True)
 楼主| 发表于 2015-1-10 14:07:11 | 显示全部楼层 来自: 中国广东深圳
ss988 发表于 2015-1-9 19:47 static/image/common/back.gif
/ Q# J6 F1 V7 ~) ~3d草图每两条线倒R角怎样选择直线?楼主会吗?
7 F; ~/ v5 e7 o% C! Z
这个不会,期待高手解答。
 楼主| 发表于 2015-1-10 14:27:26 | 显示全部楼层 来自: 中国广东深圳
Mid(stname, Len(stname) - 6) = ".SLDPRT"
: j  j" A1 T$ W1 |改为 Path.GetExtension(stname) = ".SLDPRT" 更合理。
 楼主| 发表于 2015-1-14 08:57:07 | 显示全部楼层 来自: 中国广东深圳
单位设置:
  1. swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitSystem, 0, swUnitSystem_e.swUnitSystem_Custom)
    - g1 m8 W. X- H1 n: D, f6 F
  2.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsLinear, 0, swLengthUnit_e.swMM)% Q& V& B! D5 o, p% s! T' q. u
  3.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsDualLinear, 0, swLengthUnit_e.swINCHES)5 e/ t" S0 M5 O) W- v0 c) o
  4.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropMass, 0, swUnitsMassPropMass_e.swUnitsMassPropMass_Kilograms)3 @6 o; e+ \* Y4 i( u3 E
  5.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropLength, 0, swLengthUnit_e.swMM)
    # Q& C  G1 Q. X" n7 g
  6.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropVolume, 0, swUnitsMassPropVolume_e.swUnitsMassPropVolume_Millimeters3)
    2 c9 y. B/ x- V9 T2 s! g2 Z
  7.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsPowerUnits, 0, swUnitsPowerUnit_e.swUnitsPowerUnit_Watt)
    2 \8 A( W# B! b/ L! U6 V9 D' x& e
  8.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsForce, 0, swUnitsForce_e.swUnitsForce_Newtons)
      _7 y3 Z( s. H& w+ O
  9.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropVolume, 0, swUnitsMassPropVolume_e.swUnitsMassPropVolume_Millimeters3)2 |1 o9 b/ ?9 ?0 D! O
  10.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsTimeUnits, 0, swUnitsTimeUnit_e.swUnitsTimeUnit_Second)! V" `1 O1 r; Z' H8 Q" t- r: a
复制代码
发表回复
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

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

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