![]() |
【转帖】new to api need help
new to api & need help
i try to make a macro that saves the active document to edrawing file in the same original drawing path and with the same name. so i started recording it and click on file-> save as -> choose edrawings extension and press enter but after that when i used this macro i found that it saves the active document in the same folder as the file i used to create the macro with and with the same name. the code below is the result. could any one help me with that and tell me what i have to relplace with what to make createthe edrawing file from the active sheet in the path of the drawing file. thanks in advanced. ' ****************************************************************************** ' c:\docume~1\mc1c6~1.abd\locals~1\temp\swx3912\macro1.swb - macro recorded on 12/21/08 by m. abdel moniem ' ****************************************************************************** dim swapp as object dim part as object dim selmgr as object dim boolstatus as boolean dim longstatus as long, longwarnings as long dim feature as object sub main() set swapp = application.sldworks set part = swapp.activedoc set selmgr = part.selectionmanager part.extension.saveas "d:\cad-cam-cae\solidworks\work\test\test file.edrw", 0, 0, nothing, longstatus, longwarnings end sub mohamed abdel moniem | mechanical engineer cswp, cswa, cswp core, cswp-smtl solidworks 2009 sp3.0 vista x64 sp1.0 intel q6600, 8gb ram ati hd 4850 3dconnexions spacenavigator try this. option explicit sub main() dim swapp as sldworks.sldworks dim part as sldworks.modeldoc2 dim longstatus as long, longwarnings as long dim filename as string set swapp = application.sldworks set part = swapp.activedoc filename = part.getpathname filename = left(filename, len(filename) - 6) select case part.gettype case swdocdrawing filename = filename & "edrw" case swdocassembly filename = filename & "easm" case swdocpart filename = filename & "eprt" end select swapp.setuserpreferenceintegervalue swedrawingssaveasselectionoption, swedrawingsaveall part.extension.saveas filename, 0, 0, nothing, longstatus, longwarnings end sub mahir abrahim, cswp/core. cswp/smtl mechanical design engineer sw 2009 sp2.1 proe wf3/4 i tried to do it but i think i did it in a wrong way. i copied the code you sent to me and replace it with mine as follows but it doesn't work. ' ****************************************************************************** ' c:\docume~1\mc1c6~1.abd\locals~1\temp\swx3912\macro1.swb - macro recorded on 12/21/08 by m. abdel moniem ' ****************************************************************************** dim swapp as object dim part as object dim selmgr as object dim boolstatus as boolean dim longstatus as long, longwarnings as long dim feature as object option explicit sub main() dim swapp as sldworks.sldworks dim part as sldworks.modeldoc2 dim longstatus as long, longwarnings as long dim filename as string set swapp = application.sldworks set part = swapp.activedoc filename = part.getpathname filename = left(filename, len(filename) - 6) select case part.gettype case swdocdrawing filename = filename & "edrw" case swdocassembly filename = filename & "easm" case swdocpart filename = filename & "eprt" end select swapp.setuserpreferenceintegervalue swedrawingssaveasselectionoption, swedrawingsaveall part.extension.saveas filename, 0, 0, nothing, longstatus, longwarnings end sub swapp.setuserpreferenceintegervalue swedrawingssaveasselectionoption, swedrawingsaveall part.extension.saveas filename, 0, 0, nothing, longstatus, longwarnings end sub mohamed abdel moniem | mechanical engineer cswp, cswa, cswp core, cswp-smtl solidworks 2009 sp3.0 vista x64 sp1.0 intel q6600, 8gb ram ati hd 4850 3dconnexions spacenavigator you have multiple object declarations, e.g. swapp is declared twice. don't just replace the code between "sub main()" and "end". replace all the code with what i listed in my last post. mahir abrahim, cswp/core. cswp/smtl mechanical design engineer sw 2009 sp2.1 proe wf3/4 mahir, thank you finally it works, in the beginning it wasn't working because there was a problem in the line ( filename = left(filename, len(filename) - 6) ) i opened a macro for save as pdf i already have searched for a line with the same syntax and i found it but as follows: filename = strings.left(filename, len(filename) - 6) so i edit the macro with as that one and it works. thanks so much for your help the final macro is the following, also the macro is attached below. ' ****************************************************************************** ' c:\docume~1\mc1c6~1.abd\locals~1\temp\swx3912\macro1.swb - macro recorded on 12/21/08 by m. abdel moniem ' ****************************************************************************** option explicit dim swapp as object dim part as object dim selmgr as object dim boolstatus as boolean dim longstatus as long, longwarnings as long dim feature as object sub main() dim swapp as sldworks.sldworks dim part as sldworks.modeldoc2 dim longstatus as long, longwarnings as long dim filename as string set swapp = application.sldworks set part = swapp.activedoc filename = part.getpathname filename = strings.left(filename, len(filename) - 6) select case part.gettype case swdocdrawing filename = filename & "edrw" case swdocassembly filename = filename & "easm" case swdocpart filename = filename & "eprt" end select swapp.setuserpreferenceintegervalue swedrawingssaveasselectionoption, swedrawingsaveall part.extension.saveas filename, 0, 0, nothing, longstatus, longwarnings end sub mohamed abdel moniem | mechanical engineer cswp, cswa, cswp core, cswp-smtl solidworks 2009 sp3.0 vista x64 sp1.0 intel q6600, 8gb ram ati hd 4850 3dconnexions spacenavigator i'm glad it's working. sounds like you're using vsta instead of just vba. i've never used it, but i hear it's supposed to be a more .net implementation of vba, which explains why you had to use strings.left. also, i would still get rid of everything before "sub main()" except for "option explicit". those lines are redundant and might cause problems later. mahir abrahim, cswp/core. cswp/smtl mechanical design engineer sw 2009 sp2.1 proe wf3/4 actually i don't know what is the difference between vsta & vba. but at the end it works fine till now if i got any problem i'll remove the lines before "sub main()". i think i have to join a course for vba asap. and then go in to the world of api. i think i found how mach it's useful very late. thank you again mahir. mohamed abdel moniem | mechanical engineer cswp, cswa, cswp core, cswp-smtl solidworks 2009 sp3.0 vista x64 sp1.0 intel q6600, 8gb ram ati hd 4850 3dconnexions spacenavigator thanks,i am study. quick |
| 所有的时间均为北京时间。 现在的时间是 08:46 AM. |