Closed MrPeekABoo1 closed 4 years ago
Which rule in particular are you referring to?
It’s the ilogic rule called Create Drawings From Assembly.iLogicVb When run it opens each part in a new new drawing would it be possible to open one drawing and each part added to a new sheet?
Ah yes, I see what you mean. I've got some housekeeping to do (I noticed that some rules aren't in their correct folders - so I'll sort that out and then take a look at changing up that rule so it provides more options.
Ah that would be fantastic have different options would help I will keep an eye out. Thanks
I've amended the rule with the following commit: ebe50963e1a0f182836ae9c48ce242f2934e7491
Please pull the updated copy and test it. There's a boolean called createSingleDrawing that lets you set the single/multi sheet option.
Wow my man you a genius. Works perfectly how did you add another sheet can the title block be added? Or should I run a add title block rule on all them sheet?
You can run an Add Title Block rule on each sheet, yes. I suppose you could call it from within the rule I modified too.
Looking at your code Is it possible to run each item and load the onto a sheet using sheet format? Example: oSheet=oDrawDoc.Sheets.AddUsingSheetFormat(oFormat) Of course oFormat would need to be declared in some part of the code but not what place.
Absolutely, you can do it like this:
http://help.autodesk.com/view/INVNTOR/2020/ENU/?guid=GUID-C7D6623E-6CB1-4F4C-A109-79F429DA753E
'modified from the original VBA above; this is UNTESTED
Public Sub AddUsingSheetFormat()
'Set a reference to the drawing document.
' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
'Set a reference to the sheet format named 'C size, 4 view'
Dim oFormat As SheetFormat = oDrawDoc.SheetFormats.Item("C size, 4 view")
'Open the model document invisible
Dim oModel As Document = ThisApplication.Documents.Open("C:\temp\block.ipt", False)
'Create a new sheet based on the sheet format
Dim oSheet As Sheet = oDrawDoc.Sheets.AddUsingSheetFormat(oFormat, oModel)
End Sub
Obviously, you need to know the name of the format to add.
I have a sheet format ready
Looking at that code you sent I would need to add each model in the code to open in a new sheet is that correct ?
Hi Alex Below is your Create Drawings From Assembly code. I have added Sheet formats to it but unfortunately it seems to flag up an error when it opens up the drawing. do you have any ideas have i added the Sheet format code incorrectly ?
Imports Inventor.ViewOrientationTypeEnum
Imports Inventor.DrawingViewStyleEnum
Imports System.IO
Private Sub Main
CreateDrawingsFromAssembly(ThisDoc.Document)
End Sub
Private Sub CreateDrawingsFromAssembly(ByVal oDoc As Inventor.Document)
'change the following to switch modes:
Dim createSingleDrawing As Boolean = True
Dim oDrawingDoc As DrawingDocument
Dim oPartDoc As Document
Dim oSheet As Sheet
Dim oBaseView As DrawingView
Dim oView1 As DrawingView
Dim oView2 As DrawingView
Dim oView3 As DrawingView
Dim oView4 As DrawingView
Dim ViewScale As Double = 1/10
dwgQuery=MsgBox("Would you like to Create drawings from this Assembly?", vbYesNo,"Drawing Selection")
If dwgQuery = vbYes Then
Dim oAssy As Inventor.AssemblyDocument
Dim oComp As Inventor.ComponentOccurrence
Dim oSubDoc As Inventor.Document
Dim oFormat As SheetFormat
Dim NodeName() As String
Dim InstNum As String
If oDoc.DocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then
oAssy = CType(oDoc, AssemblyDocument)
If createSingleDrawing Then
oDrawingDoc = ThisApplication.Documents.Add(kDrawingDocumentObject, "Drawing Template", True)
'oDrawingDoc = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, TemplateFileName := ThisApplication.FileManager.GetTemplateFile(DocumentTypeEnum.kDrawingDocumentObject), CreateVisible := True)
'oSheet = oDrawingDoc.Sheets.Item(1)
oFormat = oDrawingDoc.SheetFormats.Item("SheetRule")
oSheet = oDrawingDoc.Sheets.AddUsingSheetFormat(oFormat, 1)
End If
For Each refDoc As Document In oAssy.AllReferencedDocuments
If refDoc.FullFileName.Contains("Content Center") Then Continue For
'Define dwg Template File Location
If Not createSingleDrawing Then
oDrawingDoc = ThisApplication.Documents.Add(kDrawingDocumentObject, "Drawing Template", True)
'oDrawingDoc = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, TemplateFileName:= ThisApplication.FileManager.GetTemplateFile(DocumentTypeEnum.kDrawingDocumentObject), CreateVisible:= True)
'oSheet = oDrawingDoc.Sheets.Item(1)
oFormat = oDrawingDoc.SheetFormats.Item("SheetRule")
oSheet = oDrawingDoc.Sheets.AddUsingSheetFormat(oFormat, 1)
Else
'Break 'turned off after debugging.
If oDrawingDoc.Sheets.Count >= 1 Then
'oSheet = oDrawingDoc.Sheets.Add()
oFormat = oDrawingDoc.SheetFormats.Item("SheetRule")
oSheet = oDrawingDoc.Sheets.AddUsingSheetFormat(oFormat ,1)
End If
oSheet.Name = IO.Path.GetFileNameWithoutExtension( refDoc.FullFileName)
End If
Next
End If
End If
End Sub
Off the top of my head I'm not sure. What I would recommend is to change this line:
oDrawingDoc = ThisApplication.Documents.Add(kDrawingDocumentObject, "Drawing Template", True)
to this:
oDrawingDoc = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, "Drawing Template", True)
iLogic is very forgiving in what it will allow you to write in your code. The Inventor API which runs the code is not forgiving at all and the fewer places it can throw the dummy in the sand the better.
I would simply make sure that the filename you're adding with the line above matches the available one as my original (commented) line used whatever was the default file.
Beyond that I would need to see error messages.
The ilogic to create a drawing from the assembly is awesome but could it also add each item in the from the sub assemblies as well on to the same drawing but on its own sheet?
So in theory you would end up with a drawing of assemblies and the parts that built it up.