Community
I have created an I-factory of Parts and I have a master drawing ready. I am trying find something that will create drawings for every member of the I-factory.
If you put the first iPart member to the 1st drawing sheet,
then the following VBA macro could create sheets for all other members
using method shown in this video
http://www.youtube.com/watch?v=7Y2lgdPf7dM
Sub iPartMembersDrawings()
Dim oDrawDoc As DrawingDocument
Set oDrawDoc = ThisApplication.ActiveDocument
'Set a reference to the 1st sheet - master
Dim oMasterSheet As Sheet
Set oMasterSheet = oDrawDoc.Sheets.Item(1)
'reference to the base view (assume it is the 1st view)
Dim oMasterView As DrawingView
Set oMasterView = oMasterSheet.DrawingViews.Item(1)
'reference to the referenced part
Dim oDoc As Inventor.PartDocument
Set oDoc = oMasterView.ReferencedDocumentDescriptor.ReferencedDocument
Call oDoc.Update
Dim oFactory As iPartFactory
Dim oMember As iPartMember
Dim MemberName As String
Dim oTargetSheet As Sheet
Dim oTargetView As DrawingView
Dim i As Integer
'part definition
Dim oCompDef As PartComponentDefinition
Set oCompDef = oDoc.ComponentDefinition
If oCompDef.IsiPartMember Then
'this is iPart member
Set oMember = oCompDef.iPartMember
MemberName = oMember.Row.MemberName
'reference to the factory object
Set oFactory = oMember.ParentFactory
'loop through the factory table rows 2..Count
For i = 2 To oFactory.TableRows.Count
'create new sheet
Set oTargetSheet = AddNewSheet_Using_Command(oMasterSheet)
' copy all views from Master sheet to the new sheet
Call CopyAllDrawingViews(oMasterSheet, oTargetSheet)
' base view on the target sheet
Set oTargetView = oTargetSheet.DrawingViews.Item(1)
MemberName = oFactory.TableRows.Item(i).MemberName
oTargetView.ActiveMemberName = MemberName
'show member name in the view's label
'for debugging purposes only
oTargetView.Label.FormattedText = MemberName
oTargetView.ShowLabel = True
oTargetSheet.Update
Next i
Else
MsgBox "Put the 1st member to the 1st sheet"
End If
Beep
End Sub
Function AddNewSheet_Using_Command(ByRef oSourceSheet As Sheet) As Sheet
Dim oDoc As DrawingDocument
Set oDoc = oSourceSheet.Parent
Dim oCopyCmd As ControlDefinition
Set oCopyCmd = ThisApplication.CommandManager.ControlDefinitions.Item("DrawingNewSheetCtxCmd")
oCopyCmd.Execute
Set AddNewSheet_Using_Command = oDoc.Sheets.Item(oDoc.Sheets.Count)
End Function
Sub CopyAllDrawingViews(ByRef oSourceSheet As Sheet, _
ByRef oTargetSheet As Sheet)
Dim oDoc As DrawingDocument
Set oDoc = oSourceSheet.Parent
oSourceSheet.Activate
' Select all the views to copy
oDoc.SelectSet.Clear
Dim oView As DrawingView
For Each oView In oSourceSheet.DrawingViews
Call oDoc.SelectSet.Select(oView)
Next
' Execute the copy command
Dim oCopyCmd As ControlDefinition
Set oCopyCmd = ThisApplication.CommandManager.ControlDefinitions.Item("AppCopyCmd")
Call oCopyCmd.Execute
' Activate and select the destination sheet
oTargetSheet.Activate
oDoc.SelectSet.Select oDoc.ActiveSheet
' Execute the paste command
Dim oPasteCmd As ControlDefinition
Set oPasteCmd = ThisApplication.CommandManager.ControlDefinitions.Item("AppPasteCmd")
Call oPasteCmd.Execute
End Sub
Hope this helps.
Cheers,