So in the first forum post I was helping with, we were working to a user created View rep and I had Master Selectable. When selected, the visRep Object did get recognized as a MasterDesignViewRep.... That situation did trigger my If statement to brief the user that These ObjectVisibility changes didn't seem to function in the MasterViewRepresentation. I didn't notice when I brought that check over to your code, the ActiveDesignViewRepresentation [master being active] was reading as a TransientViewRepresentation.
Long story short, I thought I was catching the MasterView rep full, but It appears the ActiveView Rep is a Transient View rep even in the "Master" Is Active.
All it was meant to do is stop the View.Locked property from getting changed if the view was a "Master" View, which can't be unlocked. If you want to base the derived part on Master View Rep, we can make a temporary one then delete it when done. won't need the If Check you mentioned.
Here is a modified code:
Sub Main
Dim g_App As Inventor.InventorServer = ThisApplication
Dim AssDoc As Inventor.AssemblyDocument = TryCast(ThisDoc.Document, AssemblyDocument)
If IsNothing(AssDoc) Then Logger.Debug("Not run in assembly") : Exit Sub
Dim partname As String = AssDoc.FullFileName : partname = Left(partname, partname.Length-4) & ".ipt"
Dim visRep As DesignViewRepresentation = AssDoc.ComponentDefinition.RepresentationsManager.ActiveDesignViewRepresentation
Dim masterRep As DesignViewRepresentation = AssDoc.ComponentDefinition.RepresentationsManager.DesignViewRepresentations.Item("Master")
If visRep.Name <> masterRep.Name Then masterRep.Activate ' Make sure master is active first
Dim tempRep As DesignViewRepresentation = AssDoc.ComponentDefinition.RepresentationsManager.DesignViewRepresentations.Add() 'Make temp view based on Master
tempRep.Activate
Call ObjectVisibility(AssDoc, False)
' Create a new part document that will be the shrinkwrap substitute
Dim oPartDoc As PartDocument
oPartDoc = g_App.Documents.Add(DocumentTypeEnum.kPartDocumentObject, , True)
Dim oPartDef As PartComponentDefinition
oPartDef = oPartDoc.ComponentDefinition
Dim oDerivedAssemblyDef As DerivedAssemblyDefinition
oDerivedAssemblyDef = oPartDef.ReferenceComponents.DerivedAssemblyComponents.CreateDefinition(AssDoc.FullDocumentName)
' Set various shrinkwrap related options
oDerivedAssemblyDef.DeriveStyle = DerivedComponentStyleEnum.kDeriveAsMultipleBodies
oDerivedAssemblyDef.IncludeAllTopLevelWorkFeatures = DerivedComponentOptionEnum.kDerivedExcludeAll
oDerivedAssemblyDef.IncludeAllTopLevelSketches = DerivedComponentOptionEnum.kDerivedExcludeAll
oDerivedAssemblyDef.IncludeAllTopLeveliMateDefinitions = DerivedComponentOptionEnum.kDerivedExcludeAll
oDerivedAssemblyDef.IncludeAllTopLevelParameters = DerivedComponentOptionEnum.kDerivedExcludeAll
Call oDerivedAssemblyDef.SetHolePatchingOptions(DerivedHolePatchEnum.kDerivedPatchNone)
Call oDerivedAssemblyDef.SetRemoveByVisibilityOptions(DerivedGeometryRemovalEnum.kDerivedRemoveNone)
Dim oDerivedAss As DerivedAssemblyComponent
oDerivedAss = oPartDoc.ComponentDefinition.ReferenceComponents.DerivedAssemblyComponents.Add(oDerivedAssemblyDef)
Call oDerivedAss.BreakLinkToFile()
'Save New Document
Call SaveFile(oPartDoc, partname)
AssDoc.Activate
Call ObjectVisibility(AssDoc, True)
tempRep.Delete
End Sub
Sub SaveFile(oDoc As Document, NewFileName As String)
Try
oDoc.SaveAs(NewFileName, False)
ThisApplication.ActiveView.Fit
ThisApplication.CommandManager.ControlDefinitions.Item("AppIsometricViewCmd").Execute()
Catch
MessageBox.Show(oDoc.DisplayName & " cannot be overwritten.", "Terminating")
oDoc.Close(True)
Exit Sub
End Try
End Sub
Sub ObjectVisibility(AsmDoc As AssemblyDocument, oToggle As Boolean)
Dim oVis As ObjectVisibility = AsmDoc.ObjectVisibility
oVis.Sketches = oToggle
oVis.Sketches3D = oToggle
oVis.UserWorkPlanes = oToggle
oVis.UserWorkAxes = oToggle
oVis.UserWorkPoints = oToggle
oVis.OriginWorkPlanes =oToggle
oVis.OriginWorkAxes = oToggle
oVis.OriginWorkPoints = oToggle
End Sub
Let me know if you are still having issues/questions