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

using custom properties in a macro
hello all, i am trying to make up a macro that can be used as a tool bar icon that will export a drawing straight to pdf. i have seen a couple of these around and i think a member on here has one on his website.
but i also want the macro the pull the drawing revision letter and attach it to the file name. is that possible? how would i got about it?
i don't have much vb experience and all / any help or suggestions is appreaciated.
marc d
btw, we are running sw07 sp 5
edited: 06/23/2008 at 02:35 pm by marc dickinson
dim swapp, model as object
dim modname, newname, rev, fname as string
sub main()
set swapp = createobject("sldworks.application")
set model = swapp.activedoc
modname = model.gettitle
modname = left(modname, instr(1, modname, " ") - 1)
rev = model.custominfo("revision")
fname = modname + "_rev" + rev
pdf = "c:\" + fname + ".pdf"
model.saveas2 pdf, 0, true, false
end sub
this is short and simple. doesn't do a whole lot other than save a pdf. no error messages or catching though.
drc inc.
minneapolis, mn
.designreadycontrols.com
sw2007 sp5.0
core2 quad
3gb ram
xp pro sp2
ati firegl v3600
how would i add that into what i already have? which is:
' ******************************************************************************
' this macro can be used as a toolbar icon for one-click creation of a pdf
' ******************************************************************************
dim swapp as sldworks.sldworks
dim part as sldworks.modeldoc2
sub main()
set swapp = application.sldworks
set part = swapp.activedoc
dim filepath as string
dim pathsize as long
dim pathnoextension as string
dim newfilepath as string
filepath = part.getpathname
pathsize = strings.len(filepath)
pathnoextension = strings.left(filepath, pathsize - 6)
rev = model.custominfo("revision")
newfilepath = pathnoextension & rev & "pdf"
part.saveas2 newfilepath, 0, true, false
msgbox "saved at " & newfilepath
end sub
edited: 06/23/2008 at 03:41 pm by marc dickinson
your example will already to what you are after if you simply add a period (.) to this line:
newfilepath = pathnoextension & rev & ".pdf"
if i wanted to include information from the drawings properties such as a date or the drawing size, what would the call out be (drawing?.custominfo)?
thanks for everyones help.
for drawing size you have the get the current active sheet (drawingdoc.getcurrentsheet), then call getsize. for date you can either get the date set in a custom property field like you have done with revision or using modeldoc2.summaryinfo().
how do you call getsize? thanks for the help and i may look into purchasing your book once i finish taking a visual basic course in the coming months at a nearby community college.
marc d
type getsize into the api help it should give you an example
can you offer me a little more help / guidence?
this is what i have so far:
dim swapp, model as object
dim modname, newname, rev, fname as string
sub main()
set swapp = createobject("sldworks.application")
set model = swapp.activedoc
modname = model.gettitle
modname = left(modname, instr(1, modname, " ") - 1)
rev = model.custominfo("revision")
fname = modname + rev
pdf = "c:\" + fname + ".pdf"
model.saveas2 pdf, 0, true, false
end sub
edited: 06/25/2008 at 03:55 pm by marc dickinson
sub main()
dim swapp as sldworks.sldworks
dim swdraw as sldworks.drawingdoc
dim swsheet as sldworks.sheet
dim vsheetprops as variant
dim bfirstang as boolean
dim bret as boolean
set swapp = application.sldworks
set swdraw = swapp.activedoc
set swsheet = swdraw.getcurrentsheet
' get current sheet properties
vsheetprops = swsheet.getproperties
' current sheet properties
debug.print "name = " + swsheet.getname
debug.print " templatename = " & swsheet.gettemplatename
debug.print " papersize = " & vsheetprops(0)
debug.print " templatein = " & vsheetprops(1)
debug.print " scale1 = " & vsheetprops(2)
debug.print " scale2 = " & vsheetprops(3)
debug.print " firstangle = " & vsheetprops(4)
debug.print " width = " & vsheetprops(5)
debug.print " height = " & vsheetprops(6)
' switch projection property
bfirstang = vsheetprops(4)
vsheetprops(4) = not bfirstang
' apply updated sheet properties
swsheet.setproperties _
vsheetprops(0), _
vsheetprops(1), _
vsheetprops(2), _
vsheetprops(3), _
vsheetprops(4), _
vsheetprops(5), _
vsheetprops(6)
' current projection property
debug.print " "
debug.print " new firstangle setting = " & vsheetprops(4)
end sub
hello there again. i have another question.
this is what i have so far. what would i need to add to get sw to throw up that box asking you to select which sheets to export?
dim swapp, model as object
dim modname, newname, rev, fname as string
sub main()
set swapp = createobject("sldworks.application")
set model = swapp.activedoc
modname = model.gettitle
modname = left(modname, instr(1, modname, " ") - 1)
rev = model.custominfo("revision")
fname = modname + rev
pdf = "c:\smarteam work\" + fname + ".pdf"
model.saveas2 pdf, 0, true, false
end sub
thanks and all help is appreaciated.
marc d
edited: 09/12/2008 at 09:46 am by marc dickinson
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
 


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

高级搜索
显示模式

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

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

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】setting custom properties yang686526 SolidWorks二次开发 0 2009-04-12 10:24 PM
【转帖】overwriting custom properties yang686526 SolidWorks二次开发 0 2009-04-12 09:59 PM
【转帖】macro for adding customconfiguration properties yang686526 SolidWorks二次开发 0 2009-04-12 09:37 PM
【转帖】setting custom properties yang686526 SolidWorks二次开发 0 2009-04-12 07:36 PM


所有的时间均为北京时间。 现在的时间是 03:22 PM.


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