iLogic script "dirtying" drawing
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I've been adding some iLogic to our drawing templates and I've noticed an unwanted side effect. I have the rule run after open in case the model properties were changed. If nothing was updated and the code makes no changes the drawing will still prompt to be saved when you close it. I noticed two different things in my code that are causing the "changes" which prompts the save but I cannot figure out how to eliminate it.
My code does two main things. The first is it checks if the model has it's own iLogic rule for updating the material, if not this code will update the material saved in a custom iProperty. The second operation checks the length of two title block fields and changes the text box width scale if the text is too long.
The call to edit the title block and exit the title block show up in the undo history, which means the file was "changed" and will prompt to save. I thought about adding some code to undo those operations if nothing was changed but I'm pretty sure even if you undo any operations the file will still prompt to save.
Anyone know a way to get around dirtying the drawing while still being able to check if the values are up to date? I tried some code down below to access the title block in a different way that might not dirty the file, but it seems like it's not possible to change values when accessing the title block with that method.
Dim docFile As Document If ThisDoc.ModelDocument IsNot Nothing Then docFile = ThisDoc.ModelDocument Else Return End If 'Check if part has iLogic rule named Material, if not this will update Matrl iProp even if Matrl already exists Dim rules as IEnumerable = iLogicVb.Automation.Rules(docFile) Dim rule As Object If (rules IsNot Nothing) Then For Each rule In rules If (rule.Name = "Material") Then MatFound = True Next rule End If 'define the property set customPropertySet = docFile.PropertySets.Item("Inventor User Defined Properties") designPropertySet = docFile.PropertySets.Item("Design Tracking Properties") 'look for the custom propety and add it if not found Try If (customPropertySet.Item("MATRL").Value = "" Or MatFound <> True) Then customPropertySet.Item("MATRL").Value = designPropertySet.Item("Material").Value.toupper End If Catch customPropertySet.Add("", "MATRL") customPropertySet.Item("MATRL").Value = designPropertySet.Item("Material").Value.toupper End Try 'Titleblock text fiting Dim odrawdoc As DrawingDocument odrawdoc = ThisApplication.ActiveDocument Desc = designPropertySet.Item("Description").Value Matrl = customPropertySet.Item("MATRL").Value Dim oTitleBlockDef As TitleBlockDefinition oTitleBlockDef = odrawdoc.ActiveSheet.TitleBlock.Definition Dim oSketch As DrawingSketch Call oTitleBlockDef.Edit(oSketch) Dim count As Integer count = oSketch.TextBoxes.count While (count > 0) If (oSketch.TextBoxes.Item(count).Text = "<DESCRIPTION>") Then If (oSketch.TextBoxes.Item(count).WidthScale <> Iif(Len(Desc) < 30, 1, 29 / (Len(Desc) - 1))) Then oSketch.TextBoxes.Item(count).WidthScale = Iif(Len(Desc) < 30, 1, 29 / (Len(Desc) - 1)) End If Else If (oSketch.TextBoxes.Item(count).Text = "<MATRL>") Then If (oSketch.TextBoxes.Item(count).WidthScale <> Iif(Len(Matrl) < 26, 1, 25 / (Len(Matrl) - 1))) Then oSketch.TextBoxes.Item(count).WidthScale = Iif(Len(Matrl) < 26, 1, 25 / (Len(Matrl) - 1)) End If End If count = count - 1 End While Call oTitleBlockDef.ExitEdit iLogicVb.UpdateWhenDone = True
Failed test
Dim odrawdoc As DrawingDocument Set odrawdoc = ThisApplication.ActiveDocument Dim invDoc2 As Document Set invDoc2 = ThisApplication.Documents.ItemByName(odrawdoc.ReferencedDocuments.Item(odrawdoc.ReferencedDocuments.count).FullDocumentName) Dim Desc As String Desc = invDoc2.PropertySets.Item("Design Tracking Properties").Item("Description").Value Dim Matrl As String Matrl = invDoc2.PropertySets.Item("Inventor User Defined Properties").Item("MATRL").Value Dim oTitleBlock As TitleBlock Dim oTextBox As TextBox Dim oSheet As Sheet For Each oSheet In ThisApplication.ActiveDocument.Sheets Set oTitleBlock = oSheet.TitleBlock For Each oTextBox In oTitleBlock.Definition.Sketch.TextBoxes If (oTextBox.Text = "<DESCRIPTION>") Then If (oTextBox.WidthScale <> IIf(Len(Desc) < 30, 1, 29 / (Len(Desc) - 1))) Then Debug.Print oTextBox.WidthScale End If ElseIf (oTextBox.Text = "<MATRL>") Then If (oTextBox.WidthScale <> IIf(Len(Matrl) < 26, 1, 25 / (Len(Matrl) - 1))) Then Debug.Print oTextBox.WidthScale
'This line errors, it seems it's not possible to change things accessing the title block this way oTextBox.WidthScale = 1 End If End If Next Next