Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Sheet Size iLogic Problem

22 REPLIES 22
SOLVED
Reply
Message 1 of 23
drguitarum2005
2649 Views, 22 Replies

Sheet Size iLogic Problem

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

22 REPLIES 22
Message 2 of 23

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?

Message 3 of 23
adam.nagy
in reply to: drguitarum2005

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,



Adam Nagy
Autodesk Platform Services
Message 4 of 23
aguitton116
in reply to: adam.nagy

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

 

 

Message 5 of 23
jdkriek
in reply to: aguitton116

... or just create a custom border for each size and replace it on the sheet.

 

That's what I've been doing for 3 years now. And it's 3 lines of code in VBA, 2 in iLogic.

Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


Message 6 of 23
aguitton116
in reply to: jdkriek

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.

Message 7 of 23
adam.nagy
in reply to: aguitton116

Hi,

 

Do you still need help, or you're OK now? 🙂

 

Cheers,



Adam Nagy
Autodesk Platform Services
Message 8 of 23
aguitton116
in reply to: adam.nagy

In my case it's OK.

Message 9 of 23
johnster100
in reply to: adam.nagy

Hi,

I'm still using Inventor 2013 and have been having the same problem. Was a simpler solution ever found?

 

thanks,

John

Message 10 of 23
admaiora
in reply to: johnster100

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.

 

w.gif

 

 

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.

_____________________________________________________________________________
Facebook | Twitter | Youtube

Message 11 of 23
admaiora
in reply to: admaiora

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.

_____________________________________________________________________________
Facebook | Twitter | Youtube

Message 12 of 23
adam.nagy
in reply to: admaiora

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,



Adam Nagy
Autodesk Platform Services
Message 13 of 23
admaiora
in reply to: adam.nagy

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.

_____________________________________________________________________________
Facebook | Twitter | Youtube

Message 14 of 23
Anonymous
in reply to: admaiora

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
Message 15 of 23
adam.nagy
in reply to: Anonymous

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 Nagy
Autodesk Platform Services
Message 16 of 23
Anonymous
in reply to: adam.nagy

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

Message 17 of 23
adam.nagy
in reply to: Anonymous

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 😕      



Adam Nagy
Autodesk Platform Services
Message 18 of 23
Anonymous
in reply to: adam.nagy

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).

Message 19 of 23
adam.nagy
in reply to: Anonymous

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).



Adam Nagy
Autodesk Platform Services
Message 20 of 23
Anonymous
in reply to: adam.nagy

Thanks Adam,

It's unfortunate that, that is the case.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report