Jump to content

Welcome to ExtremeHW

Welcome to ExtremeHW, register to take part in our community, don't worry this is a simple FREE process that requires minimal information for you to signup.

 

Registered users can: 

  • Start new topics and reply to others.
  • Show off your PC using our Rig Creator feature.
  • Subscribe to topics and forums to get updates.
  • Get your own profile page to customize.
  • Send personal messages to other members.
  • Take advantage of site exclusive features.
  • Upgrade to Premium to unlock additional sites features.
IGNORED

Solidwork Macro Troubles


ENTERPRISE

Recommended Posts

Hey all, 

 

So I am having a little bit of a fight with Solidwork Macros. Not sure if anyone here will be able to help, but lets have at it. 

 

So essentially I have two working individual Macro files. The Goal of the Macro files is to Save a document and then run an auto expert of the current open file into PDF and DWG. So I have two Macro files aptly named:

 

1.Save As 

2.PDF & DWG Export 

 

Initially I tried having it as one combined Macro, but could not get it to play nicely. The I realised there is a Group function for VBA Macros. Which is a Macro that you can used to launch other Macros in sequence. Alas this did not work. I have the two Macro files attached as mentioned above as well as the ."Group Run "Macro. Can anyone smarter than myself at these get these running in sequence ? 

 

As a note, I usually find that the when running the Group Run Macro, the Save As Macro will fire up and do its job, but after that sequence is finished, the PDF &DWG Export Macro does not start. 

 

Furthermore, the "Group Run" Macro assumes you place the "Macros" folder in the attachment in the root of your C:/ drive to function.

 

Thanks,

E

Macros.zip

£3000

Owned

 Share

CPU: AMD Ryzen 9 7950X3D
MOTHERBOARD: MSI Meg Ace X670E
RAM: Corsair Dominator Titanium 64GB (6000MT/s)
GPU: EVGA 3090 FTW Ultra Gaming
SSD/NVME: Corsair MP700 Pro Gen 5 2TB
PSU: EVGA Supernova T2 1600Watt
CASE: be quiet Dark Base Pro 900 Rev 2
FANS: Noctua NF-A14 industrialPPC x 6
Full Rig Info

Owned

 Share

CPU: Intel Core i5 8500
RAM: 16GB (2x8GB) Kingston 2666Mhz
SSD/NVME: 256GB Samsung NVMe
NETWORK: HP 561T 10Gbe (Intel X540 T2)
MOTHERBOARD: Proprietry
GPU: Intel UHD Graphics 630
PSU: 90Watt
CASE: HP EliteDesk 800 G4 SFF
Full Rig Info

£3000

Owned

 Share

