Export Macro Not Outputting Apperances

Programming and macros
User avatar
tk421
Posts: 8
Joined: Thu Aug 24, 2023 5:33 pm
Answers: 1
Location: Milwaukee, WI
x 4
x 1

Export Macro Not Outputting Apperances

Unread post by tk421 »

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
by AlexB » Fri Aug 25, 2023 11:51 am
I believe you'll need to specify that this should be AP214 vs AP203 for your STEP file. If I recall correctly, only 214 maintains color selections.

https://help.solidworks.com/2021/englis ... ptions.htm
image.png
Go to full post
David
<><
-----------------------------------
the numbers never lie

www.accuratepattern.com
User avatar
AlexB
Posts: 489
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 27
x 262
x 439

Re: Export Macro Not Outputting Apperances

Unread post by AlexB »

I believe you'll need to specify that this should be AP214 vs AP203 for your STEP file. If I recall correctly, only 214 maintains color selections.

https://help.solidworks.com/2021/englis ... ptions.htm
image.png
User avatar
tk421
Posts: 8
Joined: Thu Aug 24, 2023 5:33 pm
Answers: 1
Location: Milwaukee, WI
x 4
x 1

Re: Export Macro Not Outputting Apperances

Unread post by tk421 »

wow there's a lot of stuff to sift through in this api. i wouldve never found that. thanks a bundle bro!
David
<><
-----------------------------------
the numbers never lie

www.accuratepattern.com
User avatar
CarrieIves
Posts: 162
Joined: Fri Mar 19, 2021 11:19 am
Answers: 2
Location: Richardson, TX
x 375
x 135

Re: Export Macro Not Outputting Apperances

Unread post by CarrieIves »

I'm not figuring out how to specify the STEP format in my save as macro.

We go thru a bunch of stuff in my macro to set the name with the revision and the correct file path. Here's where we set up fullfilename and then our save command.

fullfilename = FileLocation & sFileName & "_Rev" & sRev & "_" & sStatus & draftletter & ".STEP"

swModel.SaveAs (fullfilename)

FileLocation is the network drive path based on the directory the model is in. sRev and sStatus and draftletter are reading custom properties. sFilename is the model filename stripped of the extension and path.

I think I'm supposed to use a different SaveAs API as I read the help, but I'm not clear on using it, nor am I clear on what to do to get the STEP AP214 into my macro.

Can I get some guidance here?
User avatar
josh
Posts: 290
Joined: Thu Mar 11, 2021 1:05 pm
Answers: 15
x 21
x 497

Re: Export Macro Not Outputting Apperances

Unread post by josh »

Do you mean 203 vs 214, or are you saying that you're unsuccessful actually saving out a file at all?

If the first one, you have to use SetUserPreference[something] per the posts above prior to the SaveAs command.

If the second one (you can't save a file at all), please add a debug.print statement to tell you the value of fullfilename ahead of the saveas statement so that you can verify that the string you're building is good. For example, I note that you have "FileLocation & sFileName".... There is no backslash explicitly added here. If FileLocation does not end with a backslash, your save will fail (or at least save somewhere you don't expect).
User avatar
CarrieIves
Posts: 162
Joined: Fri Mar 19, 2021 11:19 am
Answers: 2
Location: Richardson, TX
x 375
x 135

Re: Export Macro Not Outputting Apperances

Unread post by CarrieIves »

We are successfully saving right now and it is STEP 203.

I added these two lines:

Dim stepversion As Long
stepversion = swApp.SetUserPreferenceIntegerValue(swUserPreferenceIntegerValue_e.swStepAP, 214)

Now it is saving in STEP 214.

Thanks.
Post Reply