Export Macro Not Outputting Apperances
Posted: Fri Aug 25, 2023 11:09 am
Below is my work in progress of my exporting macro. It works well but does not output the colors that are on the model. it's not a huge deal, but it would be nice to be able to have those come into PowerMill how they left SW. Any help is appreciated. Thanks!
Code: Select all
Option Explicit
' Connect to SolidWorks & access the
' libraries needed
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swComp As SldWorks.Component2
Dim longStatus As Long
Sub main()
' Connect to active document
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
' Check to see if the active document is an assy;
' if it isnt, exit the macro.
If Not TypeOf swModel Is SldWorks.AssemblyDoc Then
swApp.SendMsgToUser2 "This macro can only be run in an assembly document", 4, 2
Exit Sub
End If
' Get the selected part or sub-assy as 'swComp'
Set swComp = swSelMgr.GetSelectedObjectsComponent4(1, -1)
' Grab the wanted information from the selected part
' From the assy name, get the job number only
' & add the " - " to the name
Dim partName As String
Dim partPath As String
Dim myval As String
Dim nameForExport As String
Dim fullExportPath As String
nameForExport = Left(swModel.GetTitle, 5) & " - "
' Get the part name and the part path to build th
' directory name for exporting
partName = Replace(swComp.Name, "-1", "")
partPath = swComp.GetPathName
' Modify the path for the nc toolpaths folder
partPath = Replace(Replace(partPath, "SW Design", "NC Toolpaths"), partName & ".SLDPRT", "")
fullExportPath = partPath & nameForExport & "Stock.step"
' Save out the file as a step
swApp.SetUserPreferenceToggle swUserPreferenceToggle_e.swStepExportAppearances, True
longStatus = swModel.SaveAs3(fullExportPath, 0, 2)
' Flash message to user that this operation is done
swApp.SendMsgToUser "Done"
End Sub