At first I did not try the macro, I just examined the code for the
collection object usage. I put the code in my default.ivb and
tried it on a drawing I have which the part has a flatpattern in
(the view also already has a view of the flat pattern, among other
views) and I am running into an "Object required" error on the
line:
Set oOptions = InventorApp.TransientObjects.CreateNameValueMap
As far as I can determine, InventorApp is not set to anything. I changed
InventorApp to ThisApplication and it did run OK. I selected 2 views (Top & Front)
and they both changed to the same top view of the flat pattern, even though
I selected "No" on the second one when asked if the orientation was OK.
But I imagine at this point you are not finished with the macro.
I hardly ever work with sheetmetal and flat patterns, but at this point if it
is going to change all the selected views to the same flat pattern view, I
would question if it really needs to allow selection of more than one view,
but again, I realize it is not a finished macro it seems. Otherwise, looks good.
Bob S.
"Teun Ham (IV9)" wrote in message news:4148340d$1_2@newsprd01...
> No, that doesn't matter at all.
>
> I usually declare my variables when I need them.
> If I have finished the piece of code, I move all the Dims to the top of the
> code (that's cleaner)
>
> B.t.w, what do you think of this macro?
>
> "Bob S." wrote in message
> news:41483345$1_1@newsprd01...
>> Teun,
>>
>> Thanks much for the example and quick response. It looks alot
>> simpler than I had imagined.
>>
>> Bob S.
>>
>> P.S. Is there a good reason that some of the variables are declared (Dim)
>> within the loops? Just wondering if I should be doing it that way if it
>> makes any difference.
>>
>> "Teun Ham (IV9)" wrote in
> message news:4148311f_1@newsprd01...
>> > OK here's an example:
>> >
>> > This is something I put together, very handy if I may say.
>> > Open an IDW that contains some views of sheetmetal parts (which have a
>> > FlatPattern).
>> > Select some (or all) views and run this macro.
>> >
>> > See what happens...
>> >
>> > Cheers,
>> >
>> > Teun
>> >
>> > P.s. It's the "oSelectedObjects As New Collection" that you are
> interested
>> > in, I guess
>> >
>> > *****
>> >
>> > Sub ChangeViewToFlatPatternView()
>> >
>> > If ThisApplication.Documents.Count = 0 Then MsgBox "A drawing must be
>> > active!": Exit Sub
>> > If ThisApplication.ActiveDocumentType <> kDrawingDocumentObject Then
> MsgBox
>> > "A drawing must be active!": Exit Sub
>> >
>> > Dim oDrawDoc As DrawingDocument
>> > Set oDrawDoc = ThisApplication.ActiveDocument
>> >
>> > If oDrawDoc.SelectSet.Count = 0 Then MsgBox "Please select 1 or more
>> > DrawingViews", vbInformation: Exit Sub
>> >
>> > Dim oSheet As Sheet
>> > Set oSheet = oDrawDoc.ActiveSheet
>> >
>> > Dim oSelectedObjects As New Collection
>> > Set oSelectedObjects = Nothing
>> > Dim i As Integer
>> > For i = 1 To oDrawDoc.SelectSet.Count
>> > oSelectedObjects.Add (oDrawDoc.SelectSet.Item(i))
>> > Next i
>> >
>> > For i = 1 To oSelectedObjects.Count
>> > If oSelectedObjects(i).Type = kDrawingViewObject Then
>> > Dim oDrawingView As DrawingView
>> > Set oDrawingView = oSelectedObjects(i)
>> >
>> > Dim oModel As Document
>> > Set oModel =
>> > ThisApplication.Documents.Open(oDrawingView.ReferencedFile.FullFileName,
>> > False)
>> >
>> > If oModel.DocumentType = kPartDocumentObject Then
>> > Dim sCurrentDocumentSubType As String
>> > sCurrentDocumentSubType = oModel.SubType
>> >
>> > oModel.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"
>> >
>> > Dim oSheetMetalCompDef As SheetMetalComponentDefinition
>> > Set oSheetMetalCompDef = oModel.ComponentDefinition
>> >
>> > Dim oFlatPattern As FlatPattern
>> > Set oFlatPattern = oSheetMetalCompDef.FlatPattern
>> >
>> > ' Check to see if the flat exists.
>> > If Not oFlatPattern Is Nothing Then
>> > 'FlatPattern exists, so "switch views"
>> > Dim oTG As TransientGeometry
>> > Set oTG = ThisApplication.TransientGeometry
>> >
>> > 'Extract View Location
>> > Dim oPoint As Point2d
>> > Set oPoint = oTG.CreatePoint2d(oDrawingView.Center.X,
>> > oDrawingView.Center.Y)
>> >
>> > 'Create FlatPattern Option
>> > Dim oOptions As NameValueMap
>> > Set oOptions =
>> > InventorApp.TransientObjects.CreateNameValueMap
>> > Call oOptions.Add("SheetMetalFoldedModel", False)
>> >
>> > Dim oFlatView As DrawingView
>> > Set oFlatView = oSheet.DrawingViews.AddBaseView(oModel,
>> > oPoint, oDrawingView.Scale, kDefaultViewOrientation,
>> > kHiddenLineRemovedDrawingViewStyle, , , , oOptions)
>> >
>> > Dim Response As Integer
>> > Response = MsgBox("Orientation Correct?", vbYesNo)
>> >
>> > If Response = vbNo Then
>> > oFlatView.Delete
>> > Set oFlatView =
> oSheet.DrawingViews.AddBaseView(oModel,
>> > oPoint, oDrawingView.Scale, kFlatPivot180ViewOrientation,
>> > kHiddenLineRemovedDrawingViewStyle, , , , oOptions)
>> > End If
>> >
>> > oDrawingView.Delete
>> >
>> > oModel.SubType = sCurrentDocumentSubType
>> > Else
>> > MsgBox "No Flatpattern exists in this model"
>> > End If
>> > End If
>> > End If
>> > Next i
>> >
>> > Set oSelectedObjects = Nothing
>> >
>> > End Sub
>> >
>> >
>>
>>
>
>