AnsweredAssumed Answered

Macro Help

Question asked by Eric Wicklund on Aug 20, 2017
Latest reply on Aug 21, 2017 by Deepak Gupta

I was wondering if someone would have a good article or could point me in the right direction to learn how to write effective macro's.

 

I recently purchased a G13 gaming keypad and would love to have all of my "common tasks" assigned to a macro that would be activated by the hotkey on the keypad. That potion of it i am not concerned with, its the actual writing of the macros.

 

I would like to have macros

  1. Many times i have a part title that is to long and overflows the title block so i have to go in and edit the sheet format and make the font smaller; 14pt to 10pt.
  2. Insert a pre-made note style from the design library
  3. I have a macro that will add properties IF they do not exist already, it works just fine but i am curious how i can add the weight and material already assigned/calculated. (see picture)

here is what i have for a macro for line item 3;

 

Option Explicit

Public Enum swDocumentTypes_e

    swDocNONE = 0

    swDocPART = 1

    swDocASSEMBLY = 2

End Enum

 

 

Sub main()

    Dim swApp As Object

    Dim Part As Object

    Dim tDate As Date

  

    Set swApp = CreateObject("SldWorks.Application")

    Set Part = swApp.ActiveDoc  ' Get currently active document

  

    Select Case Part.GetType

  

        Case swDocPART ' If active file is a part then insert PART custom properties

             Part.AddCustomInfo "PartNo", "Text", "****" ' Part Number

             Part.AddCustomInfo "Title", "Text", "****" ' Title

             Part.AddCustomInfo "Description", "Text", "****" ' Description

             Part.AddCustomInfo "Revision", "Text", "1" ' Revision

             Part.AddCustomInfo "DrawnBy", "Text", "EAW" ' Drawn By

           ' Part.AddCustomInfo "DrawnDate", "Text", tDate ' Drawn Date

             Part.AddCustomInfo "EngineeringApproval", "Text", "MAW" ' Engineering Approval

             Part.AddCustomInfo "Finish", "Text", "BLACK ANODIZE" ' Finish

             Part.AddCustomInfo "Material", "Text", "---" ' Material

             Part.AddCustomInfo "Weight", "Text", "---" ' Weight

             Part.AddCustomInfo "Vendor", "Text", "**" ' Vendor

             Part.AddCustomInfo "VendorNo", "Text", "N/A" ' Vendor P/N

             Part.AddCustomInfo "Manufacturer", "Text", "N/A" ' Manufacturer

             Part.AddCustomInfo "Manufacturer PN", "Text", "N/A" ' Manufacturer P/N

             Part.DeleteCustomInfo "Desc1"   'Removes existing property from downloaded McMaster Carr part

             Part.DeleteCustomInfo "Desc2"   'Removes existing property from downloaded McMaster Carr part

             Part.DeleteCustomInfo "Desc3"   'Removes existing property from downloaded McMaster Carr part

  

        Case swDocASSEMBLY ' If active file is an assembly then insert ASSEMBLY custom properties

             Part.AddCustomInfo "PartNo", "Text", "SEE BOM" ' Part Number

             Part.AddCustomInfo "Title", "Text", "****" ' Title

             Part.AddCustomInfo "Description", "Text", "****" ' Description

             Part.AddCustomInfo "Revision", "Text", "1" ' Revision

             Part.AddCustomInfo "DrawnBy", "Text", "EAW" ' Drawn By

           ' Part.AddCustomInfo "DrawnDate", "Text", tDate ' Drawn Date

             Part.AddCustomInfo "EngineeringApproval", "Text", "MAW" ' Engineering Approval

             Part.AddCustomInfo "Finish", "Text", "SEE BOM" ' Finish

             Part.AddCustomInfo "Material", "Text", "SEE BOM" ' Material

             Part.AddCustomInfo "Weight", "Text", "---" ' Weight

Outcomes