CPU: 2 x Xeon|E5-2696-V4 (44C/88T)
RAM: 128GB|16 x 8GB - DDR4 2400MHz (2Rx8)
MOTHERBOARD: HP Z840|Intel C612 Chipset
GPU: Nvidia Quadro P2200
HDD: 4x 16TB Toshiba MG08ACA16TE Enterprise
SSD/NVME: Intel 512GB 670p NVMe (Main OS)
SSD/NVME 2: Samsung 1TB 980 NVMe (VM's)
SSD/NVME 3: 2x Seagate FireCuda 1TB SSD's (Apps)
Full Rig Info
Link to comment
Share on other sites

Release.

£3000

Owned

 Share

CPU: AMD Ryzen 9 7950X3D
MOTHERBOARD: MSI Meg Ace X670E
RAM: Corsair Dominator Titanium 64GB (6000MT/s)
GPU: EVGA 3090 FTW Ultra Gaming
SSD/NVME: Corsair MP700 Pro Gen 5 2TB
PSU: EVGA Supernova T2 1600Watt
CASE: be quiet Dark Base Pro 900 Rev 2
FANS: Noctua NF-A14 industrialPPC x 6
Full Rig Info

Owned

 Share

CPU: Intel Core i5 8500
RAM: 16GB (2x8GB) Kingston 2666Mhz
SSD/NVME: 256GB Samsung NVMe
NETWORK: HP 561T 10Gbe (Intel X540 T2)
MOTHERBOARD: Proprietry
GPU: Intel UHD Graphics 630
PSU: 90Watt
CASE: HP EliteDesk 800 G4 SFF
Full Rig Info

£3000

Owned

 Share

CPU: 2 x Xeon|E5-2696-V4 (44C/88T)
RAM: 128GB|16 x 8GB - DDR4 2400MHz (2Rx8)
MOTHERBOARD: HP Z840|Intel C612 Chipset
GPU: Nvidia Quadro P2200
HDD: 4x 16TB Toshiba MG08ACA16TE Enterprise
SSD/NVME: Intel 512GB 670p NVMe (Main OS)
SSD/NVME 2: Samsung 1TB 980 NVMe (VM's)
SSD/NVME 3: 2x Seagate FireCuda 1TB SSD's (Apps)
Full Rig Info
Link to comment
Share on other sites

Edit. 

 

Just like that after sleeping on it I have sorted it into one functional Macro. So if anyone is looking for a Macro that will save a 2D drawing and export said drawing into PDF,DWG or DXF then please see attached for your use 🙂

 

 

 

SAVE DRAWING WITH PDF & DWG EXPORT.zip

£3000

Owned

 Share

CPU: AMD Ryzen 9 7950X3D
MOTHERBOARD: MSI Meg Ace X670E
RAM: Corsair Dominator Titanium 64GB (6000MT/s)
GPU: EVGA 3090 FTW Ultra Gaming
SSD/NVME: Corsair MP700 Pro Gen 5 2TB
PSU: EVGA Supernova T2 1600Watt
CASE: be quiet Dark Base Pro 900 Rev 2
FANS: Noctua NF-A14 industrialPPC x 6
Full Rig Info

Owned

 Share

CPU: Intel Core i5 8500
RAM: 16GB (2x8GB) Kingston 2666Mhz
SSD/NVME: 256GB Samsung NVMe
NETWORK: HP 561T 10Gbe (Intel X540 T2)
MOTHERBOARD: Proprietry
GPU: Intel UHD Graphics 630
PSU: 90Watt
CASE: HP EliteDesk 800 G4 SFF
Full Rig Info

£3000

Owned

 Share

CPU: 2 x Xeon|E5-2696-V4 (44C/88T)
RAM: 128GB|16 x 8GB - DDR4 2400MHz (2Rx8)
MOTHERBOARD: HP Z840|Intel C612 Chipset
GPU: Nvidia Quadro P2200
HDD: 4x 16TB Toshiba MG08ACA16TE Enterprise
SSD/NVME: Intel 512GB 670p NVMe (Main OS)
SSD/NVME 2: Samsung 1TB 980 NVMe (VM's)
SSD/NVME 3: 2x Seagate FireCuda 1TB SSD's (Apps)
Full Rig Info
Link to comment
Share on other sites

I am back. 

 

So while I solved my initial problem as above. I wanted to try and make this Macro as automated as possible so that I can have the Macro initialize when a user uses the default save button within Solid works.  I found a great resource for doing this as per

WWW.CODESTACK.NET

Macro runs VBA code (or another macro) automatically on file save using SOLIDWORKS API

 

However it is clear my novice knowledge of VBA is holding me back as whenever I try to implement my current Macro code using this resource, nothing happens when I run the Macro, not even any particular errors.  Though it is clear I have done something wrong.  

 

My current Macro code is

 

............................................................................................................................

'Export Open Drawings as PDF_DWG (SW2019).swp ------------- 01/30/19

'Description: Macro to export all open drawings as PDF and DWG.

'Pre-Condition: An open drawing which has been saved and has one model view. The model should have the
' PartNumber, Revision and Description custom properties with values added.

'Post-Condition: Macro save active drawing as PDF and DXF in same location as the drawing file with
' PartNumber, Revision and Description custom properties values from referenced model as the file name.

' The macro would process all open drawings and would export only those drawings which has been saved and contains minimum one model view.

' Please back up your data before use and USE AT OWN RISK
'
'------------------------------------------------------------------------------------
' Created by Deepak Gupta (Boxer's SOLIDWORKS Blog, India) http://gupta9665.com/
'------------------------------------------------------------------------------------
' Disclaimer:
' This macro is provided as is. No claims, support, refund, safety net, or
' warranties are expressed or implied. By using this macro and/or its code in
' any way whatsoever, the user and any entities which the user represents,
' agree to hold the authors free of any and all liability.
' Free distribution and use of this code in other free works is welcome.
' You may redistribute it and/or modify it on the condition that this header is retained.
' All other forms of distribution (i.e., not free, fee for delivery, etc) are prohibited
' without the expressed written consent by the authors.
' Use at your own risk!
' ------------------------------------------------------------------------------

Option Explicit

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDrawModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim swView As SldWorks.View
Dim nErrors As Long
Dim nWarnings As Long
Dim Revision As String
Dim Description As String
Dim PartNumber As String
Dim nFileName As String
Dim sFileName As String
Dim nResponse As Integer
Dim FileSave As Boolean
Dim sDrawingCol As New Collection

Sub Main()

Set swApp = Application.SldWorks
Set swDrawModel = swApp.GetFirstDocument
Set swModel = swApp.ActiveDoc

swModel.Extension.RunCommand swCommands_SaveAs, Empty
 
' Check to see if a drawing is loaded.
If swDrawModel Is Nothing Then
MsgBox "There is no active drawing document"
Exit Sub
End If

Do While Not swDrawModel Is Nothing
If swDrawModel.GetType = swDocDRAWING Then
sDrawingCol.Add swDrawModel.GetPathName
Debug.Print swDrawModel.GetPathName
End If
Set swDrawModel = swDrawModel.GetNext
Loop

If sDrawingCol.Count > 0 Then

'Set file export type
nResponse = MsgBox("Select YES (PDF & DWG) OR NO (DXF) OR CANCEL (Exit/End)?", vbYesNoCancel)
If nResponse = vbYes Then
FileSave = True
ElseIf nResponse = vbNo Then
FileSave = False
ElseIf nResponse = vbCancel Then
Exit Sub
End If
Else

MsgBox "There is no active drawing document"
Exit Sub
 
End If

Set swDrawModel = swApp.GetFirstDocument
Do While Not swDrawModel Is Nothing
If swDrawModel.GetType = swDocDRAWING Then
Set swDraw = swDrawModel
 
If swDraw.GetPathName <> "" Then
sFileName = Mid(swDraw.GetPathName, InStrRev(swDraw.GetPathName, "\") + 1)
swApp.ActivateDoc3 sFileName, False, swDontRebuildActiveDoc, nErrors
Else
 
MsgBox "This drawing: " & UCase(swDraw.GetTitle) & " has not been saved, " & vbCrLf & _
"jumping to next drawing (if available) else ending the macro"
GoTo Jump
End If
 
Set swView = swDraw.GetFirstView
Set swView = swView.GetNextView

If Not swView Is Nothing Then
Set swModel = swView.ReferencedDocument
Else
MsgBox "No model view found in this drawing: " & UCase(swDraw.GetTitle) & ", " & vbCrLf & _
"jumping to next drawing (if available) else ending the macro"
GoTo Jump
End If


'Get Model Properties
PartNumber = swModel.GetCustomInfoValue("", "Part Number")
Revision = swModel.GetCustomInfoValue("", "Revision")
Description = swModel.GetCustomInfoValue("", "Description")
 
If Revision = "" Then
Revision = ""
End If

'nFileName = Left(swDraw.GetPathName, InStrRev(swDraw.GetPathName, "\")) & PartNumber & "-" & Revision & " " & Description
 
' Comment out above line and remove comment from following line in case you want to simply save the draing file with its own name.
nFileName = Left(swDraw.GetPathName, InStrRev(swDraw.GetPathName, "\")) & sFileName
 
If FileSave = True Then
'Save as DWG (replace DWG with DXF in following line in case you want to save as DXF)
'Note that DWG will export to one or multiple sheets depending on your solidworks DWG export settings
swDraw.SaveAs3 nFileName & ".DWG", 0, 0
'Save as PDF`
swDraw.SaveAs3 nFileName & ".PDF", 0, 0
ElseIf FileSave = False Then
'Save as DWG (replace DWG with DXF in following line in case you want to save as DXF)
swDraw.SaveAs3 nFileName & ".DXF", 0, 0
End If
End If


Jump:
Set swDrawModel = swDrawModel.GetNext
Loop
 
Set sDrawingCol = Nothing

End Sub

Anyone have any ideas ?

£3000

Owned

 Share

CPU: AMD Ryzen 9 7950X3D
MOTHERBOARD: MSI Meg Ace X670E
RAM: Corsair Dominator Titanium 64GB (6000MT/s)
GPU: EVGA 3090 FTW Ultra Gaming
SSD/NVME: Corsair MP700 Pro Gen 5 2TB
PSU: EVGA Supernova T2 1600Watt
CASE: be quiet Dark Base Pro 900 Rev 2
FANS: Noctua NF-A14 industrialPPC x 6
Full Rig Info

Owned

 Share

CPU: Intel Core i5 8500
RAM: 16GB (2x8GB) Kingston 2666Mhz
SSD/NVME: 256GB Samsung NVMe
NETWORK: HP 561T 10Gbe (Intel X540 T2)
MOTHERBOARD: Proprietry
GPU: Intel UHD Graphics 630
PSU: 90Watt
CASE: HP EliteDesk 800 G4 SFF
Full Rig Info

£3000

Owned

 Share

CPU: 2 x Xeon|E5-2696-V4 (44C/88T)
RAM: 128GB|16 x 8GB - DDR4 2400MHz (2Rx8)
MOTHERBOARD: HP Z840|Intel C612 Chipset
GPU: Nvidia Quadro P2200
HDD: 4x 16TB Toshiba MG08ACA16TE Enterprise
SSD/NVME: Intel 512GB 670p NVMe (Main OS)
SSD/NVME 2: Samsung 1TB 980 NVMe (VM's)
SSD/NVME 3: 2x Seagate FireCuda 1TB SSD's (Apps)
Full Rig Info
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×
×
  • Create New...

Important Information

This Website may place and access certain Cookies on your computer. ExtremeHW uses Cookies to improve your experience of using the Website and to improve our range of products and services. ExtremeHW has carefully chosen these Cookies and has taken steps to ensure that your privacy is protected and respected at all times. All Cookies used by this Website are used in accordance with current UK and EU Cookie Law. For more information please see our Privacy Policy