QQ登录

只需一步,快速开始

登录 | 注册 | 找回密码

三维网

 找回密码
 注册

QQ登录

只需一步,快速开始

展开

通知     

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

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

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

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

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

x
本帖最后由 steve_suich 于 2015-1-9 17:00 编辑
% E8 k! h3 b! ]/ P
) \7 ~( V; I* d5 `VB.NET代码" U4 [! c+ m6 F% F
引用SW库 : SolidWorks.Interop.sldworks.dll,SolidWorks.Interop.swconst.dll
: `; z2 v6 d- @1 u5 {) ~连接SW,打开文件  :
  1. Dim swapp As SldWorks
    , \: B$ g7 u8 b1 @) n8 b
  2. Dim swdoc As ModelDoc2
    * ?0 d* i3 V( b  ?# C! j
  3. swapp = GetObject(, "SldWorks.Application")* _3 s6 y% z2 U& W& }% `% t" _
  4. With OpenFileDialog1% q7 @% m5 V1 z! Y+ G* o. X. Q
  5.             .Filter = "SW文件(*.sldprt;*.sldasm)|*.sldprt;*.sldasm"
    : I3 m, A5 Y$ x8 h- N4 B5 ^( N
  6.             .FilterIndex = 1' Z" b4 P* ]8 Q) v% x* S
  7.             .Title = "选择零件或者装配件(Ctrl可多选)"; W; W2 i7 i% f) T4 v2 r' G; b
  8.         End With
    % p# o; Y# j( E) G. H  w
  9.         If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
    1 u2 ?8 E+ y3 i5 \& J
  10.             Dim stname As String+ B* I% I2 q2 O  ]
  11.             For Each stname In OpenFileDialog1.FileNames
    : t, I$ s# l1 Y$ P
  12.                 If Mid(stname, Len(stname) - 6) = ".SLDPRT" Then
    . `- k1 u; B4 X1 |( Q6 L4 Z3 J
  13.                     swapp.OpenDoc(stname, 1)
    ! d2 W5 a+ `; n1 ~" N
  14.                 ElseIf Mid(stname, Len(stname) - 6) = ".SLDASM" Then1 Y% v9 f( U- g2 k$ A, r
  15.                     swapp.OpenDoc(stname, 2)
    " Q/ k0 u6 ]/ _1 s5 {! p4 I, }
  16.                 End If
    % d' q$ Y, J7 g5 |" t' ]& ~
  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 编辑 : H) z  f- P+ J: \( a/ t& b$ |% w" \

% s% r6 e" T$ U3 H添加自定义属性:swdoc.AddCustomInfo2(“自定义属性名称”, swCustomInfoType_e.swCustomInfoText, "内容")) ^% G% D6 D/ ]- x6 U1 y
还可以这样:4 j7 J2 i# ^" A0 u
swdoc.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
% {/ E4 `/ T8 ^  F7 |只学了点皮毛。抛钻引玉!!

; n; n# U5 s# ?  x我想应该是这个吧。
/ U0 I' Q- ?. F* R, k' D- Q9 jswmodel.SketchManager.InsertSketch(True)
 楼主| 发表于 2015-1-10 14:06:05 | 显示全部楼层 来自: 中国广东深圳
foxjinlin 发表于 2015-1-9 19:08 static/image/common/back.gif
, V4 _/ z- E5 {: L$ c退出并保留草图绘制,代码怎么写
. R& x8 X& R4 E5 d+ O
我想应该是这个吧。
' ?; \8 H" T3 g7 C; O- N" Pswmodel.SketchManager.InsertSketch(True)
 楼主| 发表于 2015-1-10 14:07:11 | 显示全部楼层 来自: 中国广东深圳
ss988 发表于 2015-1-9 19:47 static/image/common/back.gif/ B+ D* c+ z6 L
3d草图每两条线倒R角怎样选择直线?楼主会吗?

# g5 e4 S# B! g, R这个不会,期待高手解答。
 楼主| 发表于 2015-1-10 14:27:26 | 显示全部楼层 来自: 中国广东深圳
Mid(stname, Len(stname) - 6) = ".SLDPRT"* k& c" T0 d, g7 ]! B5 R6 ^- ^& n
改为 Path.GetExtension(stname) = ".SLDPRT" 更合理。
 楼主| 发表于 2015-1-14 08:57:07 | 显示全部楼层 来自: 中国广东深圳
单位设置:
  1. swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitSystem, 0, swUnitSystem_e.swUnitSystem_Custom)1 H7 P# s. D0 G8 x+ k6 p) }/ b
  2.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsLinear, 0, swLengthUnit_e.swMM)9 ?6 Z) d8 M/ Y, W2 Q
  3.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsDualLinear, 0, swLengthUnit_e.swINCHES)( r/ i4 d4 {/ u! l7 r
  4.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropMass, 0, swUnitsMassPropMass_e.swUnitsMassPropMass_Kilograms)
    8 U, W: E+ [, g5 b# f
  5.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropLength, 0, swLengthUnit_e.swMM)4 H0 W: ~9 A; ^' J# h% O- Z
  6.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropVolume, 0, swUnitsMassPropVolume_e.swUnitsMassPropVolume_Millimeters3)
    7 T+ g! C' I' U6 j( b9 g* g( G% |
  7.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsPowerUnits, 0, swUnitsPowerUnit_e.swUnitsPowerUnit_Watt)
    4 t4 m% U& g" @
  8.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsForce, 0, swUnitsForce_e.swUnitsForce_Newtons)2 b& Q3 N9 a: _! W$ d7 M4 w
  9.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropVolume, 0, swUnitsMassPropVolume_e.swUnitsMassPropVolume_Millimeters3)
    ' l* P3 m$ O, L- m3 a7 k( O
  10.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsTimeUnits, 0, swUnitsTimeUnit_e.swUnitsTimeUnit_Second)' P( c. w. ]( ^4 f
复制代码
发表回复
您需要登录后才可以回帖 登录 | 注册

本版积分规则


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

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

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