Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IDS on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help me understand VB

Status
Not open for further replies.

Immow

Industrial
May 13, 2011
6
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?

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

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

Kind regards,

Koen
 
Replies continue below

Recommended for you

Status
Not open for further replies.

Part and Inventory Search

Sponsor