Making a drawing for each model

Making a drawing for each model

Anonymous
Not applicable
784 Views
5 Replies
Message 1 of 6

Making a drawing for each model

Anonymous
Not applicable

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

 

 

0 Likes
Accepted solutions (1)
785 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor

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)

0 Likes
Message 3 of 6

Anonymous
Not applicable

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

0 Likes
Message 4 of 6

JelteDeJong
Mentor
Mentor

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

0 Likes
Message 5 of 6

Anonymous
Not applicable

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"

 

 

0 Likes
Message 6 of 6

JelteDeJong
Mentor
Mentor
Accepted solution

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

0 Likes