- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I cannot figure out how to set the description for the currently active document. This script runs through every open part file and generates a description. No matter what combination I put into the iProperties field it only works on the very last part file.
Dim oPartDoc As PartDocument
Dim oDoc As Document
Dim oRefFile As FileDescriptor
oPartDoc = ThisDoc.Document
For Each oDoc In oPartDoc.AllReferencedDocuments
oDocName = IO.Path.GetFileNameWithoutExtension(oDoc.FullFileName)
Next
UHeight = InputBox("Enter Height of Unit in INCHES","Height","")
UWidth = InputBox("Enter Width of Unit in INCHES","Width","")
For Each oPartDoc In ThisApplication.Documents.VisibleDocuments
oPartDoc.Activate
oPartDoc = ThisDoc.Document
PanelType = InputBox("Enter Panel Type", "Panel Type", PanelType)
PanelType = UCase(PanelType)
NewDesc = "75-" & PanelType & " " & oDocName
iProperties.Value(oPartDoc.File.FullFileName, "Custom", "Panel Type") = PanelType
iProperties.Value(oPartDoc.File.FullFileName, "Project", "Description") = NewDesc
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @C_Haines_ENG. It is a little difficult for me to understand your full intent with the code you posted, but I did attempt to correct it for you. You were using two loops in there, but the first one was just re-setting the value of a variable a bunch of times in a row, so it would only retain the last one it encountered. Then the second loop did not appear to have an ending line (Next), so I wasn't sure if this was all of the code, or just part of it. And I wasn't sure if those first two InputBox uses were only supposed to show one time, or once per 'visible' document in the second loop. When using the iProperties.Value() snippet, if you do not supply the first of 3 input variables, it will target the 'active' document at that moment, but when you do specify a document (not an assembly component), it wants its file name, without its path, but with its extension. To simplify, I replaced those two lines with equivalent lines of API code for accessing those iProperties.
See if this version of the code works any better for you, or as you intended.
For Each oDoc As Document In ThisApplication.Documents.VisibleDocuments
oDoc.Activate
oDocName = IO.Path.GetFileNameWithoutExtension(oDoc.FullFileName)
UHeight = InputBox("Enter Height of Unit in INCHES","Height","")
UWidth = InputBox("Enter Width of Unit in INCHES","Width","")
PanelType = InputBox("Enter Panel Type", "Panel Type", PanelType)
PanelType = UCase(PanelType)
NewDesc = "75-" & PanelType & " " & oDocName
oDoc.PropertySets.Item("Inventor User Defined Properties").Item("Panel Type").Value = PanelType
oDoc.PropertySets.Item("Design Tracking Properties").Item("Description").Value = NewDesc
Next
Wesley Crihfield
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
The first for loop is searching for the first referenced document in a part, as all the other open documents will have the same referenced part.
The code you gave did not work, no errors just not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
OK. I clearly do not fully understand what all you had in mind. Maybe if you would explain the process you want this rule to do, in as much detail as possible, and maybe with bullet points, I (or others here) may be able to help you get it working the way you want it to work.
Wesley Crihfield
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Ok I see the problem, I corrected my code to work, however I need to add the custom iProperty before writing to it with this method. How can I do that with this API?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
You could use something like this:
Try
oDoc.PropertySets.Item("Inventor User Defined Properties").Item("Panel Type").Value = PanelType
Catch
oDoc.PropertySets.Item("Inventor User Defined Properties").Add(PanelType, "Panel Type")
End Try
...or you could do it the more proper way, which would be to loop through all of the custom iProperties in that document, to see if the one you want to work with exists yet. If it is found, set its value, but if after the loop, it has not been found yet, then create it. But that would take a lot more code.
Wesley Crihfield
(Not an Autodesk Employee)