QQ登录

只需一步,快速开始

登录 | 注册 | 找回密码

三维网

 找回密码
 注册

QQ登录

只需一步,快速开始

展开

通知     

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

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

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

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

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

x
本帖最后由 steve_suich 于 2015-1-9 17:00 编辑 6 D. |. o# J% G# K
$ B. @# L& g& i" g  C
VB.NET代码
9 Z/ }0 B6 J" g- G% I- @$ Z引用SW库 : SolidWorks.Interop.sldworks.dll,SolidWorks.Interop.swconst.dll
8 B2 O8 A, e0 r3 C- t; l/ @* c连接SW,打开文件  :
  1. Dim swapp As SldWorks
    " v+ G# @# u8 f) }
  2. Dim swdoc As ModelDoc23 Y' j( M6 K4 }
  3. swapp = GetObject(, "SldWorks.Application")0 C) a: b8 C3 X# N6 v0 L1 \
  4. With OpenFileDialog1
    7 W! o4 `' L+ K7 Y  J
  5.             .Filter = "SW文件(*.sldprt;*.sldasm)|*.sldprt;*.sldasm"% \  J6 ^1 C( x, H; E, x% {
  6.             .FilterIndex = 19 R% ^+ ~  b8 X% ]
  7.             .Title = "选择零件或者装配件(Ctrl可多选)"8 a; ~' F( L$ ?6 ]
  8.         End With1 Y: F0 c6 L/ v* g) R9 ?5 L
  9.         If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
    * a- c5 _0 q7 z# j* @8 a( }" k) R
  10.             Dim stname As String
    4 P8 H# T, n$ H6 [- X) n1 U7 V- r
  11.             For Each stname In OpenFileDialog1.FileNames* m" b3 H' h, c3 g  X1 m
  12.                 If Mid(stname, Len(stname) - 6) = ".SLDPRT" Then
    ' A: i9 b: r' D+ _4 Q1 b5 e/ g! M
  13.                     swapp.OpenDoc(stname, 1)- N: V9 s% R) c+ V6 X7 h3 L
  14.                 ElseIf Mid(stname, Len(stname) - 6) = ".SLDASM" Then
    " j# r9 A- I* F0 c- e
  15.                     swapp.OpenDoc(stname, 2)
      m6 E2 z9 C; `4 d$ A2 {, C$ J
  16.                 End If
    8 q/ _  t3 ~4 q- d: X
  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 编辑 ; ]( V# F3 t  u- n
) V) W: Q, T( `+ K, A2 [
添加自定义属性:swdoc.AddCustomInfo2(“自定义属性名称”, swCustomInfoType_e.swCustomInfoText, "内容")5 _" L- L5 F: S  G9 F3 P
还可以这样:/ J7 [7 j) }, i1 }+ N& ?- a
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.gif2 n( P; l- }' j" o6 j
只学了点皮毛。抛钻引玉!!

( E9 b& T7 D' u2 {% c: }7 C我想应该是这个吧。2 b: f) q  \8 q* f6 n
swmodel.SketchManager.InsertSketch(True)
 楼主| 发表于 2015-1-10 14:06:05 | 显示全部楼层 来自: 中国广东深圳
foxjinlin 发表于 2015-1-9 19:08 static/image/common/back.gif
5 J: S* k* x) U3 z, W退出并保留草图绘制,代码怎么写
4 {; _3 y; E5 W7 H) H  ?
我想应该是这个吧。. d4 ^4 ?, V! T  S/ Y6 B, W- b
swmodel.SketchManager.InsertSketch(True)
 楼主| 发表于 2015-1-10 14:07:11 | 显示全部楼层 来自: 中国广东深圳
ss988 发表于 2015-1-9 19:47 static/image/common/back.gif
* q/ p" B& P: I3d草图每两条线倒R角怎样选择直线?楼主会吗?
0 V3 ]$ H( D5 N+ |" T
这个不会,期待高手解答。
 楼主| 发表于 2015-1-10 14:27:26 | 显示全部楼层 来自: 中国广东深圳
Mid(stname, Len(stname) - 6) = ".SLDPRT"
% L2 N/ d' Q( y7 F改为 Path.GetExtension(stname) = ".SLDPRT" 更合理。
 楼主| 发表于 2015-1-14 08:57:07 | 显示全部楼层 来自: 中国广东深圳
单位设置:
  1. swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitSystem, 0, swUnitSystem_e.swUnitSystem_Custom); i8 N8 O3 o4 E  a/ F6 ^6 ~
  2.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsLinear, 0, swLengthUnit_e.swMM)/ m+ h: l# e4 @3 z8 j
  3.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsDualLinear, 0, swLengthUnit_e.swINCHES)
    5 L1 {, @* [( f! ?% a% K
  4.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropMass, 0, swUnitsMassPropMass_e.swUnitsMassPropMass_Kilograms)
    5 A. I, n# X" z6 F' j( U" w
  5.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropLength, 0, swLengthUnit_e.swMM)
    & j1 N3 L* @! v( C" F7 c
  6.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropVolume, 0, swUnitsMassPropVolume_e.swUnitsMassPropVolume_Millimeters3)* ~6 h7 M/ e+ N; J! w8 F
  7.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsPowerUnits, 0, swUnitsPowerUnit_e.swUnitsPowerUnit_Watt)
    $ c9 B0 F1 s* @. p2 n# i& N% a
  8.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsForce, 0, swUnitsForce_e.swUnitsForce_Newtons)# _& a) K' B3 D7 j+ L
  9.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropVolume, 0, swUnitsMassPropVolume_e.swUnitsMassPropVolume_Millimeters3)! V/ T# u/ o. b' t
  10.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsTimeUnits, 0, swUnitsTimeUnit_e.swUnitsTimeUnit_Second)1 g0 W( g# h: b6 |/ c3 g2 p
复制代码
发表回复
您需要登录后才可以回帖 登录 | 注册

本版积分规则


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

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

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