Anyone know how to set up a macro so the task scheduler can open a file and then save it. Not to convert, just save.
Thanks.
SolidworksTask Scheduler
Anyone know how to set up a macro so the task scheduler can open a file and then save it. Not to convert, just save.
Thanks.
SolidworksTask Scheduler
You may use this macro Zoom and Rebuild
OR
You need to create SolidWorks Macro Template to use in task scheduler (Search for SolidWorks Macro Template under task scheduler help files)
Link is bad?
Manually found it on the website. Now, how do you use it? I can see the custom task in the task scheduler, but how do you point it to a specific folder?
Well I am having no luck....
I am a "real novice" when it comes to this kind of stuff. Seems as though the macro file has a lot of pointless characters in it when I try to view it in notepad.
Sorry for the bad link, I have fixed it now.
You just need to edit the macro as change the file location. And then finally run it though SW (no need to use task scheduler).
Extract the macro to a known location. Then check these linkf for how to
Edit a Macro
Run a Macro
And if you need to go via task scheduler route, you need to create a SolidWorks Macro Template
I am starting to get it now.....
But when I run it, I get this....
Good to know that you're getting into it.
Now to fix this issue, edit your macro (using the method I stated above) and go to Tools > References. Now uncheck any missing library and select the corresponding one for the SW version you have. Click OK to apply the changes and then click on Save to save the settings. Run the macro again (make sure you have changed the file location)
I think that I am close.....
Is this where you change the folder location?? Capture
And with these check marks it still errors out. Capture2
Here is the error. Capture3
Will this macro work as is with 2010? Or does it need modified?
Final Help?
Don't know why that is not working. Try the attached one, just extract and run.
Currently the macro works for SW Drawings. Change the codes for parts or assemblies. And no need to set the folder/file location in the macro, just use browse option.
Works like a champ!! Thanks a million.
Now if Solidworks can just figure out why the assm thumbnails got messed up in the first place.
It happens some time so a system restart might fix it
For some odd reason - the macro is erroring out after opeing precisely 128 files....
Duplicated it on 2 completely different folders.
Thoughts???
It can be because of the system resources. Not sure how to fix it or how about doing the files in order of 100 files per run.
Can you specify in the macro what file to start with? Or a range?
If the folder I want to update has more than 128 files I do not know how to make it start at that point.
Yes a range can be set. And to further use the macro, create another folder inside that folder and move the updated files into that folder. Now run the macro again to update the remaining files else it might keep on running on same files.
Give me some time to look at range thing.
Cool - thank you.
I just did another folder and it stops at exactly 128 files.
My system resources were fine during the process. Is there maybe a "ticker" or "counter" that is getting tripped and ending the process??
I added the error captures.
I have never updated that much number of files so not sure of reason for the error but here is the one with counter. It'll stop at 100 files
I edited my above message with captures -- any help?
I attempted to set the number to 200 on your new macro and it still stopped at 128.
Anyway to "type in" the starting file number and then it will go 128 from that one??
I said the macro stops at 128 (not sure why) in macro and that's why I have put the counter to 100. You may put 128 if you wish.
I don't know any option to do that. May be create another folder in the same location and move the updated files in that. After that rerun the macro.
Hi Michael,
I didn't have time to test this, but I suspect the problem was from the MAX_PATH constant set to 260 characters...
You must have a massive folder structure behind these assemblies you're trying to run, and by coincidence, it's always been the 128th assembly...
Try this macro out...and report back...
Hope this helps
Cheers
Please disregard my previous post...as that max_path constant was strictly for the search folder...
I'm assuming you trying to achieve the same you asked in your other thread....so go with the macro I wrote up instead...
As for what's wrong with this macro, my next guess would be, that the Function Dir that's being used to get the file list, must have a limitation in characters...if you still wish to use this macro...i would recommend moving your assemblies a couple of levels (of folders) down...
Here's the solution...
https://forum.solidworks.com/message/190147#190147
cheers
I have to hit OK button after every assembly closes
?????
Using which macro?
Deepak,
Is it possible to add the function of the macro below into your "Batch File Open and Save" macro, so that it can perform the original function and the additional function found on my macro below?
' ******************************************************************************
' Created and Copyright by Raúl Rosa (08/02/2010) - All rights Reserved
' ******************************************************************************
Dim swApp As Object
Dim Part As Object
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Dim MyProp(1, 1) As String
'Property names
MyProp(0, 0) = "ECCN"
MyProp(0, 1) = "Export Control Flag"
'Property values
MyProp(1, 0) = ""
MyProp(1, 1) = "EXPORT CONTROLLED: READ THE DESIGN BINDER"
Dim m As Integer
For m = 0 To 1
retval = Part.AddCustomInfo3("", MyProp(0, m), 30, _
MyProp(1, m))
Next m
Set SelMgr = Part.SelectionManager
boolstatus = Part.Extension.SelectByID2("Design Binder", "DOCSFOLDER", 0, 0, 0, False, 0, Nothing, 0)
boolstatus = Part.Extension.InsertAttachment("J:\SolidWorks 2009 Settings\Macros\Export Control\Add Export Control Metadata\EXPORT CONTROLLED.doc", False)
boolstatus = Part.Extension.InsertAttachment("J:\SolidWorks 2009 Settings\Macros\Export Control\Add Export Control Metadata\PROPRIETARY NOTICE.doc", False)
Dim longstatus As Long, longwarnings As Long
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
boolstatus = Part.Extension.SelectByID2("", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)
Dim myComment As Object
Set myComment = Part.Extension.AddComment("EXPORT CONTROLED")
Part.ClearSelection2 True
End Sub
-----------------------------------------------------------------------------------------------------------------------------------------
Thanks in advance for any help.
Raul
Yes it should be doable
Can you help with this?
I have tried, but cannot get it to work.
TIA,
Raul
Raul I have almost done it, just getting issues with adding properties but will fix them soon
Wow, that was fast. Thank you much.
I eagerly await.
Thanks again,
Raul
Here you go
Deepak,
You are the best. Thank you so much. Works great.
Raul
Ok, I promise this will be the last request:
Can you add the "Add comment macro" below you did for me to this?
--------------------------------------------------------------------
' Finally rebuild & save the files.
' Written by: Deepak Gupta (http://gupta9665.wordpress.com/)
' ------------------------------------------------------------------------------
Dim myAnnotation As Object
Dim myTextFormat As Object
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc
Dim selMgr As SelectionMgr
Dim sFileName As String
Dim Path As String
Dim MyProp(1, 1) As String
Dim m As Integer
Dim nErrors As Long
Dim nWarnings As Long
Sub main()
Path = BrowseFolder("Select a Path/Folder")
Path = Path + "\"
sFileName = Dir(Path & "*.sldprt")
Do Until sFileName = ""
Set swModel = swApp.OpenDoc6(Path + sFileName, swDocPART, swOpenDocOptions_Silent, "", nErrors, nWarnings)
'Property names
MyProp(0, 0) = "ECCN"
MyProp(0, 1) = "Export Control Flag"
MyProp(1, 0) = ""
MyProp(1, 1) = "EXPORT CONTROLLED: READ THE DESIGN BINDER"
Next m
Set selMgr = swModel.SelectionManager
swModel.DeleteCustomInfo ("EXPORT CONTROL FLAG") ' Will delete the existing custom property "EXPORT CONTROL FLAG" if exists
swModel.AddCustomInfo3 "", "EXPORT CONTROL FLAG", 30, "EXPORT CONTROLLED: READ THE DESIGN BINDER" 'Will add custom property "EXPORT CONTROL FLAG"
Dim myNote As Object
Dim myAnnotation As Object
Dim myTextFormat As Object
Set myNote = Part.InsertNote("$PRP:""EXPORT CONTROL FLAG""") ' Change setting here for font
If Not myNote Is Nothing Then
myNote.Angle = 0
boolstatus = myNote.SetBalloon(0, 0)
Set myAnnotation = myNote.GetAnnotation()
If Not myAnnotation Is Nothing Then
longstatus = myAnnotation.SetLeader3(swLeaderStyle_e.swNO_LEADER, 0, True, False, False, False)
boolstatus = myAnnotation.SetPosition(0#, 0#, 0#) ' Set the position of note to 0, 0, 0
boolstatus = myAnnotation.SetTextFormat(0, False, myTextFormat)
End If
End If
part.ClearSelection2 True
part.WindowRedraw
swModel.EditRebuild3
swModel.Save2 False
swApp.CloseDoc swModel.GetTitle
Set swModel = Nothing
sFileName = Dir
Loop
-----------------------------------------------------------------------------------------------------------------------------------------------
Here you go
Happy to help.. so no worries if you have more to ask
Fantastic. Thanks a million.
Ok, spoke too soon. One last request.
Can you add the follwoing to the macro as well?
------------------------------------------------------------------------------
Dim swApp As Object
Dim swPart As SldWorks.ModelDoc2
Const PicPath As String = "\\SW_Settings\Macros\background.tif"
Sub main()
Set swApp = Application.SldWorks
Set swPart = swApp.ActiveDoc
If swPart.SceneBkgImageFileName = "" Then
swPart.InsertBkgImage PicPath
Else
swPart.DeleteBkgImage
End If
End Sub
-------------------------------------------------------------------------------------
Thanks again.
R.
Can you put that picture to test the macro
see attached.
Thanks
Just add these lines above swModel.EditRebuild3 in the macro.
Thanks for everything.
Just note that after adding the background file, file size will increase.
Yes. and being that only umcompressed tif seem to be supported, I may not go this route, as it does increase the file size tremendowsly.
R.