I have a very simple iLogic code that I am running before save on my drawing template. It loads the correct border size based on the sheet size. The problem is, all my borders are zone borders but when it applies the new border, it erases all numbers and letters marking the zones. They don't get erased if I change the title block manually. Anyone know why it does that?
If ActiveSheet.Size = "A" ActiveSheet.Border = "The Name of my A title block" End If
Solved! Go to Solution.
Solved by adam.nagy. Go to Solution.
Hi,
I am a little bit confused. Are you changing border or title block? These two are seperate which are defined by corresponding definition.
Could you provide more info such as a drawing (with your border definition) and a screenshot on what is the problem?
Hi,
I've just found this issue logged in our system and it does not seem to be fixed yet 😞
It's not specific to iLogic, you could reproduce the same by using "Call ThisApplication.ActiveDocument.ActiveSheet.AddBorder(myBorderDefinition)" in VBA
The only workaround I could think of is executing the same command that is being used when you double-click a specific Border definition in the Browser window in the user interface.
In that case we need to retrieve the definition of that control and then iterate through the broswer nodes, select the appropriate one and then execute the command.
In case of an iLogic rule it would look like this and it seemed to work fine when I tested it. In this case the border definition we want to add is "Border1"
Sub Main() Dim cd cd = ThisApplication.CommandManager.ControlDefinitions("DrawingBorderInsertNoDlgCtxCmd") Dim bp bp = ThisApplication.ActiveDocument.BrowserPanes("DlHierarchy") Dim node node = FindBorderNode("Border1", bp.TopNode.BrowserNodes) If Not ThisDoc.Document.ActiveSheet.Border Is Nothing Then ThisDoc.Document.ActiveSheet.Border.Delete End If node.DoSelect cd.Execute2 (True) End Sub Function FindBorderNode(name, nodes) Dim node For Each node In nodes If name = node.BrowserNodeDefinition.Label Then FindBorderNode = node Exit Function End If FindBorderNode = FindBorderNode(name, node.BrowserNodes) If Not FindBorderNode Is Nothing Then Exit Function End If Next End Function
Cheers,
Thanks a lot, I needed this as well.
I had to adapt a bit because of the BrowserPane name in french version and something that didn't work with this syntax. Here is what I changed :
Dim bp bp = ThisApplication.ActiveDocument.BrowserPanes("DlHierarchy")
Changed to
Dim bp bp = ThisApplication.ActiveDocument.BrowserPanes.Item("Modèle")
Of course "Modèle" is french for "Model". it's the browser name.
I also adapted it in VBA. It's a bit different but it works fine. Name of the border to insert is still Border1. Highlighted in bold and underlined are the french names of the browser and the border folder in Drawing resources.
Sub InsertCadre() Dim oDoc As DrawingDocument Set oDoc = ThisApplication.ActiveDocument Dim cd As ControlDefinition Set cd = ThisApplication.CommandManager.ControlDefinitions("DrawingBorderInsertNoDlgCtxCmd") Dim bp As BrowserPane Set bp = ThisApplication.ActiveDocument.BrowserPanes.Item("Modèle") Dim FoundNode As BrowserNode Dim node As BrowserNode Dim nodes As BrowserNodesEnumerator Set nodes = bp.TopNode.BrowserNodes For Each node In nodes If node.BrowserNodeDefinition.Label = "Border1" Then FoundNode = node End If Set FoundNode = FindBorderNode("Border1", node.BrowserNodes) If Not FoundNode Is Nothing Then Exit For End If Next If FoundNode Is Nothing Then If MsgBox("No border with this name", vbOKOnly, "Attention") = vbOK Then Exit Sub End If End If If Not oDoc.ActiveSheet.Border Is Nothing Then oDoc.ActiveSheet.Border.Delete End If FoundNode.DoSelect cd.Execute2 (True) End Sub Function FindBorderNode(ByVal name As String, ByVal nodes As BrowserNodesEnumerator) As BrowserNode Dim node As BrowserNode For Each node In nodes.Item("Cadres").BrowserNodes If name = node.BrowserNodeDefinition.Label Then Set FindBorderNode = node Exit Function End If If Not FindBorderNode Is Nothing Then Exit Function End If Next End Function
Yes of course but it's the case here. The aim is to use custom zone borders to place them and sometimes modify the number of zones for a same sheet size.
Hi,
Do you still need help, or you're OK now? 🙂
Cheers,
Hi,
I'm still using Inventor 2013 and have been having the same problem. Was a simpler solution ever found?
thanks,
John
Hi Adam, hi to all,
i have attached an idw file.
I use your code Adam, works fine, only some issue that i can't fix it.
Just open the idw, run the Form in it, and try switch through the sheets option (A0,A1,A2..etc..), nothing happen.
To make it works i have to manually insert a boder from Drawing Resource, then if i use the Form it works.
How can i make it works directly from the beginning?
I think that it depends on the closed border folder in Drawing Resource..
Thank you Adam, thank you all.
Admaiora
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Any solutions in the meanwhile?
Admaiora
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Hi,
The difference between when it's working and when it's not working is not that you added a border manually, but that you expanded the list of borders in the model browser window. It seems once it's been expanded the code works even if you collapse it.
You can expand the border nodes programmatically as well. Just make the selected node visible:
Dim node node = FindBorderNode("Bordo A0", bp.TopNode.BrowserNodes) node.EnsureVisible()
Cheers,
Thank you Adam!
It works perfectly!
Admaiora
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Adam,
I tried to modify your code to make it work for our stuff and somewhere something is lost. When the code runs the border that is already there gets deleted but no new border gets added. When I run the rule a second time the right border gets added. If you could help I would apprecaite it.
Thanks,
Max
Sub Main() Dim cd cd = ThisApplication.CommandManager.ControlDefinitions("DrawingBorderInsertNoDlgCtxCmd") Dim bp bp = ThisApplication.ActiveDocument.BrowserPanes("DlHierarchy") Dim node If ActiveSheet.Size = "A3" Then node = FindBorderNode("A3 Border", bp.TopNode.BrowserNodes) ElseIf ActiveSheet.Size = "A2" Then node = FindBorderNode("A2 Border", bp.TopNode.BrowserNodes) ElseIf ActiveSheet.Size = "A1" Then node = FindBorderNode("A1 Border", bp.TopNode.BrowserNodes) ElseIf ActiveSheet.Size = "A0" Then node = FindBorderNode("A0 Border", bp.TopNode.BrowserNodes) End If If Not ThisDoc.Document.ActiveSheet.Border Is Nothing Then ThisDoc.Document.ActiveSheet.Border.Delete End If node.DoSelect cd.Execute2 (True) End Sub Function FindBorderNode(name, nodes) Dim node For Each node In nodes If name = node.BrowserNodeDefinition.Label Then FindBorderNode = node Exit Function End If FindBorderNode = FindBorderNode(name, node.BrowserNodes) If Not FindBorderNode Is Nothing Then Exit Function End If Next End Function
Sorry, but I could not reproduce the issue in Inventor 2015.
What version are you using?
Not sure how the behaviour you described could happen without any error popping up.
You could try to track what your code is doing like this:
http://adndevblog.typepad.com/manufacturing/2014/08/debug-ilogic.html
You could also test how the same thing behaves from VBA, where you could also debug into the code seeing it execute line by line.
Adam,
I'm using 2015 SP1 Update 3 with Windows 7 64bit.
I have never seen anything like this before. I have the code tied to the before save trigger and when I go to save it gives me the following Debug:
[7340] iLogic: 'Main' Start Rule
[7340] iLogic: 'cd' Updated
[7340] iLogic: 'bp' Updated
[7340] iLogic: 'If' Entered A3
[7340] iLogic: 'FindBorderNode' Start Rule
[7340] iLogic: 'For Each' Started
[7340] iLogic: 'FindBorderNode' Start Rule
[7340] iLogic: 'For Each' Started
[7340] iLogic: 'FindBorderNode' Start Rule
[7340] iLogic: 'For Each' Started
[7340] iLogic: 'FindBorderNode' Start Rule
[7340] iLogic: 'For Each' Started
[7340] iLogic: 'FindBorderNode' Start Rule
[7340] iLogic: 'For Each' Started
[7340] iLogic: 'IF' Started
[7340] iLogic: 'FindBorderNode' End Function
[7340] iLogic: 'FindBorderNode' Is Nothing End Function
[7340] iLogic: 'FindBorderNode' Is Nothing End Function
[7340] iLogic: 'node' Updated w/ A3
[7340] iLogic: 'If' Ended
[7340] iLogic: 'If' Entered Nothing Border
[7340] iLogic: 'Border' Deleted
[7340] iLogic: 'If' Ended Nothing Border
[7340] iLogic: 'node' deselect
[7340] iLogic: 'cd.Execute2' Performed
[7340] iLogic: 'Main' Ended
[7364] DUMCEF: Previous user mode exception policy: 0x00000000
[7364] DUMCEF: New user mode exception policy: 0x00000000
[7364] AcDb.dll Terminating!
[7364] acfirst.dll Terminating!
I can, however manually run the rule and have it update to the right border. I can then also change the paper size and manually run the rule and have it populate correctly. It seems to be something with the trigger.
Also here is the modified code with the trace commands:
Sub Main() Trace.WriteLine("iLogic: 'Main' Start Rule") Dim cd cd = ThisApplication.CommandManager.ControlDefinitions("DrawingBorderInsertNoDlgCtxCmd") Trace.WriteLine("iLogic: 'cd' Updated") Dim bp bp = ThisApplication.ActiveDocument.BrowserPanes("DlHierarchy") Trace.WriteLine("iLogic: 'bp' Updated") Dim node If ActiveSheet.Size = "A3" Then Trace.WriteLine("iLogic: 'If' Entered A3") node = FindBorderNode("A3 Border", bp.TopNode.BrowserNodes) Trace.WriteLine("iLogic: 'node' Updated w/ A3") ElseIf ActiveSheet.Size = "A2" Then Trace.WriteLine("iLogic: 'If' Entered A3") node = FindBorderNode("A2 Border", bp.TopNode.BrowserNodes) Trace.WriteLine("iLogic: 'node' Updated w/ A2") ElseIf ActiveSheet.Size = "A1" Then Trace.WriteLine("iLogic: 'If' Entered A3") node = FindBorderNode("A1 Border", bp.TopNode.BrowserNodes) Trace.WriteLine("iLogic: 'node' Updated w/ A1") ElseIf ActiveSheet.Size = "A0" Then Trace.WriteLine("iLogic: 'If' Entered A3") node = FindBorderNode("A0 Border", bp.TopNode.BrowserNodes) Trace.WriteLine("iLogic: 'node' Updated w/ A0") End If Trace.WriteLine("iLogic: 'If' Ended") If Not ThisDoc.Document.ActiveSheet.Border Is Nothing Then Trace.WriteLine("iLogic: 'If' Entered Nothing Border") ThisDoc.Document.ActiveSheet.Border.Delete Trace.WriteLine("iLogic: 'Border' Deleted") End If Trace.WriteLine("iLogic: 'If' Ended Nothing Border") node.DoSelect Trace.WriteLine("iLogic: 'node' deselect") cd.Execute2 (True) Trace.WriteLine("iLogic: 'cd.Execute2' Performed") Trace.WriteLine("iLogic: 'Main' Ended") End Sub Function FindBorderNode(name, nodes) Trace.WriteLine("iLogic: 'FindBorderNode' Start Rule") Dim node For Each node In nodes Trace.WriteLine("iLogic: 'For Each' Started") If name = node.BrowserNodeDefinition.Label Then Trace.WriteLine("iLogic: 'IF' Started") FindBorderNode = node Trace.WriteLine("iLogic: 'FindBorderNode' End Function") Exit Function End If FindBorderNode = FindBorderNode(name, node.BrowserNodes) If Not FindBorderNode Is Nothing Then Trace.WriteLine("iLogic: 'FindBorderNode' Is Nothing End Function") Exit Function End If Next End Function
I've never used that tool before so I may have the commands in the wrong spot or not enough of them.
Thanks,
Max
Does the save happen through a dialog?: e.g. when saving for the first time or saving the doc with a different name
Because if there is something in the UI open, then I can imagine that the selection cannot not take place in the browser tree, so executing "DrawingBorderInsertNoDlgCtxCmd" will do nothing.
Also don't forget that running commands directly is just a workaround, not a robust solution.
Shame Sheet.AddBorder() does not work properly with zoned borders 😕
There isn't a save dialog that opens. It's a file I've saved a few hundred times (Ctrl+S is a habit I picked up after the first few crashes).
Yes, as I said executing control definitions is not robust, and it seems trying to do that from an event is one way to prove that :-s
If you are willing to create an add-in instead, there you would have more options. E.g. there you could even cancel the save or close if not everything is as it should be in the drawing, then bring up a dialog listing the issues offering the user to fix them on the click of a button. Then you would be outside the event handler execution and probably it should all work.
Actually, the form part could be done in iLogic as well. So in one rule you could check the drawing (that is run from "before save" event) and if there are issues it would bring up a form which can run another rule that would do the actual work of changing the border.
In this example first the form pops up because "Mine" border is not used. Then user clicks "Fix them", the border is changed, and during the next save no form pops up, because all is fine:
http://www.screencast.com/t/sPoX2Vl6jvx
I don't think there is a way however to change the border before the document save takes place.
The real solution for you would be if AddBorder() functioned as it should, but not not sure when that will happen.
In the meantime I cannot think of a way to make the border change fully event driven, not requiring the user to explicitly run your rule (e.g. from an iLogic form).