Create a drawing list Excel

Create a drawing list Excel

Anonymous
Not applicable
1,401 Views
9 Replies
Message 1 of 10

Create a drawing list Excel

Anonymous
Not applicable

Hello,

 

We have all our drawing in a folder "drawings" per project file. Is it possible to have a code running and listing all these drawings in a excell as a drawing list? I would need the following custom iproperties in it: ACME_DRAWING, ACME_DESCRIPTION and the regular property PARTNUMBER.

 

Maybe something simular exist already?

Many Thanks!

0 Likes
Accepted solutions (1)
1,402 Views
9 Replies
Replies (9)
Message 2 of 10

Sergio.D.Suárez
Mentor
Mentor

Hello, try to configure this rule, use an excel template, you must correctly place the template path.
Then you must specify the name of the new excel file where you will save the list, as well as the path where the file will be saved.

'Example - Execute in assembly or part document
Dim Dirxlsx As String = "E:\Libro1.xlsx"    ''' Specify the excel template path
Dim osheet As String = "Sheet1"              ''' Specify the excel template sheet

Dim oExcelName As String = "Drawing_List" & ".xlsx"   ''' Specify the excel file name to save list
Dim processPath As String  = ThisDoc.Path     ''' "D:\Inventor\Planos en Inventor"   '''Specify the path of the find folder

'Open excel application
xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
xlWorkbook = xlApp.Workbooks.Open(Dirxlsx)
xlWorksheet = xlWorkbook.Worksheets.Item(osheet)

Dim row As Integer
row = 2                 ''' Indicate from which row the copying will start to excel


Dim drawings () As String = System.IO.Directory.GetFiles(processPath,"*.idw",System.IO.SearchOption.AllDirectories) 
	
For Each drawing As String In drawings 
 On Error Resume Next
	Dim oDoc As Document = ThisApplication.Documents.Open(drawing, False)
		
	xlWorksheet.Range("A" & row).Value = oDoc.DisplayName
	xlWorksheet.Range("B" & row).Value = oDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
	xlWorksheet.Range("C" & row).Value = oDoc.PropertySets.Item("Inventor User Defined Properties").Item("ACME_DRAWING").Value
	xlWorksheet.Range("D" & row).Value = oDoc.PropertySets.Item("Inventor User Defined Properties").Item("ACME_DESCRIPTION").Value	
	
	oDoc.Close
	
	row=row+1
	
Next

xlWorksheet.Columns("A:Z").AutoFit

