Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ilogic - create drawing from part

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
liam.dewhurstNMKYG
1799 Views, 7 Replies

ilogic - create drawing from part

Hi Team,

 

The open drawing from part dialogue has now started digging down 5 layers deep in folders! Which now searches our entire projects folder for the drawing you haven't yet created (and locks up inventor for 10 minutes while it searches 40Gb...)

I found this code that checks in about 1 second for the drawing in the current folder which is fantastic

 

ThisApplication.Documents.Open(ThisDoc.PathAndFileName(True).Replace("ipt", "idw"))

 

However, I want to start the "create drawing" function if it doesn't find one. Currently it throws an error, so I think I can run a catch/throw function to insert a create drawing.

Does anyone know how to start the dialogue for create drawing? I've found automations (https://clintbrown.co.uk/2018/10/07/automatic-drawings-with-ilogic/)

but we have many different templates for customers so I don't want to automatically generate the drawing & place views etc.

I just want to open this dialogue here:

 

 

 

7 REPLIES 7
Message 2 of 8

Hi @liam.dewhurstNMKYG 

 

For the issue of the open dialog hanging up, please check this setting, in your project file... if it is not set to no, then setting to no might resolve this issue... I can't recall, but I remember having this issue in the past with that Open Drawing option.

 

See this link for more explination:

https://forums.autodesk.com/t5/inventor-forum/using-unique-file-names-option/m-p/6008909#M590217

 

Curtis_W_0-1622772343564.png

 

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

Message 3 of 8

As for creating a new drawing if the one isn't found, I'm not sure that we can access the create new view interfaces via automation, but something like this should get you started in creating the drawing.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

 

Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument

Try 
	ThisApplication.Documents.Open _
	(ThisDoc.PathAndFileName(True).Replace("ipt", "idw"))
	Return 'exit rule
Catch	
End Try

oNewDrawing = ThisDoc.ChangeExtension(".idw")


oTemplateFolder = ThisApplication.FileOptions.TemplatesPath
oTemplate = oTemplateFolder & "Standard.idw"

Dim oDrawingDoc As DrawingDocument 
oDrawingDoc = ThisApplication.Documents.Add _
(DocumentTypeEnum.kDrawingDocumentObject, oTemplate, True)

oDrawingDoc.Activate()
Dim oSheet As Sheet 
oSheet = oDrawingDoc.Sheets.Item(1)

Dim oPoint As Point2d
oPoint = ThisApplication.TransientGeometry.CreatePoint2d(10, 10)

Dim oView As DrawingView
oView = oSheet.DrawingViews.AddBaseView(oDoc, oPoint, 1, _
ViewOrientationTypeEnum.kFrontViewOrientation, _
DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle)

oDrawingDoc.SaveAs(oNewDrawing, False)

MessageBox.Show("This new file saved as: "& oNewDrawing, "iLogic")

 

 

 

Message 4 of 8

Or maybe something like this since you mentioned you need to choose the template

 

 

	Imports System.IO
Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument

Try 'to open the drawing 
	ThisApplication.Documents.Open _
	(ThisDoc.PathAndFileName(True).Replace("ipt", "idw"))
	Return 'exit rule
Catch	
End Try

'since nothing found create it...
oNewDrawing = ThisDoc.ChangeExtension(".idw")
oTemplateFolder = ThisApplication.FileOptions.TemplatesPath
Dim oList As New ArrayList

Dim Folder As New IO.DirectoryInfo(oTemplateFolder)
For Each File As IO.FileInfo In Folder.GetFiles("*.idw", IO.SearchOption.AllDirectories)
	Dim sName As New FileInfo(File.Name)	
	oList.Add(sName.Name)
Next

oTemplate = InputListBox("Select a template", oList, oList(0),"iLogic", "List")
oTemplate = oTemplateFolder & oTemplate

Dim oDrawingDoc As DrawingDocument 
oDrawingDoc = ThisApplication.Documents.Add _
(DocumentTypeEnum.kDrawingDocumentObject, oTemplate, True)

oDrawingDoc.Activate()
Dim oSheet As Sheet 
oSheet = oDrawingDoc.Sheets.Item(1)

Dim oPoint As Point2d
oPoint = ThisApplication.TransientGeometry.CreatePoint2d(10, 10)

Dim oView As DrawingView
oView = oSheet.DrawingViews.AddBaseView(oDoc, oPoint, 1, _
ViewOrientationTypeEnum.kFrontViewOrientation, _
DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle)

oDrawingDoc.SaveAs(oNewDrawing, False)

MessageBox.Show("This new file saved as: "& oNewDrawing, "iLogic")

 

Message 5 of 8

Hey Curtis, Brilliant.

 

I chopped the save function off the end, but I'm running that one straight as is.

 

Thanks for your help!

Message 6 of 8

Hey Curtis - 

 

Do you know how to get this running on an assembly? Currently throwing an error

 

liamdewhurstNMKYG_0-1623650888994.png

I can change the PartDocument to an AssemblyDocument and it runs however I'm just not sure how to leave it looking for a part, but  catch the error and run as an Assembly Doc instead?

 

This feels like a simple thing - but it doesn't quite compute yet/

 

Imports System.IO
Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument

'change this to 
Imports System.IO
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument

'But if I try to run two variables I get stuck in the Try loop
Dim oAsm As AssemblyDocument
Dim oDpc As PartDocument
oDoc = ThisApplication.ActiveDocument
oAsm = ThisApplication.ActiveDocument

Try 'to open the drawing 
	ThisApplication.Documents.Open _
	(ThisDoc.PathAndFileName(True).Replace("ipt", "idw"))
	Return 'exit rule
Catch	
        ThisApplication.Documents.Open _
	(ThisAsm.PathAndFileName(True).Replace("ipt", "idw"))
	Return 'exit rule
End Try

'I'm just not sure how to catch the failure and turn it into opening an assembly doc.

 

But..... I managed to get this & my other macros into buttons

#myfirstbutton

It's the small things in life that are really satisfying...

liamdewhurstNMKYG_1-1623650954145.png

 

Message 7 of 8

Hi @liam.dewhurstNMKYG 

 

Maybe just something like this.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

Imports System.IO
Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument
oExt = Right(oDoc.FullDocumentName,3) 'get file extension

Try 'to open the drawing 
	ThisApplication.Documents.Open _
	(ThisDoc.PathAndFileName(True).Replace(oExt, "idw"))
	Return 'exit rule
Catch	
End Try

'since nothing found create it...
oNewDrawing = ThisDoc.ChangeExtension(".idw")
oTemplateFolder = ThisApplication.FileOptions.TemplatesPath

Dim oList As New ArrayList

Dim Folder As New IO.DirectoryInfo(oTemplateFolder)
For Each File As IO.FileInfo In Folder.GetFiles("*.idw", IO.SearchOption.AllDirectories)
	Dim sName As New FileInfo(File.Name)	
	oList.Add(sName.Name)
Next

oTemplate = InputListBox("Select a template", oList, oList(0), "iLogic", "List")
oTemplate = oTemplateFolder & oTemplate
Logger.Info(oTemplate)

Dim oDrawingDoc As DrawingDocument 
oDrawingDoc = ThisApplication.Documents.Add _
(DocumentTypeEnum.kDrawingDocumentObject, oTemplate, True)

oDrawingDoc.Activate()
Dim oSheet As Sheet 
oSheet = oDrawingDoc.Sheets.Item(1)

Dim oPoint As Point2d
oPoint = ThisApplication.TransientGeometry.CreatePoint2d(10, 10)

Dim oView As DrawingView
oView = oSheet.DrawingViews.AddBaseView(oDoc, oPoint, 1, _
ViewOrientationTypeEnum.kFrontViewOrientation, _
DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle)

 

Message 8 of 8

How do I get it to select my default drawing template rather than listing ansi, bsi etc?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report