Check out idw from Assembly

Check out idw from Assembly

jzcrouse
Enthusiast Enthusiast
372 Views
1 Reply
Message 1 of 2

Check out idw from Assembly

jzcrouse
Enthusiast
Enthusiast

I have a code to run through every part in a assembly, open the associated idw, run a rule and close. It works great most of the time however if a user does not check out a drawing it will error out. Usually inventor will prompt to check out a drawing but sometimes the prompt does not happen and i get an error. There is probably something wrong with those specific drawings since there is no prompt but I need a work around. I need to force the drawings to check out when or before they open. 

 

My thought would be to use the commandmanager command to check out but I cannot figure out how to run that in the drawing as the code errors out on the open command. "dwgdoc = ThisApplication.Documents.Open(Dwgname)"

 

Not sure if there is a way to open the document with options and check out that way

 

 

 

Imports System.IO.Path
Imports System.IO
Imports System.Collections
Imports System.Collections.ObjectModel

 


Private Sub Main()
Dim asmDoc As AssemblyDocument
If Not ThisApplication.ActiveDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then

MessageBox.Show("Rule must be ran in assembly")
GoTo Line2
End If
asmDoc = ThisDoc.Document


'initiate list to be used in sub

Dim needsdwg As New List(Of String)

' Call the function that traverses the assembly

Call Iterate( asmDoc.ComponentDefinition.Occurrences, 1, needsdwg)

Line2:

' Update the view.

End Sub

'passes a list of parameters and retains info between sub assemblies; byref passes actual parameter

Sub Iterate(ByRef Occurrences As ComponentOccurrences, ByVal Level As Integer, ByRef needsdwg As List(Of String))

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisDoc.Document.ComponentDefinition
Dim Parentasm As String = ThisAssembly.Document.DisplayName
Dim currentasm As String
Dim oPart As ComponentOccurrence
Dim oPartpath As String
Dim FNamePos As Long
Dim Part_Name As String
'counts the number of occurances in assembly
Dim updated As New List(Of String)

Dim count As Integer
count = ThisAssembly.Components.Count

'''Iterate through part occurrences in assembly
auto = iLogicVb.Automation

For Each oPart In Occurrences

Dim oFileName As String = oPart.Definition.Document.FullFileName
'Check to see if occurance is a Part
Dim partnumber As String = iProperties.Value(oPart.Name, "Project", "Part Number")

If needsdwg.Contains(partnumber)

GoTo line1
Else

End If
needsdwg.add(partnumber)
If oPart.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject Then


Dim oDoc As PartDocument = oPart.Definition.Document
Dim dtl As String = iProperties.Value(oPart.Name, "Custom", "ITS_DTL")
If dtl.Contains("Y") Then
FNamePos = InStrRev(oFileName, "\", -1)
Part_Name = Right(oFileName, Len(oFileName) -FNamePos)
oPartpath = Left(oFileName, Len(oFileName) -Len(Part_Name))



'sets full file name to search for, drawing must be in same folder as part.

Dim Dwgname As String = oPartpath & "\" & partnumber & ".idw"



'check to see if drawing file exists
If System.IO.File.Exists(Dwgname) = True Then

Dim dwgdoc As DrawingDocument

dwgdoc = ThisApplication.Documents.Open(Dwgname)

auto.RunExternalRule(dwgdoc, "UPDATE_DRAWING_TITLEBLOCK")


dwgdoc.Save
dwgdoc.Close

Else
'Adds part names without a detail to list

' needsdwg.add(New dwgs(partnumber), partnumber)


End If

Else

End If


'ignore bolted assemblies.

ElseIf partnumber.Contains("Bolted")=True Then
GoTo line1

'recursively call sub to traverse through occurance if it is a subassembly
ElseIf oPart.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then


Call Iterate( oPart.SubOccurrences, 1, needsdwg)


End If
line1 :

Next
'finds if part being processes is in a sub or parent assembly

 


line2 :



End Sub

 

0 Likes
373 Views
1 Reply
Reply (1)
Message 2 of 2

JelteDeJong
Mentor
Mentor

Checking out (and in) files is difficult in iLogic. I have seen posts in the past that did it by communicating  with the vault server. It has always been to dificult for me. But i understand that you only have occasionally have problems. There for you might consider to skip those problem files and just show a message box. you could do it like this:

If System.IO.File.Exists(Dwgname) = True Then
    Dim dwgdoc As DrawingDocument
    Try
        dwgdoc = ThisApplication.Documents.Open(Dwgname)
        auto.RunExternalRule(dwgdoc, "UPDATE_DRAWING_TITLEBLOCK")

        dwgdoc.Save()
        dwgdoc.Close()
    Catch ex As Exception
        MsgBox("Exception was thrown while updating file: " & Dwgname)
    End Try
Else
    'Adds part names without a detail to list
    ' needsdwg.add(New dwgs(partnumber), partnumber)
End If

Jelte de Jong
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.

EESignature


Blog: hjalte.nl - github.com

0 Likes