Global Form usage across multiple open documents

Global Form usage across multiple open documents

Ktomberlin
Advocate Advocate
1,222 Views
5 Replies
Message 1 of 6

Global Form usage across multiple open documents

Ktomberlin
Advocate
Advocate

I'm hoping someone has found a solution to this with global forms. I've got a couple ilogic that do different tasks when working with drawings, I've added them to a global form. When you activate the global form. The form stays linked to the document that was active when you opened the form and doesn't change when you change to a new document. For example , I have an external rule for editing the title and stock number. It appears to be the same issue described on this post . How can i force the form to change what file it is linked to?  I did try to update the rule to use 

 

ThisApplication.ActiveDocument
or
ThisDoc.Path

 but i get errors due to activeDocument or Patht not being a member of object i'm trying to reference.  I did find some code when in an ilogic rule that does work.  Just brining up the checkin dialog.  Anyone have a form work around, or a change to the title & stock that will allow the form to change focus?

 

Code Snippet that works.

ThisApplication.ActiveDocument.Save
 ThisApplication.CommandManager.ControlDefinitions.Item("VaultCheckinTop").Execute2(False)

Code that doesn't work.

'Inputing New Title & Stock Number'
'doc = ThisDoc.ModelDocument
doc = ThisDoc.Document
Dim MyTitle As String
Dim MyStock As String
If doc.DocumentType = kDrawingDocumentObject Then
    Goto Drawing
'Else If doc.DocumentType = kPartDocumentObject Then
Else
    Goto Other    
End If
Return
Drawing:
    modelName = IO.Path.GetFileName(ThisDoc.ModelDocument.FullFileName) 
    MyTitle = iProperties.Value(modelName, "Summary", "Title")
    MyStock = iProperties.Value(modelName, "Project", "Stock Number")
    MyTitle  = InputBox("Enter New Title.",  "Description Needs to be Changed!",  MyTitle)
    MyStock  = InputBox("Enter New Stock Number.",  "Description Needs to be Changed!",  MyStock)
    If MyTitle <> Nullstring
        iProperties.Value(modelName, "Summary", "Title") = MyTitle
    End If
    If MyStock <> Nullstring
    iProperties.Value(modelName, "Project", "Stock Number") = MyStock
    End If
    doc.Update()
    Goto Ending
Other:
    MyTitle = iProperties.Value("Summary", "Title")
    MyStock = iProperties.Value("Project", "Stock Number")
    MyTitle  = InputBox("Enter New Title.",  "Description Needs to be Changed!",  MyTitle)
    MyStock  = InputBox("Enter New Stock Number.",  "Description Needs to be Changed!",  MyStock)
    If MyTitle <> Nullstring
        iProperties.Value("Summary", "Title") = MyTitle
    End If
    If MyStock <> Nullstring
        iProperties.Value("Project", "Stock Number") = MyStock
    End If
    Goto Ending
Return
Ending:Return
'
'update the file'ThisApplication.ActiveView.Update()'InventorVb.DocumentUpdate(modelName)
InventorVb.DocumentUpdate()
iLogicVb.UpdateWhenDone = True

 

0 Likes
Accepted solutions (1)
1,223 Views
5 Replies
Replies (5)
Message 2 of 6

rjay75
Collaborator
Collaborator

The iProperties command you are using is for use on assembly documents. While in the drawing environment you have to reference the drawing model properties the long way.

 

Notice that mDoc is set to the document on the current sheet first.

 

SyntaxEditor Code Snippet

'Inputing New Title & Stock Number'
'doc = ThisDoc.ModelDocument
doc = ThisDoc.Document
Dim MyTitle As String
Dim MyStock As String
If doc.DocumentType = kDrawingDocumentObject Then
    Goto Drawing
'Else If doc.DocumentType = kPartDocumentObject Then
Else
    Goto Other    
