Access "Author" and "Comments" properties in VBA macro
Access "Author" and "Comments" properties in VBA macro
(OP)
How can I get and set the values of "Author" and "Comments" properties from a macro in SolidWorks?
When was the last time you drove down the highway without seeing a commercial truck hauling goods?
Download nowINTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS Come Join Us!Are you an
Engineering professional? Join Eng-Tips Forums!
*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail. Posting GuidelinesJobs |
Access "Author" and "Comments" properties in VBA macro
|
Access "Author" and "Comments" properties in VBA macroAccess "Author" and "Comments" properties in VBA macro(OP)
How can I get and set the values of "Author" and "Comments" properties from a macro in SolidWorks?
Red Flag SubmittedThank you for helping keep Eng-Tips Forums free from inappropriate posts. Reply To This ThreadPosting in the Eng-Tips forums is a member-only feature.Click Here to join Eng-Tips and talk with other members! |
ResourcesThe world has changed considerably since the 1980s, when CAD first started displacing drafting tables. Download Now
Prototyping has always been a critical part of product development. Download Now
As the cloud is increasingly adopted for product development, questions remain as to just how cloud software tools compare to on-premise solutions. Download Now
Engineering-centric businesses face a number of challenges today, but unmanageable design and change processes don’t need to be counted among them. Download Now
|
RE: Access "Author" and "Comments" properties in VBA macro
Deepak Gupta
SW 2010 SP4.0 & 2011 SP1.0
DriveWorks Pro 7 SP5
Boxer's SolidWorks™ Blog
RE: Access "Author" and "Comments" properties in VBA macro
CODE
'
' Will not overwrite existing values for Author and Comemnts
'
' ------------------------------------------------------------------------------
' Written by: Deepak Gupta (http://gupta9665.wordpress.com/)
' ------------------------------------------------------------------------------
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim bRet As Boolean
Dim value As String
Dim svalue As String
Sub main()
Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
Debug.Print "File = " + swModel.GetPathName
'Get and set the Author KeyWord in the File Summary Info
value = swModel.SummaryInfo(swSumInfoAuthor)
If value = "" Then
swModel.SummaryInfo(swSumInfoAuthor) = "Author name here"
'Get and set the Comment KeyWord in the File Summary Info
svalue = swModel.SummaryInfo(swSumInfoComment)
If svalue = "" Then
swModel.SummaryInfo(swSumInfoComment) = "Comments Here"
Else
End If
End If
End Sub
RE: Access "Author" and "Comments" properties in VBA macro
Deepak Gupta
SW 2010 SP4.0 & 2011 SP1.0
DriveWorks Pro 7 SP5
Boxer's SolidWorks™ Blog
RE: Access "Author" and "Comments" properties in VBA macro
I have been trying this for a couple days now, I got your code to work, but I am just getting to learn VBA, so programming is a little difficult right now lol
Thanks again
Eric Roe
Electro-Mechanical Engineer
Airfloat LLC
RE: Access "Author" and "Comments" properties in VBA macro
CODE
'
' Will not overwrite existing values for Author and Comemnts
'
' ------------------------------------------------------------------------------
' Written by: Deepak Gupta (http://gupta9665.wordpress.com/)
' ------------------------------------------------------------------------------
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim bRet As Boolean
Dim value As String
Dim svalue As String
Sub main()
Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
Debug.Print "File = " + swModel.GetPathName
'Get and set the Author KeyWord in the File Summary Info
value = swModel.SummaryInfo(swSumInfoAuthor) ' this lines gets the info
If value = "" Then
swModel.SummaryInfo(swSumInfoAuthor) = "Author name here" ' this line sets the info, so put the author name what you want to display
'Get and set the Comment KeyWord in the File Summary Info
svalue = swModel.SummaryInfo(swSumInfoComment)
If svalue = "" Then
swModel.SummaryInfo(swSumInfoComment) = "Comments Here"
Else
End If
End If
End Sub
' Similarly you can use codes for setting up info for
' Title = swModel.SummaryInfo(swSumInfoTitle)
' Subject = swModel.SummaryInfo(swSumInfoSubject)
' Keywords = swModel.SummaryInfo(swSumInfoKeywords)
' For getting the info for follwoing information
' SavedBy = swModel.SummaryInfo(swSumInfoSavedBy)
' CreateDate = swModel.SummaryInfo(swSumInfoCreateDate)
' SaveDate = swModel.SummaryInfo(swSumInfoSaveDate)
Deepak Gupta
SW 2010 SP4.0 & 2011 SP3.0
Boxer's SolidWorks™ Blog
RE: Access "Author" and "Comments" properties in VBA macro
But this program will only fill in the Summary Tab of the Summary Information dialog box correct?
What if I would like to fill out the Custom Tab of the Summary Information dialog box? (where the part Description, StockNumber, Routing, and Material Description are)
I tried replacing the Author with Description, but that did not work..
Eric Roe
Electro-Mechanical Engineer
Airfloat LLC
RE: Access "Author" and "Comments" properties in VBA macro
Deepak Gupta
SW 2010 SP4.0 & 2011 SP3.0
Boxer's SolidWorks™ Blog
RE: Access "Author" and "Comments" properties in VBA macro
CODE
Dim swApp As Object
Dim MyProp(1, 5) As String ' If you add more properties, just increment the second number in the bracket
Dim m As Integer
Set swApp = CreateObject("SldWorks.Application")
Set Part = swApp.ActiveDoc
'Define custom property names here and add more line for more properties. Just increment the second number in the bracket
MyProp(0, 0) = "File Name"
MyProp(0, 1) = "Material"
MyProp(0, 2) = "Finish"
MyProp(0, 3) = "Weight"
MyProp(0, 4) = "Description"
'Define Property values here add more line for more properties values added above. Just increment the second number in the bracket
MyProp(1, 0) = "$PRP:" & Chr(34) & "SW-File Name" & Chr(34)
MyProp(1, 1) = Chr(34) & "SW-Material" & Chr(34)
MyProp(1, 2) = "-"
MyProp(1, 3) = Chr(34) & "SW-Mass" & Chr(34)
MyProp(1, 4) = "Plate"
For m = 0 To 5 ' If you add more properties, just increment the second number i.e 5 here
retval = Part.AddCustomInfo3("", MyProp(0, m), 30, MyProp(1, m))
Next m
End Sub
Deepak Gupta
SW 2010 SP4.0 & 2011 SP3.0
Boxer's SolidWorks™ Blog
RE: Access "Author" and "Comments" properties in VBA macro
Thanks again
Eric Roe
Electro-Mechanical Engineer
Airfloat LLC
RE: Access "Author" and "Comments" properties in VBA macro
Sub main()
Dim swApp As Object
Dim MyProp(1, 5) As String ' If you add more properties, just increment the second number in the bracket
Dim m As Integer
Set swApp = CreateObject("SldWorks.Application")
Set Part = swApp.ActiveDoc
'Define custom property names here and add more line for more properties. Just increment the second number in the bracket
MyProp(0, 0) = "File Name"
MyProp(0, 1) = "Material"
MyProp(0, 2) = "Finish"
MyProp(0, 3) = "Weight"
MyProp(0, 4) = "Description"
'Define Property values here add more line for more properties values added above. Just increment the second number in the bracket
MyProp(1, 0) = "$PRP:" & Chr(34) & "SW-File Name" & Chr(34)
MyProp(1, 1) = Chr(34) & "SW-Material" & Chr(34)
MyProp(1, 2) = "2543"
MyProp(1, 3) = Chr(34) & "SW-Mass" & Chr(34)
MyProp(1, 4) = "Plate"
For m = 0 To 5 ' If you add more properties, just increment the second number i.e 5 here
Part.CustomInfo(MyProp(0, m)) = MyProp(1, m)
Next m
End Sub
------------
For some reason, when I kept the original line:
retval = Part.AddCustomInfo3("", MyProp(0, m), 30, MyProp(1, m))
If I tried to change the value of a property that has already been set, it would not overwrite it. So I did some research and canged the line to:
Part.CustomInfo(MyProp(0, m)) = MyProp(1, m)
This way the value will be overwritten every time.
Thanks a lot Deepak, by sharing these two programs with me, I have learned so much more about programming in SW compared to the week I spent trying to figure it out using only the API help browser.
Eric Roe
Electro-Mechanical Engineer
Airfloat LLC
RE: Access "Author" and "Comments" properties in VBA macro
Deepak Gupta
SW 2010 SP4.0 & 2011 SP3.0
Boxer's SolidWorks™ Blog
RE: Access "Author" and "Comments" properties in VBA macro
Is there any way I can get a macro to run automatically when the user performs a certain task in SW?
The company I work for uses a laser cutter to cut all of our sheet metal parts, so we have a template already made that sets everything up with our laser program (pronest). The only tedious part about using the laser template is that in order for the laser to determine which type of sheet metal to cut the part, the user has to manually enter the stock number of the material (we have a list of about 15 different types of sheet metal we use as our standard material).
With the help of Deepak, I am able to automatically update the stock number of the part with a macro. This works great, but the macro has to be run every time someone changes the thickness (All of our stock material has a different thickness, so the program I made is driven by the thickness of the part) or else the stock number will be incorrect.
I have made a custom message box that pops up when the macro is run, and the user can choose from a list of materials that we keep on stock.
I would like to make the macro run every time someone edits the Base-Flange1 feature under the template we use (and only under this template). So when the user clicks to edit the feature, the box pops up, then the user selects the material, and the macro will assign the correct thickness, stock number, material, ect.., and then exit out of the Base-Flange feature.
The macro is already working (except for setting the material thickness, which I think will not be that hard), I just need to get it to run when the user selects to edit the Base-Flange1 feature...
Thanks for all the help,
Eric Roe
Electro-Mechanical Engineer
Airfloat LLC
RE: Access "Author" and "Comments" properties in VBA macro
Eric
RE: Access "Author" and "Comments" properties in VBA macro
I made a custom message box that will open when a user runs the macro. This box lists all of the stock materials that my company uses. So all the user has to do is select the material he wants to use, and the program will automatically set the thickness, stock number, material description, and change to the correct material.
I have attached a screen shot of the message box. I added a user entry field if the part is not stock (but I do not have that working yet).
I have everything working right now, except:
I have not figured out a way to edit the thickness of the material (I think I am close, but any help via similar programs would be awesome). I found a way to edit the base-Flange feature using VBA, but I am still trying to figure out how to change the thickness value.
The program is a little disorganized. At first I wanted to enter all the data I need into an array, but I was having problems with getting it to work, so right now there is no easy way to edit our stock material. If a stock number changes, I would have to search through the program and find the button press that is attached to that specific stock number and change it. I would like to have a table in a csv or excel file that the program could reference to.
And the last update that I want to do, but have not even started trying to figure out is getting the message box to open automatically. I would like in the future for the box to open up only if the user is working with a sheet metal part, and tries to edit the base-flange1 feature. I imagine that there would have to be a macro that starts up when SW starts, and waits (if a macro can wait) until it sees the user trying to edit the base-flange1 feature, then when the program enters the feature edit, the message box will pop up allowing the user to enter the desired stock material.
I am still working on some bugs in the program, but as soon as I finish, I will post.
Eric Roe
Electro-Mechanical Engineer
Airfloat LLC
RE: Access "Author" and "Comments" properties in VBA macro
http://
Personally I've never seen a macro auto-run in SW. It seems like a security hole to me anyway.
To reference an external file, would be some direct VB.NET code.
http://www.w3schools.com/vbscript/
That is a good reference. But then I need to ask:
Does anyone know if a SW Macro can access external files that are not SW related?
Devon Murray, EIT [Mechanical]
Solidworks 2011 SP 2.0
RE: Access "Author" and "Comments" properties in VBA macro
Deepak Gupta
SW 2010 SP4.0 & 2011 SP3.0
Boxer's SolidWorks™ Blog