![]() |
【转帖】a simple macro help
a simple macro help.
i want to assign custom properties to part file or assembly file base on the file name structure. the file name is like 1234567890baseplate.sldprt, which is 10 digit number plus part description. so how can i assign the first 10 digit number to "partno" custom properties and assign the base plate ( the rest of the strings) as " description" custom properties. thanks... mechanical design engineer (cswp, cswa, cswp-core | cdes | smtl | surf) hi shaodun, what you can do is strip the extension(always 7 characters) of the file name and then get the first 10 characters to use for "partno" and the rest for description". code wise this can be done as seen below: option explicit dim swapp as sldworks.sldworks dim swmodel as sldworks.modeldoc2 dim custpropmgr as sldworks.custompropertymanager dim title as string, name as string, descr as string dim retval as long sub main() set swapp = application.sldworks set swmodel = swapp.activedoc title = swmodel.gettitle title = left(title, (len(title) - 7)) name = left(title, 10) descr = right(title, len(title) - 10) set custpropmgr = swmodel.extension.custompropertymanager("") 'if the custom properties do not exist if they do exist yu need to use custompropertymanager::set instead retval = custpropmgr.add2("partno", swcustominfotype_e.swcustominfotext, name) retval = custpropmgr.add2("description", swcustominfotype_e.swcustominfotext, descr) end sub in this world i am nobody... and nobody is perfect ;) !!! --------- solidworks office 2008 sp4.0 dell precision pws390 nvidia quadro fx 3450/4000 sdi answer title will not always be the actual filename can be totally different, blank, with a * if not saved, or custom. option explicit dim swapp as sldworks.sldworks dim swmodel as modeldoc2 dim cpm as custompropertymanager sub main() set swapp = application.sldworks set swmodel = swapp.activedoc set cpm = swmodel.extension.custompropertymanager("") dim path as string, filename as string, partno as string, desc as string path = swmodel.getpathname filename = mid$(path, instrrev(path, "\") + 1) ' with extension filename = left$(filename, instrrev(filename, ".") - 1) ' remove extension partno = left(filename, 10) desc = right(filename, len(filename) - 10) cpm.delete "partno" cpm.delete "description" cpm.add2 "partno", swcustominfotext, partno cpm.add2 "description", swcustominfotext, desc end sub originally posted by: luke malpass title will not always be the actual filename can be totally different, blank, with a * if not saved, or custom. end sub perfect !!! many thanks!!! mechanical design engineer (cswp, cswa, cswp-core | cdes | smtl | surf) quick |
所有的时间均为北京时间。 现在的时间是 07:46 PM. |