Ilogic - get idw iproperties from assembly occurences without opening idw

Ilogic - get idw iproperties from assembly occurences without opening idw

Anonymous
Not applicable
845 Views
1 Reply
Message 1 of 2

Ilogic - get idw iproperties from assembly occurences without opening idw

Anonymous
Not applicable

Good afternoon,

 

 

I have some ilogic that I have been tweeking. I open an assembly, then run the rule and it looks for all the IDWs of all the component occurences in the assembly and then it opens each IDW of the occurences, grabs a custom iproperty and writes it to a cell in excel and then closes the drawing.

 

I am wondering if there is a way to access the iproperties of the IDW without opening it. I am currently using:

 

idwPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName) - 3) & "idw"
oDrawDoc = ThisApplication.Documents.Open(idwPathName, True)
oDWGNo = oDrawDoc.PropertySets.Item("Inventor User Defined Properties").Item("Drawing Number").Value

All my assemblies and parts have the same filename and location as their respective idw files.

 

Here is the whole code in its entirerty: 

 

SyntaxEditor Code Snippet

'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

oPath = ThisDoc.Path
oPath = Right(oPath, Len(oPath) - InStrRev(oPath, "Vault Working Folder")-19)




oPath = "\\ODESSA-SRV2\CAD-Data\Design PDFs" & oPath & "\"


'get PDF target folder path
oFolder = oPath 



Dim sToday As String
sToday = Now

'sToday = Left(sToday, Len(sToday) - InStrRev(sToday, " "))
sToday = Left(sToday, InStrRev(sToday, " ")-1)
sToday = Left(sToday, InStrRev(sToday, " ")-1)


sToday = (sToday).Replace("/", "-")



oExcelName = oFolder & oAsmName & " - " & sToday & ".xlsx"




'Check for the PDF folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
    System.IO.Directory.CreateDirectory(oFolder)
End If
'- - - - - - - - - - - - -'Shell("explorer.exe " & oFolder,vbNormalFocus)'- - - - - - - - - - - - -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

'If OpenOrPDF = True


'define Excel Application object
excelApp = CreateObject("Excel.Application")
'set Excel to run visibly, change to false if you want to run it invisibly
excelApp.Visible = True
'suppress prompts (such as the compatibility checker)
excelApp.DisplayAlerts = False
'check for existing file 
If Dir(oExcelName) <> "" Then
'workbook exists, open it
excelWorkbook = excelApp.Workbooks.Open(oExcelName)
ExcelSheet = ExcelWorkbook.Worksheets(1)
Else
'workbook does NOT exist, so create a new one
excelWorkbook = excelApp.Workbooks.Add
End If

    
'Insert data into Excel.
With excelApp    .Range("A1").Select    .ActiveCell.FormulaR1C1 = "DRAWING NUMBER"
End With 
With excelApp    .Range("B1").Select    .ActiveCell.FormulaR1C1 = "PDF PATH"
End With 

oRow = 2


PDFPath = "\\ODESSA-SRV2\CAD-Data\1_ENGINEERING\DRAWING FILES\"

For Each oRefDoc In oRefDocs
On Error Resume Next


idwPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName) - 3) & "idw"
oDrawDoc = ThisApplication.Documents.Open(idwPathName, True)

oFileName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName) -3)
 ' if PDF exists and is open or read only, resume next
 
 
oDWGNo = ""
oDWGNo = oDrawDoc.PropertySets.Item("Inventor User Defined Properties").Item("Drawing Number").Value

If oDWGNo = ""
Resume Next
Else


'Insert data into Excel.
With excelApp    .Range("A" & oRow).Select
    '.ActiveCell.FormulaR1C1 = PDFPath & oDWGNo & ".pdf"
    .ActiveCell.FormulaR1C1 = oDWGNo 
End With 
'
'oHyperRow = "A" & oRow

With excelApp    .Range("B" & oRow).Select    .ActiveCell.FormulaR1C1 = PDFPath & oDWGNo & ".pdf"
End With 

oRow = oRow + 1    

'set all of the columns to autofit
excelApp.Columns.AutoFit   
'save the file
excelWorkbook.SaveAs (oExcelName)


oDrawDoc.Close
            
End If

Next
'- - - - - - - - - - - - -

 

 

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

Vladimir.Ananyev
Alumni
Alumni

Running iLogic rule you have to open IDW to access their iProperties. You may speed up this process if the rule opens the drawing document invisibly:

 

oDrawDoc = ThisApplication.Documents.Open(idwPathName, False)

 

Alternative method is to use Apprentice but it could not be used from Inventor Add-Ins (and from iLogic as well):  http://modthemachine.typepad.com/my_weblog/2010/03/iproperties-without-inventor-apprentice.html

You may develop standalone EXE to fill the excel sheet with iProperties or you may call Apprentice from the Excel VBA macros.


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

0 Likes