End If
Return
Drawing:
    If ActiveSheet.Sheet.DrawingViews.Count > 0 Then
        'Get Referenced Document on first view of sheet
        Dim mDoc As Document  = ActiveSheet.Sheet.DrawingViews(1).ReferencedDocumentDescriptor.ReferencedDocument
        MyTitle = mDoc.PropertySets.Item("Summary Information").Item("Title").Value
        MyStock = mDoc.PropertySets.Item("Design Tracking Properties").Item("Stock Number").Value
        MyTitle  = InputBox("Enter New Title.",  "Description Needs to be Changed!",  MyTitle)
        MyStock  = InputBox("Enter New Stock Number.",  "Description Needs to be Changed!",  MyStock)
        If MyTitle <> Nullstring
            mDoc.PropertySets.Item("Summary Information").Item("Title").Value = MyTitle
        End If
        If MyStock <> Nullstring
            mDoc.PropertySets.Item("Design Tracking Properties").Item("Stock Number").Value = MyStock
        End If
        doc.Update()
    End If
    Goto Ending
Other:
    MyTitle = iProperties.Value("Summary", "Title")
    MyStock = iProperties.Value("Project", "Stock Number")
    MyTitle  = InputBox("Enter New Title.",  "Description Needs to be Changed!",  MyTitle)
    MyStock  = InputBox("Enter New Stock Number.",  "Description Needs to be Changed!",  MyStock)
    If MyTitle <> Nullstring
        iProperties.Value("Summary", "Title") = MyTitle
    End If
    If MyStock <> Nullstring
        iProperties.Value("Project", "Stock Number") = MyStock
    End If
    Goto Ending
Return
Ending:Return
'
'update the file'ThisApplication.ActiveView.Update()'InventorVb.DocumentUpdate(modelName)
InventorVb.DocumentUpdate()
iLogicVb.UpdateWhenDone = True
Message 3 of 6

Ktomberlin
Advocate
Advocate

Here is a screencast to demonstrate the issue. I just picked two random parts I had in my imported parts folded. I took rjay75's code saved it as a External Rule. My rule and his both function when run on the drawings independently. Now add the rule to a global form and open the form when one drawing is the active document, then switch to the other document. This should better illustrate what I'm trying to solve. Thank you for your suggestion and efforts.

 

The ScreenCast may not appear so here is the link.

0 Likes
Message 4 of 6

MjDeck
Autodesk
Autodesk
Accepted solution

Hi Ktomberlin,

As you found, a global form is tied to the document from which it was launched. In a future version, we could add an option to make it track the active document. For now, the workaround is to use ThisApplication.ActiveDocument. This will work for rules run from the form. But in addition to that, you will probably need to change other things. Most iLogic functions use the document from which the rule was launched (ThisDoc.Document) internally. To get away from that limitation, you need to use Inventor API functions directly. rjay75's version of your rule did that for the model document referenced by the drawing. But similar changes are required when the rule is running directly in a model document. I started from his version and made more changes. See the attached text file. It will always operate on the active document when launched from a form.


Mike Deck
Software Developer
Autodesk, Inc.

Message 5 of 6

Ktomberlin
Advocate
Advocate

Also it should be noted (thanks you Mike), 

 

 

oDocument = ThisApplication.ActiveDocument

 

Dim oPath As String = IO.Path.GetDirectoryName(oDocument.FullFileName)

Dim oFileName As String = IO.Path.GetFileNameWithoutExtension(oDocument.FullFileName)

 

Make sure to replace all occurrences of ThisDoc.FileName(False) with oFileName.

 

This additional code will help convert other ilogic to move to the activeDocument.

 

 

0 Likes
Message 6 of 6

DRoam
Mentor
Mentor

@MjDeck wrote:

In a future version, we could add an option to make it track the active document.


 

FYI for anyone who comes on this thread, I created an Idea for this so it can be tracked as an enhancement request. You can add your vote here: iLogic: Option to close or refresh Global Forms when switching documents.

 

Here's a photoshopped image I posted of what it might look like:

 

Global Form Switching Options.png