几何尺寸与公差论坛------致力于产品几何量公差标准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, 10:08 AM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】custom properties for multiple part configurations

custom properties for multiple part configurations
hi everyone,
i am very new to solidworks api. i don't know much visual basic, but i have written quite a bit in c++. i have written a macro using someone else's base code to insert custom property values into a part file. is there a way that i can use it for parts with multiple configurations, or will i have to input it manually in those cases?
click for full image
hi jonathan,
there are several threads on this forum regarding custom properties.
search about and if you cant find what you're after reply again here.
cheers,
--stav.
in this world i am nobody...
and nobody is perfect !!!
---------
solidworks office 2008 sp4.0
dell precision pws390
nvidia quadro fx 3450/4000 sdi
jonathan,
then go to that forum, and check the documentation for the "what's new in sw 2009".
you may be pleasantly surprised with some of the new functionality in 2009.
charles culp, cswp
aerospace design engineer
essex industries - st louis, missouri
sw2009 sp2.1
thanks for the link. i may not want to waste my time trying to figure out how to code this then. assuming that i will try to finish this, the problem that i was having concerned using multiple pages in vb. i wanted to have a main "custom props" tab and a secondary "config. spec." tab. the config. spec. tab would have certain standard information in the part file as a whole and other info. for each config. i wanted to have some way to populate a list and select the config. you want to work with. i'm just not really sure how to do this. i have zero training in vb and have been looking at other code and some how making things work. a pointer in the right direction would be very helpful
hi jonathan,
post what you have so far (your macro file) and also a list of the custom properties that you are trying to add/edit in your parts and which ones are to be configuration specific. i have been upgrading our company's macro over the past few days so most of the code necessary is still fresh in my head.
cheers,
declan.
this is the macro:
'see custprop form for file information.
public swapp as object
public currentdoc as object
public inilist as string
public properties(10) as string
public propname(10) as string
public confignum as long
public confignames as variant
public configcount as long
public propcheck as string
public csid as string
public description as string
public oem1 as string
public oem2 as string
public oem3 as string
public oem4 as string
public drawnby as string
public drawndate as string
public alt as string
public notes as string
public checkcsid as string
public checkdescription as string
public checkoem1 as string
public checkoem2 as string
public checkoem3 as string
public checkoem4 as string
public checkdrawnby as string
public checkdrawndate as string
public checkalt as string
public checknotes as string
public const swcustominfotext = 30
public const swviewanimationspeed = 38
const swdocpart = 1
const swdocassembly = 2
const swdocdrawing = 3
sub checkprops()
' get custom properties
checkcsid = currentdoc.custominfo2("", "columbia id") ' get current columbia steel id no
checkdescription = currentdoc.custominfo2("", "description") ' get current description
checkoem1 = currentdoc.custominfo2("", "oem1") ' get current oem1
checkoem2 = currentdoc.custominfo2("", "oem2") ' get current oem2
checkoem3 = currentdoc.custominfo2("", "oem3") ' get current oem3
checkoem4 = currentdoc.custominfo2("", "oem4") ' get current oem4
checkdrawnby = currentdoc.custominfo2("", "drawn by") ' get drawing engineer
checkdrawndate = currentdoc.custominfo2("", "date") ' get original drawn date
checkalt = currentdoc.custominfo2("", "alt") ' get current revision
checknotes = currentdoc.custominfo2("", "notes") ' get current notes
call enterconfiggenprops
end sub
sub enterconfiggenprops()
' initiate dialog box
load custprop
custprop.show
' set custom properties
for y = 0 to 9
currentdoc.custominfo2("", propname(y)) = properties(y)
next y
end sub
sub main()
set swapp = createobject("sldworks.application")
set currentdoc = swapp.activedoc
set part = swapp.activedoc
' no document loaded error handler
if part is nothing then
msgbox "no document loaded!", vbcritical
end
else
end if
part.clearselection2 true
' assign custom properties
propname(0) = "csid"
propname(1) = "description"
propname(2) = "oem1"
propname(3) = "oem2"
propname(4) = "oem3"
propname(5) = "oem4"
propname(6) = "drawnby"
propname(7) = "drawndate"
propname(8) = "alt"
propname(9) = "notes"
' add custom properties (won't overwrite if they already exist)
prop = currentdoc.addcustominfo3("", propname(0), swcustominfotext, " ")
prop = currentdoc.addcustominfo3("", propname(1), swcustominfotext, " ")
prop = currentdoc.addcustominfo3("", propname(2), swcustominfotext, " ")
prop = currentdoc.addcustominfo3("", propname(3), swcustominfotext, " ")
prop = currentdoc.addcustominfo3("", propname(4), swcustominfotext, " ")
prop = currentdoc.addcustominfo3("", propname(5), swcustominfotext, " ")
prop = currentdoc.addcustominfo3("", propname(6), swcustominfotext, " ")
prop = currentdoc.addcustominfo3("", propname(7), swcustominfotext, " ")
prop = currentdoc.addcustominfo3("", propname(8), swcustominfotext, " ")
prop = currentdoc.addcustominfo3("", propname(9), swcustominfotext, " ")
call checkprops
end sub
this is the code behind the form:
'''''''begin code added to disable "x" button
private declare function removemenu lib "user32" (byval hmenu as long, byval nposition as long, _
byval wflags as long) as long
private declare function getsystemmenu lib "user32" (byval hwnd as long, byval brevert as long) as long
private declare function findwindow lib "user32.dll" alias "findwindowa" (byval lpclassname as string, _
byval lpwindowname as string) as long
private const mf_byposition = &h400&
'''''''end code added to disable "x" button
private sub clearvalues_click()
csid.text = ""
description.text = ""
oem1.text = ""
oem2.text = ""
oem3.text = ""
oem4.text = ""
drawnby.text = ""
drawndate.text = ""
alt.text = ""
notes.text = ""
end sub
private sub copyproperties_click()
' get custom properties from textboxes
properties(0) = csid.text
properties(1) = description.text
properties(2) = oem1.text
properties(3) = oem2.text
properties(4) = oem3.text
properties(5) = oem4.text
properties(6) = drawnby.text
properties(7) = drawndate.text
properties(8) = alt.text
properties(9) = notes.text
currentdoc.editrebuild ' rebuild document
custprop.hide 'hide dialog box
'not having an unload function leaves these values in memory by keeping this macro
'active but not displayed.
end sub
private sub copyprophelp1_click()
userform1.show 'show help window
end sub
'private sub label9_click()
'msgbox "see " & chr(34) & "help" & chr(34) & " for details", vbexclamation
'end sub
private sub tddate_click()
drawndate.text = str(date) 'sets date to today's date
end sub
private sub userform_initialize()
'disable the "x" button
dim lhwnd as long
lhwnd = findwindow(vbnullstring, "custom properties") 'change to match userforms caption
do while lhwnd = 0
lhwnd = findwindow(vbnullstring, "custom properties") 'change to match userforms caption
doevents
loop
removemenu getsystemmenu(lhwnd, 0), 9, mf_byposition 'when using by position, 6 represents the 7th menu item (including separators)
'"x" button now disabled
' establishes fields and their values
csid.text = checkcsid
description.text = checkdescription
oem1.text = checkoem1
oem2.text = checkoem2
oem3.text = checkoem3
oem4.text = checkoem4
drawnby.text = checkdrawnby
drawndate.text = checkdrawndate
alt.text = checkalt
notes.text = checknotes
' list originators (modify this section to list internal contributors)
'drawnby.clear
' inilist = swapp.getcurrentmacropathfolder ' get macro path
' inilist = inilist + "\customproperties.ini" ' set source filename
' set rbo = createobject("scripting.filesystemobject")
' if rbo.fileexists(inilist) then ' does source file exist?
' set rbofile = rbo.opentextfile(inilist, 1)
' do until rbofile.atendofstream
' drawnby.additem rbofile.readline
' loop
' else
' drawnby.additem "g. stegmaier"
' drawnby.additem "m. perez"
' drawnby.additem "j. maguire"
'drawnby.additem "j. sakkos"
'end if
end sub
private sub cancel_click()
end ' quit macro
end sub
public sub save_click()
' get custom properties from textboxes
properties(0) = csid.text
properties(1) = description.text
properties(2) = oem1.text
properties(3) = oem2.text
properties(4) = oem3.text
properties(5) = oem4.text
properties(6) = drawnby.text
properties(7) = drawndate.text
properties(8) = alt.text
properties(9) = notes.text
' refresh document and unload form
currentdoc.editrebuild ' rebuild document
custprop.hide 'hide dialog box
unload custprop 'removes macro from memory on end sub
end sub
i just want a tab for configuration specific properties w/ the same info as the custom properties one. thank you for the help
answer hi jonathan,
i had bit of free time today and i was feeling generous so i done you a small favour. i have written the macro i "think" you are looking for.
i have tested it with sw2007 sp5.0 and sw2008 sp4.0 and it seems to be working fine, but you will be the better judge. let me know if it works like you want it, if not let me know and i can make the few changes for you. feel free to make any changes or improvements yourself.
make sure to place the macro file and ini file in the same folder. the ini file just contains a list of engineers names (as i saw a list of names in your posted code).
you may need to change the type library and constant references in the macro to suit your version of solidworks, using tools, references.
anyhow, i hope it is what you were looking for.
cheers,
declan.
declan,
thank you very much for your help. it is not exactly how i imagined it, but does everything that we need it to. the only thing i had to do was add a few more engineer names for our older documents. again thank you, it was very kind of you.
hi jonathon,
no problem, i was glad to help, it was great practice for me to do it. happy to hear it is working.
just as a matter of interest, what part of the macro is not how you imagined it would be?. i'm just curious.
i was just checking over it again and you will need to add a little bit of code to the "main" sub. the current code doesn't have error handling for when someone tries to use the macro while a drawing is the active document. just paste these additional few lines into the select statement and this should take care of it.
case swdocdrawing
msgbox "please open a solidworks part or assembly file!", _ vbinformation, "custom properties"
end
cheers,
declan.
the funtionality of the macro is perfect, i had just pictured the layout being slightly different. i actually like the way you did it much better than how i planned to make it. i added the code and everything works great.
quick
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
 


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

高级搜索
显示模式

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

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

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】looking for help debugging hatch macro please yang686526 SolidWorks二次开发 0 2009-04-12 09:34 PM
【转帖】creating a reference poin on a surface yang686526 SolidWorks二次开发 0 2009-04-12 08:36 PM
【转帖】batch printing as pdfs from a list bo yang686526 SolidWorks二次开发 0 2009-04-12 08:16 PM
【转帖】draw shaft using visual basic application yang686526 SolidWorks二次开发 0 2009-04-12 06:01 PM


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


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