custom property macro for Weight, how to get the parenthesis?

250 views
Skip to first unread message

Sam

unread,
Jan 10, 2008, 11:30:37 AM1/10/08
to
I am trying to write a macro to create a custom property for Weight
and set the Weight custom property value to "SW-
Ma...@Part1.SLDPRT" (including parenthesis) so that at the next save
the value of the Weight custom property will be set to the weight of
the model. The macro works for the most part but I cannot get the
initial value of the Weight custom property to include the
parenthesis. The codes is below and as you can see the "SW-
Ma...@Part1.SLDPRT" is enclosed in parenthesis but the only thing added
to the custom property value is SW-...@Part1.SLDPRT (without the
parenthesis). I tried adding a second set of parenthesis to the code
(""SW-...@Part1.SLDPRT"") but that causes a problem with the macro.

I am sure there must be a way to do this, any help will be greatly
appreciated.


ModelDoc.AddCustomInfo3("", "Weight", swCustomInfoText, "SW-
Ma...@Part1.SLDPRT")

That70sTick

unread,
Jan 10, 2008, 12:03:49 PM1/10/08
to
Do you mean "quotation marks"?

Use CHR(34) to get a quote mark.

i.e.
String1 = chr(34) & "This text in quotes" & chr(34)

Sam

unread,
Jan 10, 2008, 12:17:26 PM1/10/08
to
HA, yes quotation marks...

But for some reason that is not getting converted into the weight
value, the custom property value remains "SW-...@Part1.SLDPRT". If I
manually add that same text string to the value for a custom property
(and I mean manual key strokes, not by selecting from the combo box)
then the weight of the component is assigned to the custom property.
Even if I add "SW-...@Part1.SLDPRT" to a custom property for a part
file that has already been saved as 1234.sldprt then the Part1 is
converted to 1234.sldprt and the weight value is assigned to the
custom property but it does not seem to be working that way when the
custom property value is assigned via the API.

Any ideas why???


Thanks,

Sam

That70sTick

unread,
Jan 10, 2008, 12:53:40 PM1/10/08
to
Post your code.

Sam

unread,
Jan 10, 2008, 1:04:51 PM1/10/08
to
Here is the code, its part of a batch utilities program that I have
developed over time. There is some "filtering" at the first to make
sure its only working on sldprt files then a silent save at the end.
The code for adding the Weight custom property is near the end, look
for SetSuccess = ...

Dim selcol As New Collection
Dim longerror As Long
Dim DocOptions As Long
Dim thisDoc As Variant
Dim i As Integer
Dim c As Integer
Dim retval As Variant
Dim vConfNameArr As Variant
Dim sConfigName As String
Dim ci As Long
Dim bShowConfig As Boolean
Dim boolstatus As Boolean
Dim swSelMgr As SldWorks.SelectionMgr

Set swApp = Application.SldWorks
DocOptions = swOpenDocOptions_Silent

For Each thisDoc In doclist

Dim DocType As Long
Dim DocExt As String
Dim SkipFile As Long

SkipFile = InStr(1, thisDoc, "~", vbTextCompare) 'Do not
process temp files

If SkipFile = 0 Then
DocExt = UCase(Right(thisDoc, 3))
Select Case DocExt
Case "PRT"
DocType = swDocPART
Case "DRW"
DocType = swDocDRAWING
Case "ASM"
DocType = swDocASSEMBLY
Case Else
DocType = swDocNONE
'MsgBox "Unexpected extension encountered: " &
thisDoc
End Select

'*** Filter doc types to act on***
If DocType = swDocPART Then 'Act on slddrw files only
Dim DocErrors As Long
Dim DocWarnings As Long
Dim ModelDoc As SldWorks.ModelDoc2
Dim nretval As Long
Dim SetSuccess As Boolean
Dim swCustPropMgr As SldWorks.CustomPropertyManager

Set ModelDoc = swApp.OpenDoc6(thisDoc, DocType,
DocOptions, "", DocErrors, DocWarnings)
If ModelDoc Is Nothing Then
MsgBox "Couldn't open document: " & thisDoc
Else

SetSuccess = ModelDoc.AddCustomInfo3("", "Weight", swCustomInfoText,
Chr(34) & "SW-...@Part1.SLDPRT" & Chr(34))

Dim SaveOptions As Long
SaveOptions = swSaveAsOptions_Silent
Dim SaveSuccess As Boolean
SaveSuccess = ModelDoc.Save3(SaveOptions,
DocErrors, DocWarnings)
If SaveSuccess = False Then
MsgBox "Couldn't save document: " & thisDoc
End If
End If
swApp.CloseDoc thisDoc
End If
End If
Next
End Sub

That70sTick

unread,
Jan 10, 2008, 1:35:13 PM1/10/08
to
Looks like it should work.

Does the property already exist in the file? AddCustomInfo does not
overwrite or change existing properties.

Usually I perform an AddCustomInfo and then a CustomInfo2 immediately
after in case the property already exists and I want to overwrite.

Sam

unread,
Jan 10, 2008, 2:24:49 PM1/10/08
to
No the custom property does not already exist.

I think figured out the problem, Chr(34) does not seem to be adding a
quote. It adds two individual hash marks that looks like a quote but
it actually two indivdual characters. I need to find the character
number for a real quote, I think that will fix the problem.


Sam

That70sTick

unread,
Jan 10, 2008, 2:33:26 PM1/10/08
to
Interesting. I just checked one of my other macros and CHR(34) works
fine for this purpose.

Are you using a different (non-English) character set on your computer?

Sam

unread,
Jan 10, 2008, 2:54:25 PM1/10/08
to
Nope, its english. Can you explain how and where you were able to find
out that Chr(34) converts to an apostrophe? Maybe I can do some
research and find the number for quotes?

Thanks for your help...

Sam

unread,
Jan 10, 2008, 3:06:10 PM1/10/08
to
It looks like 39 gives a single apostrophe and 34 gives a double
apostrophe (that looks like a quote but really is not a quote).

Sam

That70sTick

unread,
Jan 10, 2008, 3:25:04 PM1/10/08
to
Perhaps write a program.

I once wrote a VBA program w/ a form w/ one textbox and a command
button. Enter the a character into the textbox, hit command button,
and get a message box that returns the ascii number of the first
character in the textbox.

You will need to use the ASC command.

Sam

unread,
Jan 10, 2008, 3:43:54 PM1/10/08
to
I got it to work, it needs three opening quotes and three closing
quotes. I tested it and it works fine.


SetSuccess = ModelDoc.AddCustomInfo3("", "Weight", swCustomInfoText,

"""SW-...@Part1.SLDPRT""")


Thanks for your help

Sam

xlei...@gmail.com

unread,
Jul 2, 2017, 1:52:15 PM7/2/17
to
Please I need the macro to just insert weight into the custom properties for all parts in a folder
Reply all
Reply to author
Forward
0 new messages