Macro dxf conversion with part property name

Hello

I would like to modify the macro below to use a property of the part as the DXF filename. (instead of adding the hint)

 

Can you help me, I don't know how to program macros and I have 500 files to process

 

 

Sub main()

Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc

If Part.GetType = swDocDRAWING Then 'verif type document

    Set swModExt = Part.Extension
    Set Prop = swModExt.CustomPropertyManager("")
    Part.ForceRebuild3 True

    Set swView = Part.GetFirstView
    'the first view being the sheet, move on to the next
    Set swView = swView.GetNextView
    Coin recovery
    Set swModel = swView.ReferencedDocument
    Set swModExt = swModel.Extension
    
    
    Assignment from "Index" to "Att"
    Dim RevTable as Object
    Set Prop = swModExt.CustomPropertyManager("")
    Set RevTable = Part.GetCurrentSheet.RevisionTable
    Set custpropmgr = Part.Extension.CustomPropertyManager("")
    Att = ""    'initializes the Ind variable
    Att = RevTable.Text(0, 0)
    'Att = Part.GetCustomInfoValue("", "Revision") 'retrieves the plan's index
    'boolstatus = Prop.Get3("Index", false, ValOut, Att)
    If Att = " " Then Att = ""
    If Att = "Hint" Then Att = ""
    
    Full Path Recovery
    swPathName = Part.GetPathName
    If swPathName = "" Then
        swApp.SendMsgToUser ("The drawing file is not saved, please do it and start over")
        Exit Sub
    End If
    
    pathname = Mid(swPathName, 1, Len(swPathName) - 7)
    
    DXF Registration
    swPathName = pathname & Att + ".dxf" ' adds _ind and.dxf"
    Set swModExt = Part.Extension
    Part.ViewZoomtofit2
    boolstatus = swModExt.SaveAs(swPathName, 0, 0, swExportPDFData, Errors, Warnings) 'save to dxf
    
    PDF Registration
    
    swPathName = pathname & Att + ".pdf" ' adds _ind and .pdf"
    Set swModExt = Part.Extension
    Part.ViewZoomtofit2
    boolstatus = swModExt.SaveAs(swPathName, 0, 0, swExportPDFData, Errors, Warnings)
    
    
    
    Else: swApp.SendMsgToUser ("This macro only works with a drawing")
    
End If

    
End Sub

 

Hello

The easiest way is to use the BatchConverter tool from myCADtools

You have naming rules that correspond to your needs.

 

Philippe

1 Like

Hello 

And what properties are we talking about???

1 Like

Hello

The dxf and pdf file name must match the BIO property

 

 

Hello

In your macro, you replace the lines:

Assignment from "Index" to "Att"
Dim RevTable As Object
Set Prop = swModExt.CustomPropertyManager("")
Set RevTable = Part.GetCurrentSheet.RevisionTable
Set custpropmgr = Part.Extension.CustomPropertyManager("")
Att = ""    'initializes the Ind variable
Att = RevTable.Text(0, 0)
'Att = Part.GetCustomInfoValue("", "Revision") 'retrieves the plan's index
'boolstatus = Prop.Get3("Index", false, ValOut, Att)
If Att = " " Then Att = ""
If Att = "Hint" Then Att = ""

By:

Set Prop = swModExt.CustomPropertyManager("")
Set custpropmgr = Part.Extension.CustomPropertyManager("")
Att=""
Att = Part.GetCustomInfoValue("", "BIO")

Kind regards

1 Like

Please use the Code tag using the highlighted button:

This makes the posts much more readable...


boutoncode.png
1 Like

Thank you for the info remrem, I didn't know this function ....

1 Like