QQ登录

只需一步,快速开始

登录 | 注册 | 找回密码

三维网

 找回密码
 注册

QQ登录

只需一步,快速开始

展开

通知     

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

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

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

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

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

x
本帖最后由 steve_suich 于 2015-1-9 17:00 编辑 . V; w1 \6 Q, T$ A0 I
: P* d, u, {* U! f2 }
VB.NET代码
' ~+ u4 I* Q& H) s7 W引用SW库 : SolidWorks.Interop.sldworks.dll,SolidWorks.Interop.swconst.dll
1 v; Y5 F4 W" b7 n4 n) \连接SW,打开文件  :
  1. Dim swapp As SldWorks/ r; X4 C- [+ r8 W
  2. Dim swdoc As ModelDoc2
    4 Z% l+ h5 ^0 D. g' C
  3. swapp = GetObject(, "SldWorks.Application")& Y7 ?) B" t$ u. V9 f& L  K: s6 {2 r# G
  4. With OpenFileDialog1& c" z" g: R7 S+ d  A
  5.             .Filter = "SW文件(*.sldprt;*.sldasm)|*.sldprt;*.sldasm"
    5 Z3 W/ T1 G8 J9 ?5 d0 H
  6.             .FilterIndex = 1
    * Q6 g* M( }, s
  7.             .Title = "选择零件或者装配件(Ctrl可多选)"
    ( @2 {# [) I2 P- r
  8.         End With
    * Z. @: j+ x* y) q
  9.         If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then5 v7 d" t* Q1 C5 }+ G
  10.             Dim stname As String! E7 P( ~) w; [! C
  11.             For Each stname In OpenFileDialog1.FileNames
    ! D5 S( m5 w' Q+ w
  12.                 If Mid(stname, Len(stname) - 6) = ".SLDPRT" Then
    - Q! j& I+ Z3 b. T$ ^# x
  13.                     swapp.OpenDoc(stname, 1)( s7 P) ]4 A. `. |
  14.                 ElseIf Mid(stname, Len(stname) - 6) = ".SLDASM" Then6 p' u# n8 a: l1 S8 l- @
  15.                     swapp.OpenDoc(stname, 2)" `3 K8 W7 w# Q( n, A. D5 Y2 n
  16.                 End If
    5 ]1 G1 o( A9 `8 J+ l
  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 编辑
. V8 _( k$ g7 @2 }0 v# Z( E  W) S2 s( R( y% Q5 F
添加自定义属性:swdoc.AddCustomInfo2(“自定义属性名称”, swCustomInfoType_e.swCustomInfoText, "内容")
% b9 q* P' u# m还可以这样:/ {" @: V. \5 X9 o. W* z
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
, r( b/ g* ~( o& ]只学了点皮毛。抛钻引玉!!
/ u, o0 f+ q3 M! ]* m  j
我想应该是这个吧。% g& E4 U8 s* N7 k
swmodel.SketchManager.InsertSketch(True)
 楼主| 发表于 2015-1-10 14:06:05 | 显示全部楼层 来自: 中国广东深圳
foxjinlin 发表于 2015-1-9 19:08 static/image/common/back.gif! i: \* F; `% @& o0 a' c' Y
退出并保留草图绘制,代码怎么写

9 j3 R! H  I" N8 w我想应该是这个吧。
4 C. @. t8 D5 ~+ `! D: hswmodel.SketchManager.InsertSketch(True)
 楼主| 发表于 2015-1-10 14:07:11 | 显示全部楼层 来自: 中国广东深圳
ss988 发表于 2015-1-9 19:47 static/image/common/back.gif
2 P" V) H4 q2 Z  G, |3d草图每两条线倒R角怎样选择直线?楼主会吗?

" o  d, c5 O3 _* A+ }+ @这个不会,期待高手解答。
 楼主| 发表于 2015-1-10 14:27:26 | 显示全部楼层 来自: 中国广东深圳
Mid(stname, Len(stname) - 6) = ".SLDPRT"" W9 M; [# e3 Z  b4 k/ A( f
改为 Path.GetExtension(stname) = ".SLDPRT" 更合理。
 楼主| 发表于 2015-1-14 08:57:07 | 显示全部楼层 来自: 中国广东深圳
单位设置:
  1. swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitSystem, 0, swUnitSystem_e.swUnitSystem_Custom)
    # `$ I5 ^' r3 k
  2.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsLinear, 0, swLengthUnit_e.swMM): @3 A& j; d; u: ^2 C
  3.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsDualLinear, 0, swLengthUnit_e.swINCHES)" k# U4 l; p" q: Z4 T5 v
  4.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropMass, 0, swUnitsMassPropMass_e.swUnitsMassPropMass_Kilograms)7 s5 |! n7 v# K1 P
  5.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropLength, 0, swLengthUnit_e.swMM); `4 a! _1 I+ s) Z( _
  6.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropVolume, 0, swUnitsMassPropVolume_e.swUnitsMassPropVolume_Millimeters3), G" x7 u$ [, r$ x  h
  7.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsPowerUnits, 0, swUnitsPowerUnit_e.swUnitsPowerUnit_Watt)" T: V1 i: m& {! S6 `3 l5 n, i9 _
  8.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsForce, 0, swUnitsForce_e.swUnitsForce_Newtons)
    % C6 f8 J: X# v
  9.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropVolume, 0, swUnitsMassPropVolume_e.swUnitsMassPropVolume_Millimeters3)& |+ E/ L0 y# q9 x
  10.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsTimeUnits, 0, swUnitsTimeUnit_e.swUnitsTimeUnit_Second)
    . x4 z9 h7 a1 H& b! O; ?* s! U
复制代码
发表回复
您需要登录后才可以回帖 登录 | 注册

本版积分规则


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

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

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