I recorded a dxf macro but when I run it from any drawing, it always names the dxf file 'PART3.DXF'
I would like for saved dxf files to match whatever drawing file name I'm running it from.
Recording macros only gets you so far. It only captures what you are doing at that moment if it captures anything at all. Some steps don't show up in the recorder.
You can get the name of the active doc with Part.GetTitle, but it doesn't get you the path. I typically use this to close a doc after I'm done using it. It's helpful in loops.
nam = Part.GetTitle
You can get the path with Part.GetFullPath.
This assumes whatever you are working with is a Solidworks file. There are better, more flexible ways to do this, but this will get you where you want to go for now.
sfil = Left(Part.GetFullPath, Len(Part.GetFullPath) - 6) & DXFlongstatus = Part.SaveAs3(sfil, 0, 0)
Danniel Sims wrote: You can get the path with Part.GetFullPath.
Danniel Sims wrote:
It should be Part.GetPathName
OK, I got the Part.GetFullPath string but this still doesn't explain how to apply it to my macro.
Obviously I applied it incorrectly because the file name becomes Part.GetFullPath.dxf.
Instead the file name should be Part4.dxf
' Save Aslongstatus = Part.SaveAs3("P:\_Engineering\_WATERJET_FILES\Part.GetPathName.DXF", 0, 0)End Sub
To re-iterate, I would like the dxf files to be saved in WATERJET location every time, not the location of the drawing. This part is working, but the naming of the actual dxf file is not using the drawing file name.
Please show how Part.GetFullPath fits in with the rest of the code line.
Additionally as a second priority, any way for it to also pull the revision from the drawing and add it to the file name? example: Part4 r3.dxf
Part.GetTitle gets the saved part/assembly/drawings name and extension
This isolates the root name minus the extension
nam = Left(Part.GetTitle, Len(Part.GetTitle) - 6) ' - 6 deletes SW file extension, but leaves "."
longstatus = Part.SaveAs3("P:\_Engineering\_WATERJET_FILES\" & nam & "DXF", 0, 0)
As for your second priority, there a couple ways to do it. It really depends on how your template is setup.
If you know the exact name of the annotation that contains your revision number, you can store it to a variable at the top of the code and then add it to nam.
If the annotation is added indepenedly, and changes all the time, then you would have to traverse all the annotations to locate your R#. This is a bit more complicated, but doable. There's an example on the Solidworks help webpages.
I don't have a specific example of getting a specific note's text at hand, but you'd need to use GetText for annotations/notes.
rev = swNote.GetText ' need to get the specific note first.
nam = Left(Part.GetTitle, Len(Part.GetTitle) - 6) & "_" & rev ' This would make the filename nam_rev.DXF
Hope this helps.
Looks like I found a macro that does exactly what I was trying to record. However, it's file name output needs to change for our needs.
Macro is found on link below and I left a reply there with an example of how we would prefer the file name output.
There is a lot going on in that macro. I don't think you're using the same rev naming system shown. It appends the rev to the name in the macro if it is not rev "A".
If rev <> "A" And rev <> "-" Then sPathName = sPathName & " r" & rev 'append revision if not rev A End If
If that part is actually working for you (which by your image it doesn't appear to be) then all you need to do is remove the extras on the line that looks like this:
bRetDWG = swModelDocExt.SaveAs(sPathName & "_" & i + 1 & "_" & i + 1 & ".DWG", swSaveAsCurrentVersion, swSaveAsOptions_Silent, Nothing, nErrors, nWarnings)
bRetDWG = swModelDocExt.SaveAs(sPathName & ".DXF", swSaveAsCurrentVersion, swSaveAsOptions_Silent, Nothing, nErrors, nWarnings)
I don't know if this is still going to work for you. It's saving each sheet out as a revision on a multi-sheet drawing.
I think you just have to step through it line-by-line and watch your sPathName and r values and make sure they are what you need them to be.
Retrieving data ...