QQ登录

只需一步,快速开始

登录 | 注册 | 找回密码

三维网

 找回密码
 注册

QQ登录

只需一步,快速开始

展开

通知     

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

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

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

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

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

x
本帖最后由 steve_suich 于 2015-1-9 17:00 编辑 1 x8 @/ K! Q2 G; X  D
4 A% A# K! L# J1 N$ r5 k# F
VB.NET代码* W1 C" b, l9 b0 K) f( @. K' [6 g
引用SW库 : SolidWorks.Interop.sldworks.dll,SolidWorks.Interop.swconst.dll: s( o- u. n. e4 q+ P  N7 i
连接SW,打开文件  :
  1. Dim swapp As SldWorks# `! e- E. O, h; C
  2. Dim swdoc As ModelDoc2! U; ?) n4 h: v& r" w# c: S* ~2 u: {
  3. swapp = GetObject(, "SldWorks.Application")
    & d9 Y9 f& H/ m% G# X7 k3 c# _) M
  4. With OpenFileDialog1: F( a7 R. u+ A6 p9 F& C6 y4 o- N
  5.             .Filter = "SW文件(*.sldprt;*.sldasm)|*.sldprt;*.sldasm"' g  @* R! [: G# W9 t
  6.             .FilterIndex = 1+ b, `6 M, k$ I2 H0 I
  7.             .Title = "选择零件或者装配件(Ctrl可多选)"/ ^* V2 J& J5 H! s1 U8 w  y; K/ o
  8.         End With7 f3 R! D7 t4 T9 ~
  9.         If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then4 b  p  L1 ~1 B+ ~7 z
  10.             Dim stname As String5 j, j) m! K4 u3 _& R, c
  11.             For Each stname In OpenFileDialog1.FileNames8 o' _, [. y5 a- @" R
  12.                 If Mid(stname, Len(stname) - 6) = ".SLDPRT" Then/ ?6 g. L. I, w3 r
  13.                     swapp.OpenDoc(stname, 1)
    * Q3 s' y3 ^6 c( I0 l  X8 m! R
  14.                 ElseIf Mid(stname, Len(stname) - 6) = ".SLDASM" Then
    ( o+ @- {* F6 x7 C8 j
  15.                     swapp.OpenDoc(stname, 2)
    % y$ Q4 P+ K  _: J# [
  16.                 End If
    % t; V4 _, x! ^3 D. C
  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) l2 p5 Q! H. a& W' w

' [1 k6 v- j, Y7 ]2 A添加自定义属性:swdoc.AddCustomInfo2(“自定义属性名称”, swCustomInfoType_e.swCustomInfoText, "内容")! F/ _  J0 J% a, I. {
还可以这样:
, @- m4 G3 A+ r3 f. Z, Tswdoc.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.gif3 F9 U& a8 q) T+ p0 I( ~
只学了点皮毛。抛钻引玉!!
2 W. X" G1 M- |0 M) ~
我想应该是这个吧。* f# [9 n& W; h/ r" L7 k/ p( A
swmodel.SketchManager.InsertSketch(True)
 楼主| 发表于 2015-1-10 14:06:05 | 显示全部楼层 来自: 中国广东深圳
foxjinlin 发表于 2015-1-9 19:08 static/image/common/back.gif; ]+ [: n& e" U# b
退出并保留草图绘制,代码怎么写
0 H3 ~5 e9 g8 `6 p
我想应该是这个吧。( @! \" `. _1 A1 |2 o7 ]& x& O8 w  u
swmodel.SketchManager.InsertSketch(True)
 楼主| 发表于 2015-1-10 14:07:11 | 显示全部楼层 来自: 中国广东深圳
ss988 发表于 2015-1-9 19:47 static/image/common/back.gif
, r, j) K& Z; |  |2 ]( Z3 J3d草图每两条线倒R角怎样选择直线?楼主会吗?

8 j# A5 k* E& A6 u' I) a这个不会,期待高手解答。
 楼主| 发表于 2015-1-10 14:27:26 | 显示全部楼层 来自: 中国广东深圳
Mid(stname, Len(stname) - 6) = ".SLDPRT"
+ z8 B2 ?8 ]- v# `# m& R7 F) M! B- x改为 Path.GetExtension(stname) = ".SLDPRT" 更合理。
 楼主| 发表于 2015-1-14 08:57:07 | 显示全部楼层 来自: 中国广东深圳
单位设置:
  1. swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitSystem, 0, swUnitSystem_e.swUnitSystem_Custom)6 _8 E- H& R0 Q1 L' ^6 v- L
  2.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsLinear, 0, swLengthUnit_e.swMM)
    3 }$ x9 Y" L( F& @/ A" c
  3.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsDualLinear, 0, swLengthUnit_e.swINCHES)
    / D1 \; ~+ e  w8 _4 v
  4.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropMass, 0, swUnitsMassPropMass_e.swUnitsMassPropMass_Kilograms)
    : W: T. Y! K' f0 s, S5 ^9 L
  5.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropLength, 0, swLengthUnit_e.swMM)3 R3 y: |1 Y, C; }, e- c
  6.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropVolume, 0, swUnitsMassPropVolume_e.swUnitsMassPropVolume_Millimeters3); k# M. [" Z: R. }. d
  7.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsPowerUnits, 0, swUnitsPowerUnit_e.swUnitsPowerUnit_Watt)2 C7 X$ }! q4 C6 w, l1 l1 T" P
  8.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsForce, 0, swUnitsForce_e.swUnitsForce_Newtons)2 e, k; `# x, q* V
  9.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropVolume, 0, swUnitsMassPropVolume_e.swUnitsMassPropVolume_Millimeters3)
    , F# A& o& ^: `; I0 P# \
  10.         swdoc.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsTimeUnits, 0, swUnitsTimeUnit_e.swUnitsTimeUnit_Second): Y# O" S: P% d  t1 m
复制代码
发表回复
您需要登录后才可以回帖 登录 | 注册

本版积分规则


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

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

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