MessageBox.Show(oExcelName , "Export to")
xlWorkBook.SaveAs(ThisDoc.Path & "\" & oExcelName)' The excel file will be saved in the location of the assembly file
xlWorkbook.Close(True)
xlApp.Quit

 I hope it helps you solve your problem.


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes
Message 3 of 10

Anonymous
Not applicable

Hello thanks for the start, but I was thinking of looping through the drawing folder instdead of an assembly. There might be more assemblies in the project, but there is only 1 drawing folder with all the drawings in it.

(I might copy the models iproperties to the drawing iproperties if needed)

 

Projectpath\drawings\....

0 Likes
Message 4 of 10

Sergio.D.Suárez
Mentor
Mentor
Accepted solution

In the example I gave you, the assembly part or drawing is only to activate the rule, not to use it itself, what you need is to configure the rule, so that it looks in the folder requested all the drawings (I do not know which is the route of the folder that contains drawings)
This rule looks only for drawing files, it does not look for assembly files. and will return the properties of those drawings in an excel table.


You must change the line

Dim processPath As String = ThisDoc.Path

and place your path of drawing files, for example

Dim processPath As String = "D:\Inventor\Drawings Files"

 

'Example
Dim Dirxlsx As String = "E:\Libro1.xlsx"    ''' Specify the excel template path
Dim osheet As String = "Sheet1"              ''' Specify the excel template sheet

Dim oExcelName As String = "Drawing_List" & ".xlsx"   ''' Specify the excel file name to save list
Dim processPath As String  = ThisDoc.Path     ''' "D:\Inventor\Planos en Inventor"   '''Specify the path of the find folder

'Open excel application
xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
xlWorkbook = xlApp.Workbooks.Open(Dirxlsx)
xlWorksheet = xlWorkbook.Worksheets.Item(osheet)

Dim row As Integer
row = 2                 ''' Indicate from which row the copying will start to excel


Dim drawings () As String = System.IO.Directory.GetFiles(processPath,"*.idw",System.IO.SearchOption.AllDirectories) 
	
For Each drawing As String In drawings 
 On Error Resume Next
	Dim oDoc As Document = ThisApplication.Documents.Open(drawing, False)
		
	xlWorksheet.Range("A" & row).Value = oDoc.DisplayName
	xlWorksheet.Range("B" & row).Value = oDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
	xlWorksheet.Range("C" & row).Value = oDoc.PropertySets.Item("Inventor User Defined Properties").Item("ACME_DRAWING").Value
	xlWorksheet.Range("D" & row).Value = oDoc.PropertySets.Item("Inventor User Defined Properties").Item("ACME_DESCRIPTION").Value	
	
	oDoc.Close
	
	row=row+1
	
Next

xlWorksheet.Columns("A:Z").AutoFit

MessageBox.Show(oExcelName , "Export to")
xlWorkBook.SaveAs(processPath & "\" & oExcelName)
xlWorkbook.Close(True)
xlApp.Quit

 Excuse me if I have not been clear. regards


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes
Message 5 of 10

Anonymous
Not applicable

@Sergio.D.Suárez 

Thank you very much. Would it be difficult to change the way the iproperties are collected? I don't have the iproperties in my drawing, but only in the model that is used in the drawing...? My titleblocks also get filled in with the models iproperties.

0 Likes
Message 6 of 10

Sergio.D.Suárez
Mentor
Mentor

No, I think it's not very difficult once you open the drawing in false mode, you would have to access the specific view and then the view model
you must specify the sheet and the view where you want to reference (As you place a piece by plane there is no problem, I will put the number 1)

 

Dim oView As DrawingView
oView = oDoc.Sheets(1).DrawingViews.Item(1)  ' specify the sheet and the view where you want to reference 

oViewModelDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument ' Document reference of part or assembly in drawing view
oViewModelName = oView.ReferencedDocumentDescriptor.ReferencedDocument.DisplayName 'Document name of part or assembly in drawing view
ACME_DESCRIPTION= iProperties.Value(oViewModelName, "Custom", "ACME_DESCRIPTION")' Iproperty of part or assembly in drawing view

I hope it will be helpful for you to solve your problem

 


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes
Message 7 of 10

Anonymous
Not applicable

This should come inside the For each loop?

 

For Each drawing As String In drawings 
 On Error Resume Next
	Dim oDoc As Document = ThisApplication.Documents.Open(drawing, False)
	
	Dim oView As DrawingView
	oView = oDoc.Sheets(1).DrawingViews.Item(1)  ' specify the sheet and the view where you want to reference 

	oViewModelDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument ' Document reference of part or assembly in drawing view
	oViewModelName = oView.ReferencedDocumentDescriptor.ReferencedDocument.DisplayName 'Document name of part or assembly in drawing view
	PTN_DRAWING = iProperties.Value(oViewModelName, "Custom", "PTN_DRAWING")' Iproperty of part or assembly in drawing view		
	PTN_DESCRIPTION_NL= iProperties.Value(oViewModelName, "Custom", "PTN_DESCRIPTION_NL")' Iproperty of part or assembly in drawing view		
	
	xlWorksheet.Range("A" & row).Value = oDoc.DisplayName
	xlWorksheet.Range("B" & row).Value = oDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
	xlWorksheet.Range("C" & row).Value = oDoc.PropertySets.Item("Inventor User Defined Properties").Item("PTN_DRAWING").Value
	xlWorksheet.Range("D" & row).Value = oDoc.PropertySets.Item("Inventor User Defined Properties").Item("PTN_DESCRIPTION_NL").Value	
	
	oDoc.Close
	
	row=row+1
	
Next
0 Likes
Message 8 of 10

Sergio.D.Suárez
Mentor
Mentor
For Each drawing As String In drawings 
 On Error Resume Next
	Dim oDoc As Document = ThisApplication.Documents.Open(drawing, False)
	
	Dim oView As DrawingView
	oView = oDoc.Sheets(1).DrawingViews.Item(1)  ' specify the sheet and the view where you want to reference 

	oViewModelDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument ' Document reference of part or assembly in drawing view
	oViewModelName = oView.ReferencedDocumentDescriptor.ReferencedDocument.DisplayName 'Document name of part or assembly in drawing view
	PTN_DRAWING = iProperties.Value(oViewModelName, "Custom", "PTN_DRAWING")' Iproperty of part or assembly in drawing view		
	PTN_DESCRIPTION_NL= iProperties.Value(oViewModelName, "Custom", "PTN_DESCRIPTION_NL")' Iproperty of part or assembly in drawing view		
	
	xlWorksheet.Range("A" & Row).Value = oDoc.DisplayName
	xlWorksheet.Range("B" & Row).Value = oDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value ' Part number of drawing document
	xlWorksheet.Range("C" & Row).Value = PTN_DRAWING
	xlWorksheet.Range("D" & Row).Value = PTN_DESCRIPTION_NL	
	
	oDoc.Close
	
	Row=Row+1
	
Next

 I should try something like this, I have not tried it, I will never probe a view in false document opening mode
Note that the property of part number refers to the drawing file, if you need the property of the part or assembly, you should apply a criterion similar to the one described above.

Surely there must be alternative paths for what you are looking for, it occurred to me to go here, maybe some of the experts have a better solution to the problem described


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes
Message 9 of 10

Anonymous
Not applicable

After all, I don't think this is the good way (cause of false document open mode?) because other rules that are set to run on "document open", fail and are prohibiting this rule to run... it gives errors...

 

So if other suggestion pop up...?

0 Likes
Message 10 of 10

Sergio.D.Suárez
Mentor
Mentor

If you want to try not to open in false mode, try modifying this line, if the iproperties are from the drawing document, put false to not have the need to open it, now dealing with the iproperties of the view model, you may need to open each document normally and that the program then closes it alone

Dim oDoc As Document = ThisApplication.Documents.Open(drawing, True)

 


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes