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: 

Making a drawing for each model

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
Anonymous
575 Views, 5 Replies

Making a drawing for each model

Hi, Tried looping for each model in assembly. But I had a mistake every time. Can someone help me change this code:

 

 

Public Sub AddUsingSheetFormat()


Dim oDrawDoc As DrawingDocument
Set oDrawDoc = ThisApplication.ActiveDocument


Dim oFormat As SheetFormat
Set oFormat = oDrawDoc.SheetFormats.Item("test")

'Open the model document invisible
Dim oModel As Document
Set oModel = ThisApplication.Documents.Open("C:\Users\zlozenie.iam", False)

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

End Sub

 

 

Labels (2)
5 REPLIES 5
Message 2 of 6
WCrihfield
in reply to: Anonymous

These are very basic questions, but it's a fairly basic code.

Is the 'active' document a drawing document, when you run that macro?

Have you made sure that a sheet format with the name "test" already exists within that 'active' drawing document?

Is that assembly file at that location, with that file name?

Can you include a screenshot image of the contents of both tabs within the error message that pops up please.  That may help us understand what is going wrong.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 6
Anonymous
in reply to: Anonymous

This code runs. Yes, the active document is drawing and I have "test" sheet format. I want to change to:

It looped through all objects in an assembly :

 

Public Sub AddUsingSheetFormat()


Dim oDrawDoc As DrawingDocument
Set oDrawDoc = ThisApplication.ActiveDocument


Dim oFormat As SheetFormat
Set oFormat = oDrawDoc.SheetFormats.Item("test")

'Open the assembly document invisible
Dim oAssembly As Document
Set oAssembly = ThisApplication.Documents.Open("C:\Users\zlozenie.iam", False)

Dim oModel As Object

For Each oModel in oAssembly

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

Next

End Sub

Message 4 of 6
JelteDeJong
in reply to: Anonymous

You can try this iLogic code.

Dim oDrawDoc As DrawingDocument = ThisDoc.Document
Dim oFormat As SheetFormat = oDrawDoc.SheetFormats.Item("test")
Dim oAssembly As Document = ThisApplication.Documents.Open("C:\Users\zlozenie.iam", False)

For Each refDoc As Document In oAssembly.ReferencedDocuments
    Dim oSheet As Sheet = oDrawDoc.Sheets.AddUsingSheetFormat(oFormat, refDoc)
Next

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 5 of 6
Anonymous
in reply to: Anonymous

I have an error: "HRESULT: 0x80070057 (E_INVALIDARG))", possibly in line 2. I have inventor 2018. Maybe I should import some library?\

 

I tried to do this in VBA but I can't use the word "in"

 

 

Message 6 of 6
JelteDeJong
in reply to: Anonymous

I only have inventor 2020 and 2021 so i cant test the code for you. But as far as i can tell all functions that i use are available from 2009.

This exception is also thrown if you did not write the sheet format name correct. You also should be aware that the name is case sensitive. This last problem can be solved with a little bit more code. have a look if this works.

Dim oDrawDoc As DrawingDocument = ThisDoc.Document
Dim oFormat As SheetFormat = Nothing 
Dim sheetFormatName = "test"
For Each sf As SheetFormat In oDrawDoc.SheetFormats
	If (sf.Name.Equals(sheetFormatName, StringComparison.InvariantCultureIgnoreCase)) Then
		oFormat = sf
	End If
Next
If (oFormat Is Nothing) Then
	msgbox("Could not find Sheet format: " & sheetFormatName)
End If

For Each refDoc As Document In oAssembly.ReferencedDocuments
    Dim oSheet As Sheet = oDrawDoc.Sheets.AddUsingSheetFormat(oFormat, refDoc)
Next

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

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

Post to forums  

Autodesk Design & Make Report