×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Help me understand VB

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?

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

RE: Help me understand VB

The module name should not have any space but you can use an underscore. Renaming should work fine.

Deepak Gupta
CSWE, CSWP
SW 2011 SP5.0 & 2012 SP1.0
Boxer's SolidWorks™ Blog

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources