×
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

SW09 Macro to get custom properties
2

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.

RE: SW09 Macro to get custom properties

2
Look into the CustomPropertyManager object.

-handleman, CSWP (The new, easy test)

RE: SW09 Macro to get custom properties

(OP)
I am not sure what you mean.

RE: SW09 Macro to get custom properties

Are you familiar with the API help?  Do you know anything about macros/VBA, or do you just have a macro that you found somewhere?  I'm not trying to be a smart***, just looking for the starting point to help you out.

-handleman, CSWP (The new, easy test)

RE: SW09 Macro to get custom properties

(OP)
I tried looking through the API help but nothing seemed to work. Not very familiar with writing macros. Using a macro I found somewhere, just slightly modified.

I appreciate any help you can give.

RE: SW09 Macro to get custom properties

So did you search the API help for CustomPropertyManager?

-handleman, CSWP (The new, easy test)

RE: SW09 Macro to get custom properties

SCTodd, where did you find the macro, 3DCC?

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

(OP)
Not sure where I found it. Wasn't 3DCC as far as I can remember.

RE: SW09 Macro to get custom properties

(OP)
I searched the API help for CustomPropertyManager, but that doesn't seem to work.

RE: SW09 Macro to get custom properties

Well, the CustomPropertyManager is the way to access custom properties through code.  

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

(OP)
Here it is:

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

Configuration-specific custom properties, or general file custom properties?

-handleman, CSWP (The new, easy test)

RE: SW09 Macro to get custom properties

(OP)
It is for a drawing, so general file custom properties.

RE: SW09 Macro to get custom properties

handleman,

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

-1 star for me for not looking at the current thread before hitting submit.

Eric
 

RE: SW09 Macro to get custom properties

(OP)
You guys didn't give up did you?

RE: SW09 Macro to get custom properties

Sorry, forgot about this one.  Find this block:

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

Default = "0"    ' Set default.
with

CODE

model.Extension.CustomPropertyManager("").Get2 "Revision", Empty, default

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

(OP)
When I try that the block ends up as:


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

Ah, this is due to improper variable declaration.  Lazy people just declare everything without specifying a type.  You run into problems when functions expect a specific type and don't get it.  

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

(OP)
Thank you very much for your help! It works finally! It successfully brings the revision from the file into the message box!

RE: SW09 Macro to get custom properties

(OP)
Is there a way to just have the custom properties brought into the macro. What I am hoping to do is only bring up the message boxes of the custom properties are blank.

RE: SW09 Macro to get custom properties

The line

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

(OP)
One last question.
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

Use Set instead of Get.

-handleman, CSWP (The new, easy test)

RE: SW09 Macro to get custom properties

(OP)
When I added a line:

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

Where did you put the line?

-handleman, CSWP (The new, easy test)

RE: SW09 Macro to get custom properties

(OP)
In the following block:


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

(OP)
Last line should have said:

Model.Extension.CustomPropertyManager("").Set2 "Revision", Empty, Revision

Still doesn't work.
 

RE: SW09 Macro to get custom properties

(OP)
handleman,
Is there a reason this doesn't work?
 

RE: SW09 Macro to get custom properties

Sorry.  I meant "Look up the CustomPropertyManager in the API help and see how to use the setting method corresponding to Get2".

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

(OP)
handleman,
Thank you for all your help!! It works perfectly now!

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