几何尺寸与公差论坛

 找回密码
 注册
查看: 750|回复: 0

【转帖】using custom properties in a macro

[复制链接]
发表于 2009-4-12 22:45:00 | 显示全部楼层 |阅读模式
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
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|几何尺寸与公差论坛

GMT+8, 2024-12-23 23:06 , Processed in 0.036898 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

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