Help me understand VB
Help me understand VB
(OP)
Hello all
1) I have this macro and it works but when I change the Module name it stops working. It has to be Macro11... and I would like to know why?
2) I would like to combine the script below with the above.
Kind regards,
Koen
1) I have this macro and it works but when I change the Module name it stops working. It has to be Macro11... and I would like to know why?
CODE
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim cpm As CustomPropertyManager
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set cpm = swModel.Extension.CustomPropertyManager("")
Dim path As String, filename As String, partno As String, desc As String, mass As String, material As String
path = swModel.GetPathName
filename = Mid$(path, InStrRev(path, "\") + 1) ' With extension
filename = Left$(filename, InStrRev(filename, ".") - 1) ' Remove extension
partno = Left(filename, 16)
desc = Right(filename, Len(filename) - 17)
mass = """SW-Mass@ & filename & .SLDPRT"""
material = """SW-Material@ & filename & .SLDPRT"""
cpm.Delete "PartNo"
cpm.Delete "Title"
cpm.Delete "Mass"
cpm.Delete "Material"
cpm.Add2 "PartNo", swCustomInfoText, partno
cpm.Add2 "Title", swCustomInfoText, desc
cpm.Add2 "Mass", swCustomInfoText, mass
cpm.Add2 "Material", swCustomInfoText, material
End Sub
Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim cpm As CustomPropertyManager
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set cpm = swModel.Extension.CustomPropertyManager("")
Dim path As String, filename As String, partno As String, desc As String, mass As String, material As String
path = swModel.GetPathName
filename = Mid$(path, InStrRev(path, "\") + 1) ' With extension
filename = Left$(filename, InStrRev(filename, ".") - 1) ' Remove extension
partno = Left(filename, 16)
desc = Right(filename, Len(filename) - 17)
mass = """SW-Mass@ & filename & .SLDPRT"""
material = """SW-Material@ & filename & .SLDPRT"""
cpm.Delete "PartNo"
cpm.Delete "Title"
cpm.Delete "Mass"
cpm.Delete "Material"
cpm.Add2 "PartNo", swCustomInfoText, partno
cpm.Add2 "Title", swCustomInfoText, desc
cpm.Add2 "Mass", swCustomInfoText, mass
cpm.Add2 "Material", swCustomInfoText, material
End Sub
2) I would like to combine the script below with the above.
CODE
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
boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitSystem, 0, swUnitSystem_e.swUnitSystem_Custom)
boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsLinearFractionDenominator, 0, 0)
boolstatus = Part.Extension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swUnitsLinearFeetAndInchesFormat, 0, False)
boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsDualLinearFractionDenominator, 0, 0)
boolstatus = Part.Extension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swUnitsDualLinearFeetAndInchesFormat, 0, False)
boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropMass, 0, swUnitsMassPropMass_e.swUnitsMassPropMass_Kilograms)
End Sub
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
boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitSystem, 0, swUnitSystem_e.swUnitSystem_Custom)
boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsLinearFractionDenominator, 0, 0)
boolstatus = Part.Extension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swUnitsLinearFeetAndInchesFormat, 0, False)
boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsDualLinearFractionDenominator, 0, 0)
boolstatus = Part.Extension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swUnitsDualLinearFeetAndInchesFormat, 0, False)
boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropMass, 0, swUnitsMassPropMass_e.swUnitsMassPropMass_Kilograms)
End Sub
Kind regards,
Koen






RE: Help me understand VB
Deepak Gupta
CSWE, CSWP
SW 2011 SP5.0 & 2012 SP1.0
Boxer's SolidWorks™ Blog