Hi,
I am working on a macro to generate drawing and other thing from assembly components.I have a problem becouse newly generated drawings do NOT save if I use No. 2. way of saving it does not save the file! If I use No. 1. works fine but I get windows explorer window to save the drawing.I would like the file to be saved silently with no user touch.
Here is a sub I use to save:
Thank you for any help.
SolidworksApi macros
If you have not previously saved the drawing you will need to use swModel.Extension.SaveAs method to save it for the first time. That method will allow you to specify the silent option. Subsequent saves can use the Save3 method.
2016 SOLIDWORKS API Help - Save3 Method (IModelDoc2)
swModel.Save3(swSaveAsOptions_e.swSaveAsOptions_Silent + swSaveAsOptions_e.swSaveAsOptions_SaveReferenced, errors, warnings)
I hate code screendump. As far as I can see, you are saving you assembly or part and indirectly your drawing. Why not this way?
swDraw.Save3(swSaveAsOptions_e.swSaveAsOptions_Silent , errors, warnings)
Sorry for the screendump but I have several sub procedures and maybe I mest up with the different type of variables I pass to these procedures.I tried both variants Scotts and yours with No succes.Yes I try to import a STEP assembly add some custom preperties
and then make drawings from parts and assemblies.Untill now all was going well and now I got stuck with (probably) the simpliest thing I have to do.Can you please pass me a simple code how to make From active assembly a drawing for a part and save it and close it (that last I can even manage!).I creat a NewDocument put in BOM and Annottations and then I can not save the THING.
Apreciate any help and thanks to both of you.
as Scott Stuart wrote you need to save your drawing first time with saveAs, to give it filename, maybe is that an issue why your drawing is not saving
<p>Option Explicit</p><p>Dim swApp As SldWorks.SldWorks</p><p>Dim swModel As SldWorks.ModelDoc2</p><p>Dim swDrawingModel As SldWorks.ModelDoc2</p><p>Dim swModelDocExt As SldWorks.ModelDocExtension</p><p>Dim swDrawing As SldWorks.DrawingDoc</p><p>Dim swSelmgr As SldWorks.SelectionMgr</p><p>Dim swView As SldWorks.View</p><p>Dim retval As String</p><p>Dim status As Boolean</p><p>Dim errors As Long</p><p>Dim warnings As Long</p><p></p><p>Sub main()</p><p> Set swApp = Application.SldWorks</p><p> Set swModel = swApp.ActiveDoc</p><p> If swModel.GetPathName = "" Then</p><p> MsgBox "Save document"</p><p> Exit Sub</p><p> End If</p><p> retval = swApp.GetUserPreferenceStringValue(swDefaultTemplateDrawing)</p><p> Set swDrawingModel = swApp.NewDocument(retval, 0, 0, 0)</p><p> Set swDrawing = swDrawingModel</p><p> Set swModelDocExt = swDrawingModel.Extension</p><p> Set swSelmgr = swDrawingModel.SelectionManager</p><p> </p><p> Set swView = swDrawing.CreateDrawViewFromModelView3(swModel.GetPathName, "*Front", 0.1314541543147, 0.1407887187817, 0)</p><p> </p><p> status = swModelDocExt.SelectByID2("Drawing View1", "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0)</p><p> status = swDrawing.ActivateView("Drawing View1")</p><p> swModel.ClearSelection2 True</p><p> <span style="color: rgba(0, 0, 0, 0); font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px;">swModelDocExt.</span>SaveAs "d:\newDrawing.slddrw", 0, swSaveAsOptions_e.swSaveAsOptions_Silent, Nothing, errors, warnings</p><p> </p><p></p><p>End Sub</p><p></p><p></p><p></p><p></p><p></p>Thanks for this Ivana.But stil having problems.When I try to put avariable instead fix path it gives me an error?
swApp.CloseDoc FileName
Set swApp = Application.SldWorks
End Sub
Because document has not been saved, you can not use
OK I understand.So for the first time I have to generate a name? No way to pass path and name like Make Drawing from Part/Assembly in SW.
filename is string variabele, therefore don't use set.
dim filename as string
filename = lcase( swModel.GetPathName)
filename = replace( filename, ".sldasm", ".slddrw")
filename = replace (filename, ".sldprt",".slddrw")
You can get the full path from the model whose drawing is being made and then can use that to save you drawing (if you want same name/path). But you you've to remove the SLDPRT/SLDASM extension and replace with SLDDRW.
You can also use this free awesome tool to make drawings for you #TASK
spot on.
, sorry did not looked at your codes fully. Please do as has suggested.
Thanks Ivana,great help.
Thanks to Deepak.You guys are great to take time for us who learn from the masters.