Showing posts with label Macro in SolidWorks. Show all posts
Showing posts with label Macro in SolidWorks. Show all posts

Friday, 27 October 2017

Add Macro Button (customize command) in SolidWorks .

You can add customised macro button to solidworks toolbar (and also generate new button in new toolbar) and that can linked by specific macro.


Steps- Follow steps to build button (customised command).


  1. Expand the option button and select customize.. Or Right click on free space near toolbar and select customize...



2. Go on Commands tab.
3. Select Macro in left hand panel.
4.  Select New Macro Button Command.




5. Drag command (new macro Button) where you want to place this new button (command).







6. After placed, Customize Macro Button tab will open, where it will require some information, Ex-

  • Macro- Browse your macro file, which you saved in your system (computer/laptop).
  • Method- Program will start from. (by default)
  • Appearance - Image Icon, where you can select image for your button (command).
  • Tooltips- Name for button, which will display.
 
7. Press Ok. and also in Customize tab press Ok.


Wednesday, 25 October 2017

Macro program to change font of dimension , note, section view text, and diameter / radius value in SolidWorks Macro.

This program/code will help to manage the all font in same size with one click in solidWorks drawing. you can make a command tool in drawing by this macro.
This program will cover-

  1.  Dimension font size
  2. Section view font size
  3. Diameter text location - horizontal
  4. Note font size
  5. Size of detail font size
  6. Save file after done all changes
In this program, font size is 8. you can change it as per requirement. 



Dim swApp As Object

Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long

Sub main()

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

'dimension font size

Dim myTextFormat As Object
Set myTextFormat = Part.Extension.GetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingDimensionTextFormat, swUserPreferenceOption_e.swDetailingDimension)


myTextFormat.CharHeightInPts = 8
boolstatus = Part.Extension.SetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingDimensionTextFormat, swUserPreferenceOption_e.swDetailingDimension, myTextFormat)



'section font size

Dim myTextFormat1 As Object
Set myTextFormat1 = Part.Extension.GetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingSectionTextFormat, 0)
myTextFormat1.CharHeightInPts = 8
boolstatus = Part.Extension.SetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingSectionTextFormat, 0, myTextFormat1)
Set myTextFormat1 = Part.Extension.GetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingSectionLabelNameTextFormat, 0)
myTextFormat1.CharHeightInPts = 8
boolstatus = Part.Extension.SetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingSectionLabelNameTextFormat, 0, myTextFormat)
Set myTextFormat1 = Part.Extension.GetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingSectionLabelLabelTextFormat, 0)
myTextFormat1.CharHeightInPts = 8
boolstatus = Part.Extension.SetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingSectionLabelLabelTextFormat, 0, myTextFormat)
Set myTextFormat1 = Part.Extension.GetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingSectionLabelScaleTextFormat, 0)
myTextFormat1.CharHeightInPts = 8
boolstatus = Part.Extension.SetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingSectionLabelScaleTextFormat, 0, myTextFormat)
Set myTextFormat1 = Part.Extension.GetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingSectionLabelDelimiterTextFormat, 0)
myTextFormat1.CharHeightInPts = 8
boolstatus = Part.Extension.SetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingSectionLabelDelimiterTextFormat, 0, myTextFormat)
Set myTextFormat1 = Part.Extension.GetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingSectionView_RotationTextFormat, 0)
myTextFormat1.CharHeightInPts = 8
boolstatus = Part.Extension.SetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingSectionView_RotationTextFormat, 0, myTextFormat)



'diameter text location
boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swDetailingDimensionTextAndLeaderStyle, swUserPreferenceOption_e.swDetailingDiameterDimension, swDisplayDimensionLeaderText_e.swBrokenLeaderHorizontalText)

boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swDetailingDimensionTextAndLeaderStyle, swUserPreferenceOption_e.swDetailingRadiusDimension, swDisplayDimensionLeaderText_e.swBrokenLeaderHorizontalText)

'note font size



Dim myTextFormat2 As Object
Set myTextFormat2 = Part.Extension.GetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingNoteTextFormat, 0)
myTextFormat2.CharHeightInPts = 8
boolstatus = Part.Extension.SetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingNoteTextFormat, 0, myTextFormat2)

'SIZE OF DETAILS
Dim myTextFormat3 As Object
Set myTextFormat3 = Part.Extension.GetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingDetailTextFormat, 0)
myTextFormat3.CharHeightInPts = 8
boolstatus = Part.Extension.SetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingDetailTextFormat, 0, myTextFormat)

