SW09 Macro to get custom properties
SW09 Macro to get custom properties
(OP)
I currently have a macro that saves my SW drawings as pdf. It uses two dialog boxes to enter the revision and drawing size, which are then used in the file name for the pdf. (ex. 12345678_BA.pdf for Size B, Rev A)
Is there anyway to pull these out of the custom property fields? I have a custom property already set up for revision and drawing size, but I can't seem to find the code to call them up.
Is there anyway to pull these out of the custom property fields? I have a custom property already set up for revision and drawing size, but I can't seem to find the code to call them up.






RE: SW09 Macro to get custom properties
-handleman, CSWP (The new, easy test)
RE: SW09 Macro to get custom properties
RE: SW09 Macro to get custom properties
-handleman, CSWP (The new, easy test)
RE: SW09 Macro to get custom properties
I appreciate any help you can give.
RE: SW09 Macro to get custom properties
-handleman, CSWP (The new, easy test)
RE: SW09 Macro to get custom properties
Colin Fitzpatrick (aka Macduff)
Mechanical Designer
Solidworks 2008 SP 4.0
Dell 490 XP Pro SP 2
Xeon CPU 3.00 GHz 3.00 GB of RAM
nVida Quadro FX 3450 512 MB
3D Connexion-SpaceExplorer
RE: SW09 Macro to get custom properties
RE: SW09 Macro to get custom properties
RE: SW09 Macro to get custom properties
To sum up:
You have some macro.
You don't know where it came from or who wrote it.
You want said macro to access custom properties.
You can't figure out how to use the CustomPropertyManager.
The examples in the API help don't help.
Not sure where to go from here... Can you post the code or the macro file?
-handleman, CSWP (The new, easy test)
RE: SW09 Macro to get custom properties
Dim SwApp As SldWorks.SldWorks
Dim Model As SldWorks.ModelDoc2
Dim MyPath, ModName, NewName As String
Dim dPathName As String
Dim MyPathConf As String
Dim fso As Object
Dim MB As Boolean
Dim Errs As Long
Dim Warnings As Long
Sub main()
Set SwApp = Application.SldWorks
Set Model = SwApp.ActiveDoc
' Error handler for no document loaded
If Model Is Nothing Then MsgBox "No document loaded!", vbCritical: End
' Use one of the three following options for PDF save location
' Comment out the options with are not used.
' Option 1: Use the current directory
'MyPath = CurDir
' Option 2: Specify the directory you want to use
'MyPath = "K:\input"
' Option 3: Use the drawing folder
MyPath = Left(Model.GetPathName, InStrRev(Model.GetPathName, "\") - 1)
' Call correct sub
If Model.GetType <> 3 Then Call notdrawing
Call ifdrawing
End Sub
Sub notdrawing()
' Get documnet save path
dPathName = Model.GetPathName()
' Error handler if no save path
If ("" = dPathName) Then MsgBox ("This document has not been saved yet"), vbCritical: End
' Set PDF file name
ModName = Left(Model.GetTitle, InStrRev(Model.GetTitle, ".") - 1)
Call alldoc
End Sub
Sub ifdrawing()
' Set PDF file name
ModName = Left(Model.GetTitle, InStrRev(Model.GetTitle, " Sheet") - 3)
Call alldoc
End Sub
Sub alldoc()
Dim Message2, Title2, Default2, DwgSize
Message2 = "Enter a Drawing Size" ' Set prompt.
Title2 = "Drawing Size" ' Set title.
Default2 = "B" ' Set default.
' Display message, title, and default value.
DwgSize = InputBox(Message2, Title2, Default2)
Dim Message, Title, Default, Revision
Message = "Enter a Revision Level" ' Set prompt.
Title = "Revision Level" ' Set title.
Default = "0" ' Set default.
' Display message, title, and default value.
Revision = InputBox(Message, Title, Default)
' See PDF file name with extention .pdf
NewName = ModName & "_01" & DwgSize & Revision & ".pdf"
' Get path and user confirmation
MyPathConf = InputBox("No notification will occur for " & Chr(13) & "success PDF creation." & Chr(13) & Chr(13) & "Save " & NewName & " to:", "Confirm PDF Save Path", MyPath)
If MyPathConf = "" Then MsgBox "Save As PDF cancelled by user.", vbInformation: End
' Determine if directory exists
Set fso = CreateObject("Scripting.FileSystemObject")
If (Not fso.FolderExists(MyPathConf)) Then MsgBox (MyPathConf + " does not exist!"), vbCritical: End
' PDF Creation
MB = Model.SaveAs4(MyPathConf & "\" & NewName, swSaveAsCurrentVersion, swSaveAsOptions_Silent, Errs, Warnings)
' Warnings to user on Error
' MsgBox "Errors: " & Errs & vbCrLf & "Warnings: " & Warnings
If Warnings <> 0 Then
MsgBox "There were warnings. PDF creation may have failed. Verify" & Chr(13) & "results and check possible causes.", vbExclamation
Else
End If
If MB = False Then
MsgBox "PDF creation has failed! Check Add-ins (if S/W 2005 or older)," & Chr(13) & "available disk space or other possible causes.", vbCritical
Else
End If
Call last
End Sub
Sub last()
' Clear immediate values
Set Model = Nothing
Set MyPath = Nothing
End
End Sub
RE: SW09 Macro to get custom properties
-handleman, CSWP (The new, easy test)
RE: SW09 Macro to get custom properties
RE: SW09 Macro to get custom properties
I think the OP's intent is to run the macro on drawings, which unless I am mistaken do not have configuration-specific custom properties.
It does get a bit uglier if the desire is to pull the values from a model included in the drawing.
Eric
RE: SW09 Macro to get custom properties
Eric
RE: SW09 Macro to get custom properties
http://www.eng-tips.com/viewthread.cfm?qid=163578
RE: SW09 Macro to get custom properties
RE: SW09 Macro to get custom properties
CODE
Dim Message, Title, Default, Revision
Message = "Enter a Revision Level" ' Set prompt.
Title = "Revision Level" ' Set title.
Default = "0" ' Set default.
' Display message, title, and default value.
Revision = InputBox(Message, Title, Default)
Replace
CODE
CODE
Of course, replace Revision with whatever you've named your revision property.
-handleman, CSWP (The new, easy test)
RE: SW09 Macro to get custom properties
Dim Message, Title, Default, RevLev
Message = "Enter a Revision Level" ' Set prompt.
Title = "Revision Level" ' Set title.
Model.Extension.CustomPropertyManager("").Get2 "Revision", Empty, Default
' Display message, title, and default value.
RevLev = InputBox(Message, Title, Default)
It gives me the following error:
Compile Error
ByRef argument type mismatch
RE: SW09 Macro to get custom properties
Change
Dim Message, Title, Default, RevLev
to (at least)
dim Message as String
dim Title, Default, RevLev
it would also be good if you go through the code and figure out what data type each variable really should be and explicitly declare their type.
-handleman, CSWP (The new, easy test)
RE: SW09 Macro to get custom properties
RE: SW09 Macro to get custom properties
RE: SW09 Macro to get custom properties
Model.Extension.CustomPropertyManager("").Get2 "Revision", Empty, Default
puts the value of the custom property "Revision" into the string variable Default. The line
RevLev = InputBox(Message, Title, Default)
takes the string variable Default and uses it as the default value for the InputBox. The result of the InputBox goes into RevLev.
-handleman, CSWP (The new, easy test)
RE: SW09 Macro to get custom properties
I updated the code so that if the custom property is blank, it opens the message box to prompt the user for the values.
How do I save the user input back to the custom properties?
RE: SW09 Macro to get custom properties
-handleman, CSWP (The new, easy test)
RE: SW09 Macro to get custom properties
Model.Extension.CustomPropertyManager("").Get2 "DwgSize", Empty, DwgSize
It gave me a run-time 438 error: Object does not support this property or method
RE: SW09 Macro to get custom properties
-handleman, CSWP (The new, easy test)
RE: SW09 Macro to get custom properties
Dim Revision As String
Model.Extension.CustomPropertyManager("").Get2 "Revision", Empty, Revision
If Revision = "" Then
Dim Message As String
Dim Title As String
Dim Default As String
Message = "Enter a Revision" ' Set prompt.
Title = "Revision" ' Set title.
Default = 0
' Display message, title, and default value.
Revision = InputBox(Message, Title, Default)
Model.Extension.CustomPropertyManager("").Set2 Revision, Revision
End If
RE: SW09 Macro to get custom properties
Model.Extension.CustomPropertyManager("").Set2 "Revision", Empty, Revision
Still doesn't work.
RE: SW09 Macro to get custom properties
Is there a reason this doesn't work?
RE: SW09 Macro to get custom properties
Hint 1: There is no "Set2"
Hint 2: You have too many arguments.
-handleman, CSWP (The new, easy test)
RE: SW09 Macro to get custom properties
Thank you for all your help!! It works perfectly now!