Written by: Bryce Hooper, Application Engineer, DASI Solutions
Continuing our series on automating forms inside of SOLIDWORKS PDM, we’ll move along with an example in Microsoft Word. (See Part 1 on Excel docs as forms here.)
Here is our example of an Engineering Change Notice form:
Now, to map these properties to our file and our data card, we will need to start with the variable setup. For Microsoft Office documents, the setup is pretty simple. For each variable we are mapping we will want to use the attribute block CustomProperty. This should be familiar as it is the same that we would use for SOLIDWORKS documents and was also noted in our article about Excel forms.
Set this to use the proper extensions that we are intending to use and the rest of the options can be set at your discretion.
It is then time to map the custom properties to those ranges. This is done by going to the file info inside of Word, then properties and Advanced properties.
In the dialog that shows we go to the Custom tab. Here we find a list of properties that are already defined. Any variables that have already been assigned a value inside of PDM will automatically be created. Any that haven’t we will create now. To do this, we give the property a name in the Name field and then give it a value in the Value field. A space will work for this value, but in the interest of seeing what we are setting up, it may be advantageous to give this a realistic value to get our formatting right.
Now that we’ve created the custom properties inside of Word, we can enter them into the body of our document. This is done by going to the Insert tab > Quick Parts > Field.
Do this with your cursor in the desired location, and the following dialog will help us add the right field.
To get to our custom properties, we need to scroll down to the Field Name “DocProperty”. This will give us the Field Property of our available custom properties (plus some file properties). Select the custom property that we need to enter and click “OK”. If we had filled in a value for the custom property, it will now show.
For Word, custom properties and the fields they are linked to do will not update automatically or open by themselves. We have two options in this case.
Here, I’ll give you the code to do number two on that list.
To start we’ll need to create a new macro in Word. To do this, we can press Alt+F8. We get the dialog shown below.
Click “Create” and paste in the following code snippet:
Sub AutoOpen()
With Options .UpdateFieldsAtPrint = True .UpdateLinksAtPrint = True End With ActiveDocument.Fields.Update End Sub |
Save and close the VB editor. From now on, each time the file is opened the fields should update.
From here, we can make things even easier by creating a template to help us fill in values or serialize a naming convention. We can also create actions in our workflow transitions to automatically fill in names and dates for approvals.
There are, of course, some pros and cons to this technique. I’ll break them down a bit here. By no means is this an all-encompassing list.
Pros:
Cons:
If you’re looking for other ways to create forms inside of PDM, you may also want to check out our blog on Microsoft Excel forms and watch for our upcoming third part in the series covering XML documents as forms in PDM.
Categories: SOLIDWORKS Enterprise PDM, Tips & Tricks