Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

How to open all ipt. files in directory

Preston_Reed
Advocate

How to open all ipt. files in directory

Preston_Reed
Advocate
Advocate

Hello, I am currently working on some drawing automation and need help.  I have figured out how to make a new sheet, place multiple views, size them and orientate them.  The issue I am having now is scaling this up to do it for every piece part in my part folder.  Is there a way to loop through my part folder so it will do this for every piece part and avoid assembly files??   And any suggestion on how to properly loop this would be greatly appreciated.  I'm new to iLogic and coding still, thankyou.  

 

Here is what my code looks like so far

 

Sub Main()
	PlaceView
	DrawingViewScale
	DrawingViewScale2
	DrawingViewScale3
	Page1
End Sub

Sub PlaceView()
'Set a reference to the drawing document.
'This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument

'Set a reference to the sheet format named "Custom D, 5 View"
Dim oFormat As SheetFormat
Try
oFormat = oDrawDoc.SheetFormats.Item("Custom D, 5 View")
Catch
MessageBox.Show("Error: C size, 4 view might not exist.", "iLogic")
Return
End Try

'Open the model document invisible
Dim oModel As Document
oModel = ThisApplication.Documents.Open("X:\My Documents\LOCAL PROJECTS\CONFIGURATORS\SC-SERIES_U20D\Parts\RIGHT.ipt", False)

'Create a new sheet based on the sheet format using the specified model
Dim oSheet As Sheet
oSheet = oDrawDoc.Sheets.AddUsingSheetFormat(oFormat, oModel)

End Sub

Sub DrawingViewScale()
    Dim oDwgDoc As Document
    oDwgDoc = ThisApplication.ActiveDocument 'assuming you are running it from the current document, otherwise reference the correct file here.
    Dim oSheet As Sheet
    oSheet = oDwgDoc.Sheets.Item(2) 'assuming we are working on the first sheet
    
    Dim oView As DrawingView
    oView = oSheet.DrawingViews.Item("1") 'assuming the base view is the first view
    oView.ScaleString = ".85:1"
    
    Dim ViewWide As Double
    ViewWide = 5 'change this to how wide you want your view to be
    
    Dim DrawingScale As String
    DrawingScale = CStr(ViewWide / oView.Width)

    oView.ScaleString = DrawingScale
	
End Sub

Sub DrawingViewScale2()
    Dim oDwgDoc As Document
    oDwgDoc = ThisApplication.ActiveDocument 'assuming you are running it from the current document, otherwise reference the correct file here.
    Dim oSheet As Sheet
    oSheet = oDwgDoc.Sheets.Item(2) 'assuming we are working on the first sheet
    
    Dim oView As DrawingView
    oView = oSheet.DrawingViews.Item("2") 'assuming the base view is the first view
    oView.ScaleString = ".75:1"
    
    Dim ViewWide As Double
    ViewWide = 5 'change this to how wide you want your view to be
    
    Dim DrawingScale As String
    DrawingScale = CStr(ViewWide / oView.Width)

    oView.ScaleString = DrawingScale
	
End Sub

Sub DrawingViewScale3()
    Dim oDwgDoc As Document
    oDwgDoc = ThisApplication.ActiveDocument 'assuming you are running it from the current document, otherwise reference the correct file here.
    Dim oSheet As Sheet
    oSheet = oDwgDoc.Sheets.Item(2) 'assuming we are working on the first sheet
    
    Dim oView As DrawingView
    oView = oSheet.DrawingViews.Item("3") 'assuming the base view is the first view
    oView.ScaleString = ".75:1"
    
    Dim ViewWide As Double
    ViewWide = 5 'change this to how wide you want your view to be
    
    Dim DrawingScale As String
    DrawingScale = CStr(ViewWide / oView.Width)

    oView.ScaleString = DrawingScale
	
End Sub

 

0 Likes
Reply
545 Views
1 Reply
Reply (1)

A.Acheson
Mentor
Mentor

You will need to use objects and methods outside of inventor to process the files in the folder. Here is a starting point, if you look at this link and find the sub routine Public Shared Sub ProcessDirectory(ByVal targetDirectory As String).

 

This method can be accessed in VB.Net through
System.IO.Directory.GetFiles.......

 

You can remove the recursive aspect of this routine to loop through folders and use the rest. Then check the extension of the file by Path.GetExtension.

 

Alternatively add a search criteria to get files 

 Directory.GetFiles(path, "*.txt", SearchOption.AllDirectories)

 

Once you have an ipt then you can call the drawing  sub routine and pass in the path as an argument.  

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes