IsModifiable Query

IsModifiable Query

roy7BB24
Advocate Advocate
294 Views
3 Replies
Message 1 of 4

IsModifiable Query

roy7BB24
Advocate
Advocate

Hi All,

I've recently started using a script that iterates through a top level assembly BOM and conducts a few processes on each line of the BOM depending on what each item is. The loose format of the script is:

Sub Main

Dim Doc As AssemblyDocument = ThisApplication.ActiveDocument

Dim BOM As BOM = Doc.ComponentDefinition.BOM
Dim BomView As BOMView = BOM.BOMViews.Item(1)

SetPartNumbers (BOMView.BOMRows)

End Sub

 

Which then calls the subroutine:

 

Private Sub SetPartNumbers(BOMRows As BOMRowsEnumerator, A_No As Integer)

For i As Integer = 1 To BOMRows.Count
'Get the current row
Dim Row As BOMRow = BOMRows.Item(i)
'Reference to the primary component definition of the Row
Dim CompDef As ComponentDefinition = Row.ComponentDefinitions.Item(1) 

 

Without posting the whole code here one of the processes here is: 

'Process Assemblies
ElseIf CompDef.Document.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject _
AndAlso CompDef.Document.IsModifiable _
AndAlso CompDef.Document.PropertySets.Item(4).Item("PartSet").Value = 0 _
AndAlso CompDef.BOMStructure = 51970
CompDef.Document.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value = "A-" + Format(GlobalVariable.Assembly_Counter, "00")
CompDef.Document.PropertySets.Item(4).Item("PartSet").Value = 1
CompDef.Document.Save
'Logger.Info(GlobalVariable.Assembly_Counter)
GlobalVariable.Assembly_Counter += 1
A_Input = GlobalVariable.Assembly_Counter - 1
Logger.Info("Found Subbassembly - Beginning processing A-" + Format(A_Input, "00"))
SetPartNumbers(Row.ChildRows, A_Input)
'Logger.Info("Labelled new assembly as " + CompDef.Document.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value)
 
I've found few problems with this code that I think are related to the size of the assembly and possibly something else that I'm not sure of (for reference the assembly I'm testing on has 1668 total files and 783 unique files). The first issued seemed to be that the script worked correctly but inventor wasn't saving the complete list of changes properly. The script will affect every single editable part in the assembly, and every sub assembly that makes up the top level, which I think I've corrected by saving each part as it finishes processing.
I think the second problem is related to the IsModifiable property. Looking up the definition in the API Help (Inventor 2022 Help | PartDocument.IsModifiable Property | Autodesk) it says that a part may be non-modifiable if another document belonging to the file is being edited. I'm finding I can only run the script if I restart inventor and only have top level assembly open, and even then it seems to be working 99% of the time. In the current example there's over 100 assemblies but 2 of them aren't processing correctly. I'm wondering if somehow these two assemblies process as unmodifiable at the moment the script processes them, or if the error is related to the size of the assembly. If anyway has experience with this, any assistance would be appreciated. Note sure if its possible or not but if someone has an example of how to close each Bom line on completion it would be appreciated
Kind Regards
 
Roydon Mackay

 

0 Likes
Accepted solutions (1)
295 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor
Accepted solution

Hi @roy7BB24.  That is a tough one to explain, and possibly even tougher to work around, when dealing with a really large assembly like that.  There are multiple possible reasons why the IsModifiable property would return False.  One of the most common reasons is due to the file being ReadOnly.  If the file is in the Content Center, or the file is located within a directory that has been configured as a 'library' area, then those files will usually act like ReadOnly, even if the file itself does not have that main file attribute checked.  Another more recent issue though, is when there are multiple ModelStates defined within a single model file.  If a model file is for something like an iPart or iAssembly, it will not have any ModelStates at all, because iPart/iAssembly and ModelStates to not mix.  But most normal parts and assemblies will have at least the one, original ModelState named either "Master" (in 2022), or "[Primary]" (2023 or later).  While there is only that one, original ModelState present in a model file, everything seems normal / OK.  However, once you have more than just that one, things start to get complicated.  This is because each ModelState is sort of like another Document object in the same file on disk.  Then, when you place an instance of a model with multiple ModelStates in it into an assembly, it gets seen as referencing a ModelState 'member' document.  Those often act like ReadOnly, but there are ways to work around that behavior.  Unfortunately, one of the workarounds is to update the assembly between working on one component, and working on the next component instance tha....  That can cause the process to be very slow when dealing with a large assembly.  Another trick is, even though technically all of the referenced documents are already either 'initialized' or opened (not visibly, but in the background), we can still use the Documents.Open method, and specify its FullDocumentName (not just FullFileName) to directly open the model document, and use the referenced document that method returns to edit it with, because that seems to let you edit it directly, where it may otherwise not be modifiable (IsModifiable = False).  Then you may still need to be mindful of the MemberEditScope setting (a setting which specifies if you intend to edit just the active member, or all members).  A lot more could still be said, but its getting to be like writing a book.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 4

Frederick_Law
Mentor
Mentor

Add Logger.Info to show files that are Not IsModifiable.

Then check and see why.

0 Likes
Message 4 of 4

roy7BB24
Advocate
Advocate

Hi, Thanks for the help. The first section of the code was meant to go through and flag all the unmodifiable parts that weren't content center or reference parts, unfortunately I made an error in this section, it wasn't flagging anything which was adding to my confusion. I've made some changes and its now flagging the unmodifiable parts correctly. All of the un-modifiable flags were due to model states. At this stage I've deleted the model states out as I don't need them for the project I'm working on, but this is a tool I'm hoping to use on every job I complete, and I'd rather the tool worked on components with different model states. That said there's a little bit for me to rethink here to make it work. I'm thinking down the track I'll take suggestion of detecting if there's more than one model state and opening just those files directly for edit. But I don't need this just yet, so I think I'll finish testing this version and make sure everything else works and go from there

 

Kind Regards

 

Roydon Mackay

 

 

0 Likes