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
Solved! Go to Solution.
Solved by JelteDeJong. Go to Solution.
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
(Not an Autodesk Employee)
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
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.
Blog: hjalte.nl - github.com
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"
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.
Blog: hjalte.nl - github.com
Can't find what you're looking for? Ask the community or share your knowledge.