Dim myTextFormat4 As Object
Set myTextFormat4 = Part.Extension.GetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingDetailView_NameTextFormat, 0)
myTextFormat4.CharHeightInPts = 8
boolstatus = Part.Extension.SetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingDetailView_NameTextFormat, 0, myTextFormat)
Set myTextFormat4 = Part.Extension.GetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingDetailView_LabelTextFormat, 0)
myTextFormat4.CharHeightInPts = 8
boolstatus = Part.Extension.SetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingDetailView_LabelTextFormat, 0, myTextFormat)
Set myTextFormat4 = Part.Extension.GetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingDetailView_ScaleTextFormat, 0)
myTextFormat4.CharHeightInPts = 8
boolstatus = Part.Extension.SetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingDetailView_ScaleTextFormat, 0, myTextFormat)
Set myTextFormat4 = Part.Extension.GetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingDetailView_DelimiterTextFormat, 0)
myTextFormat4.CharHeightInPts = 8
boolstatus = Part.Extension.SetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingDetailView_DelimiterTextFormat, 0, myTextFormat)


'save file

Dim swErrors As Long
Dim swWarnings As Long
boolstatus = Part.Save3(1, swErrors, swWarnings)

End Sub




Download Macro- Click Here

Tuesday, 12 September 2017

SolidWorks run by VBScript

If you want to start/run SolidWorks by VBScript then it's easy by this program.

Just copy this program and save in ".vbs" format.

Program

set swapp=createobject("SldWorks.Application")
swapp.visible=true

Download VBScript Code- Click Here

Sunday, 23 April 2017

SaveAs SolidWorks Active File at new Location with new name

Program

* For this Program, you must open any file before use this macro.


Sub main()

Dim swApp As Object
Set swApp = Application.SldWorks

Dim longstatus As Long

Dim part As Object
Set part = swApp.ActiveDoc

longstatus = part.SaveAs3("F:\DESIGN LIBRARY\New Part 8.SLDPRT", 0, 2)
swApp.CloseDoc "New Part 8"


End Sub

Open SolidWorks Part file by Macro

Program

*This Macro (API) is used for open any file from a specific Location and name




Sub main()

Dim swApp As Object
Set swApp = Application.SldWorks

Dim longstatus As Long, longwarnings As Long
Dim part As Object

Set part = swApp.OpenDoc6("F:\DESIGN LIBRARY\Part8.SLDPRT", 1, 0, "", longstatus, longwarnings)
swApp.ActivateDoc2 "Part8", False, longstatus

End Sub

Thursday, 20 April 2017

Update (rebuild ) Assembly after change in Solidworks by Macro

Macro Program

After Changes in Assembly ,you want to update.

Sub main ( )

Dim swapp As SldWorks.SldWorks
Set swapp = Application.SldWorks

Dim swmodel As ModelDoc2
Set swmodel = swapp.ActiveDoc

swmodel.EditRebuild3

End Sub

File Resolve From Lightweight in SolidWorks

Macro Program

For resolve from Lightweight in SolidWorks.
*You can improve performance of large assemblies significantly by using lightweight components. Loading an assembly with lightweight components is faster than loading the same assembly with fully resolved components


Sub main ( )

Dim swapp As SldWorks.SldWorks
Set swapp = Application.SldWorks

Dim swmodel As ModelDoc2
Set swmodel = swapp.ActiveDoc

resolve = swmodel.ResolveAllLightweight

End Sub

Saturday, 25 March 2017

To Know file location in SolidWorks by Macro (API )

Macro Program

For print / msg of file location where it is saved.
*For find the location you must saved your file.

Sub main ( )

Dim swapp As SldWorks.SldWorks
Set swapp = Application.SldWorks

Dim swmodel As ModelDoc2
Set swmodel = swapp.ActiveDoc

filelocation = swmodel.GetPathName

Msgbox filelocation

End Sub

To Know Title/File name saved in SolidWorks by Macro (API)

Macro Program

For print / msg of part name by which we saved the part file.


Sub main ( )

Dim swapp As SldWorks.SldWorks
Set swapp = Application.SldWorks

Dim swmodel As ModelDoc2
Set swmodel = swapp.ActiveDoc

filename = swmodel.GetTitle

Msgbox filename

End Sub

Friday, 24 March 2017

Macro in SolidWorks

Introduction of Macro Toolbar

Macro- It means, Single Instruction (Set of Instruction) that can work automatically to perform many number of operation.
Play Macro- This option allows you to play/run an already recorded macro.
                                  (Format- *.swp* ,* .sub* ).

Stop Macro- Stops  the recording of a Macro.

Record/pause Macro- This option allows you to start recording on first click and pause on second click.

New macro- This Option allows you to create new macro. and start in visual basic editor to save and edit.

Edit Macro- Allows you to open already recorded macro for editing.