几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量  


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 仿射空间:CAX软件开发(三)二次开发与程序设计 » CAD二次开发 » SolidWorks二次开发
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


 
 
主题工具 搜索本主题 显示模式
旧 2009-04-13, 09:49 AM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】components on layers

components on layers
our company has to export drawings to acad for customers. we want these drawings to be on layers. currently notes, etc. are on layers, but we want individual components in assemblies to be on separate layers. yesterday i found a macro in the sw api help files that says it will do this, but i can't figure out how. i saved it as a macro, assigned it to an icon, select the view, and hit the icon. nothing seems to happen though. can anyone tell me what is wrong, or how to do this?
(i am trying to learn vbscript, but am still very new)
thank you!
here's the script i'm working w/:
(can someone tell me how i can copy/paste the script into here w/o it screwing the format? any easy way for me to show you what i'm working w/ would be great.)
edited: 04/20/2007 at 04:06 pm by steven wood
steven,
how are you copying the code?
are you using vbscript or vba? i do not know how vbscript and sw get along.
if you have the code in the form of a swp file. put it in a zip file and upload that.
you could also tell us where in api you found the example.
also what version of solidworks and sp are you using?
sa
edited: 04/20/2007 at 06:23 pm by solidair
oh, so a zip file will upload, okay. i tried it w/ a text file but that wouldn't.
in the sw api help you can find it under: "put assemblyfff"> components in drawing view on different layersfff"> example (vb)
i tried to copy/paste (ctrl-c/ctrl-v) the test straight from there, from the swp file, and from a text file into this thread, but none of those format it correctly and it looks like one big paragraph. i am also attaching a zip file.
i copied the code exactly from the help file, and it says that is vb. that's all i know about whether the macro is one or another. (i'm new to all of this)
i'm using sw 2007 sp3.1.
thanks,
steven
edited: 04/23/2007 at 09:18 am by steven wood
steven,
you are not alone in having trouble pasting code directly into posts. several others have had the same problem. i wish i could be there when you were doing it so i could see what is going on. as you can see, at the end of this post, i took the macro from your zip file, made a few adjustments and pasted it into this reply. and, except for losing the indentations, it looks pretty good.
the problem with some of solidworks examples is that sw tries hard to format the code so you can just paste it into a macro, but to make it more readable they double space the lines. the vba editor gets confused with this when underscores are used for line continuation. when you pasted the example into the vba editor, there were three different parts where the text turned red. red text always means there is an error in the code format (unless you changed it to another color in the options dialog) and it has to be corrected before it will run the code. for example, if you look at this code in your macro:
private sub changecomponentlayer _
()
( _
swapp as sldworks.sldworks, _
swdraw as sldworks.drawingdoc, _
swdrawcomp as sldworks.drawingcomponent, _
slayername as string _
)
lines 3, 4, 5, 6 and 8 were red. to fix this, i had to get rid of double spacing (and the extra parenthesises) like this
private sub changecomponentlayer( _
swapp as sldworks.sldworks, _
swdraw as sldworks.drawingdoc, _
swdrawcomp as sldworks.drawingcomponent, _
slayername as string _
)
to get the code to turn black. try pasting the code below into a macro and running it (i tried it before posting and it worked for me).
sa
'-------------------
'
' preconditions:
' (1) drawing document is open.
' (2) drawing view of an assembly is selected.
'
' postconditions:
' (1) new drawing layer is created for each component.
' (2) each part is put on its own layer.
'
' note: illegal characters are replaced with legal characters when creating a new
' drawing layer.
'
'-------------------
option explicit
public enum swlinestyles_e
swlinecontinuous = 0
swlinehidden = 1
swlinephantom = 2
swlinechain = 3
swlinecenter = 4
swlinestitch = 5
swlinechainthick = 6
end enum
public enum swlineweights_e
swlw_none = -1
swlw_thin = 0
swlw_normal = 1
swlw_thick = 2
swlw_thick2 = 3
swlw_thick3 = 4
swlw_thick4 = 5
swlw_thick5 = 6
swlw_thick6 = 7
swlw_number = 8
swlw_layer = 9
end enum
private sub changecomponentlayer( _
swapp as sldworks.sldworks, _
swdraw as sldworks.drawingdoc, _
swdrawcomp as sldworks.drawingcomponent, _
slayername as string _
)
dim bret as boolean
' form a legal layer name by replacing backslash (/) and at sign (@) symbols
' with underscores
slayername = replace(slayername, "/", "_")
slayername = replace(slayername, "@", "_")
bret = swdraw.createlayer( _
slayername, _
"layer for " & slayername, _
0, swlinecontinuous, swlw_normal, true): debug.assert bret
swdrawcomp.layer = slayername
end sub
sub processdrawingcomponent _
( _
swapp as sldworks.sldworks, _
swdraw as sldworks.drawingdoc, _
swdrawcomp as sldworks.drawingcomponent, _
spadstr as string _
)
dim vdrawcompchildarr as variant
dim vdrawcompchild as variant
dim swdrawcompchild as sldworks.drawingcomponent
debug.print spadstr & swdrawcomp.name
changecomponentlayer swapp, swdraw, swdrawcomp, swdrawcomp.name
vdrawcompchildarr = swdrawcomp.getchildren
if not isempty(vdrawcompchildarr) then
for each vdrawcompchild in vdrawcompchildarr
set swdrawcompchild = vdrawcompchild
processdrawingcomponent swapp, swdraw, swdrawcompchild, spadstr + " "
next
end if
end sub
sub main()
dim swapp as sldworks.sldworks
dim swmodel as sldworks.modeldoc2
dim swdraw as sldworks.drawingdoc
dim swselmgr as sldworks.selectionmgr
dim swview as sldworks.view
dim swdrawcomp as sldworks.drawingcomponent
dim bret as boolean
set swapp = application.sldworks
set swmodel = swapp.activedoc
set swdraw = swmodel
set swselmgr = swmodel.selectionmanager
set swview = swselmgr.getselectedobject5(1)
set swdrawcomp = swview.rootdrawingcomponent
debug.print "file = " & swmodel.getpathname
debug.print " " & swview.name & " [" & swview.type & "]"
processdrawingcomponent swapp, swdraw, swdrawcomp, " "
end sub
thank you!
and dang am i an idiot!!! i knew that... i knew to fix that, and completely missed it.
this script should be a big help to us, so this is a huge break through!
thanks again, and i'm sure y'all will be seeing a lot more of me.
steven
i know this is an old topic. but, i was hoping to find a version of this program with some more features...
- automatically assign random colors to each of the layers.
- option to treat sub assemblies as one part rather than always putting each individual part on a separate layer.
- the layer names are too long, and the layer management window will not expand large enough to see the layer name.
joe dunfee
sw 2008 sp4
sw 2009 sp3.0 windows xp
hp compaq dc5800 microtower
nvidia quadro fx 3700
quick
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
 


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭

相似的主题
主题 主题发起者 论坛 回复 最后发表
pc-dmis 3.6 mr1 发布了 huangyhg PC-DMIS 0 2009-04-06 08:46 PM


所有的时间均为北京时间。 现在的时间是 10:04 AM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多