Update drawing with iLogic from Assembly file

Update drawing with iLogic from Assembly file

Jesper_S
Collaborator Collaborator
1,746 Views
4 Replies
Message 1 of 5

Update drawing with iLogic from Assembly file

Jesper_S
Collaborator
Collaborator

Hi.

 

Trying to write a iLogic code that is run from the assembly file, that opens all related drawings, 

update them then ask if you want to proceed to the next drawing, save and close it.

But im not sure if i got the code right. The thing im not sure with is the Update bit of the code. (Red text in the code below)

First iLogic code i have written by my self. 

 

'define the active document As an Assembly file
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) -4)

'check that the active document is an assembly file
If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
MessageBox.Show("Please run this rule from the assembly file.", "iLogic")
Exit Sub
End If

'- - - - - - - - - - - - -Component Drawings - - - - - - - - - - - -'look at the files referenced by the assembly
Dim oRefDocs As DocumentsEnumerator
oRefDocs = oAsmDoc.AllReferencedDocuments
Dim oRefDoc As Document

'work the the drawing files for the referenced models'this expects that the model has a drawing of the same path and name
For Each oRefDoc In oRefDocs
idwPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName) - 3) & "idw"
'check to see that the model has a drawing of the same path and name
If(System.IO.File.Exists(idwPathName)) Then
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.Documents.Open(idwPathName, True)
InventorVb.DocumentUpdate()


    question = MessageBox.Show("Continue with next Drawing?", "Drawing Looks Good?",MessageBoxButtons.YesNo,MessageBoxIcon.Question)

    If question = vbYes Then
    'Save
    oDrawDoc.Save        
    'close the file
    oDrawDoc.Close

    Else
    Return
    End If

Else
End If

 

 Some help would be appreciated. 

 

Thanks


//Jesper

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
0 Likes
Accepted solutions (1)
1,747 Views
4 Replies
Replies (4)
Message 2 of 5

Owner2229
Advisor
Advisor
Accepted solution

Hi, did you try this one?

 

oDrawDoc.Update

 

Here it is along with some other changes:

 

' Check that the active document is an assembly file
If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
    MessageBox.Show("Please run this rule from the assembly file.", "iLogic")
    Exit Sub
End If

' Define the active document As an Assembly file
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
Dim oAsmName As String
oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) -4)

'- - - - - - - - - - - - -Component Drawings - - - - - - - - - - - -
' Look at the files referenced by the assembly Dim oRefDocs As DocumentsEnumerator oRefDocs = oAsmDoc.AllReferencedDocuments Dim oRefDoc As Document ' Work the the drawing files for the referenced models
' This expects that the model has a drawing of the same path and name For Each oRefDoc In oRefDocs idwPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName) - 3) & "idw" ' Check to see that the model has a drawing of the same path and name If(System.IO.File.Exists(idwPathName)) Then Dim oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.Documents.Open(idwPathName, True) oDrawDoc.Update Q1 = MessageBox.Show("Do you want to save this drawing?", "Drawing Looks Good?",MessageBoxButtons.YesNo,MessageBoxIcon.Question) If Q1 = vbYes Then ' Save oDrawDoc.Save
End If ' Close the file
oDrawDoc.Close
Q2 = MessageBox.Show("Continue with next Drawing?", "Continue?",MessageBoxButtons.YesNo,MessageBoxIcon.Question) If Q2 = vbNo Then
Exit For End If
End If
Next

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 3 of 5

Jesper_S
Collaborator
Collaborator

Hi.

 

Nope, not that one. Thanks Smiley Happy

 

Got a question, does this code go throuh ALL referenced documents? 

I mean all levels of the assemby, sub assy and so.

 

/Thanks


//Jesper

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
0 Likes
Message 4 of 5

Owner2229
Advisor
Advisor

Hi, this one goes through "AllReferencedDocuments", so yea, it should go through all levels of the assembly.

The one that runs only for the top level of the assembly is the "ComponentOccurence".

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 5 of 5

gma
Advocate
Advocate

Hi,

 

Is it possible to make the rule so it not will check drawings at released files?

 

 

0 Likes