Create derived part of assembly | Exclude all assembly parts Sketches Parameters WorkFeatures

Create derived part of assembly | Exclude all assembly parts Sketches Parameters WorkFeatures

RolfEven
Enthusiast Enthusiast
2,362 Views
17 Replies
Message 1 of 18

Create derived part of assembly | Exclude all assembly parts Sketches Parameters WorkFeatures

RolfEven
Enthusiast
Enthusiast

Hi,

 

I've found an iLogic rule from the site in the link below that creates a derived part of an assembly.

https://microconcepts.typepad.com/design_automation/2015/07/ilogic-rule-to-create-a-single-derived-p... 

 

The reason for this post is that I can not figure out how I can exclude all assembly parts sketches, parameters and workfeatures in the derived part. I hope this can be accomplished in other ways than turning sketch visibility off inn all parts. What would be ideal is to control this in a similar way as done in the GUI shown in the picture below.

 

Excludes the selected objects.PNG

 

What I have tried is ask Google to see if anybody have solved this task already, but either I'm asking Google the wrong questions (most likely) or Google simply doesn't know. I've also looked in the API help in Inventor and here I found a Method to do the opposite to what I want to do, IncludeAllSketches. I want to ExcludeAllSketches. For top-level sketches in the assembly there is a similar API document, but this is not a Method but a Properties. I lack the programming skills to know the difference, but I see there is a difference in the two.

API Sketch Method.PNG

 

The code below is what I have tried so far, but I'm not doing this correctly. The include all (not commented out) is doing what it is supposed to do, but I struggle to create the code to do the opposite.

 

'--- Work in progress, this section is not okay
'Method that includes all sketches from the source assembly.
'This includes top level sketches In the source assembly As well As sketches In Sub-assemblies And parts.
oDerivedAssemblyDef.IncludeAllSketches()
'oDerivedAssemblyDef.ExcludeAllSketches()
'oDerivedAssemblyDef.IncludeAllSketches() = DerivedComponentOptionEnum.kDerivedExcludeAll
'oDerivedAssemblyDef.IncludeAllSketches = False
'---End Work in progress

 

 

If anybody can point me the right direction to help me understand what I have to do I would highly appreciate that.

/Rolf Even

0 Likes
Accepted solutions (1)
2,363 Views
17 Replies
Replies (17)
Message 2 of 18

A.Acheson
Mentor
Mentor

Maybe try below. This is how the sample is layed out. 

oDerivedAssemblyDef.IncludeAllSketches() = kDerivedExcludeAll

AAcheson_0-1643928568967.png

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 18

RolfEven
Enthusiast
Enthusiast

Thanks Alan,

I've tried adding the suggested code but it creates an error when I run the iLogic rule.

Error line 24.PNG

The only way I can make the Method "oDerivedAssemblyDef.IncludeAllSketches()" to work is shown below. And this code includes all sketches in all assembly parts. Do I need to create a loop function that turns off all sketches after the derived part is created, or is it possible to use the Method to exclude instead of include?

'---End Work in progress
oDerivedAssemblyDef.IncludeAllSketches()
'--- Start Work in progress

Include all sketches.PNG

/Rolf Even

0 Likes
Message 4 of 18

A.Acheson
Mentor
Mentor

oDerivedAssemblyDef.IncludeAllTopLevelSketches = kDerivedExcludeAll

Based on testing this will only effect the top assembly sketches, by default all sub assembly sketches will be removed. Sample taken from 2020 API help Shrink wrap substitute in assembly API Sample

 

Sub Main
    '  a reference to the active assembly document
    Dim oDoc As AssemblyDocument
     oDoc = ThisApplication.ActiveDocument

    Dim oDef As AssemblyComponentDefinition
     oDef = oDoc.ComponentDefinition

    ' Create a new part document that will be the shrinkwrap substitute
    Dim oPartDoc As PartDocument
     oPartDoc = ThisApplication.Documents.Add(kPartDocumentObject, , False)

    Dim oPartDef As PartComponentDefinition
     oPartDef = oPartDoc.ComponentDefinition

    Dim oDerivedAssemblyDef As DerivedAssemblyDefinition
     oDerivedAssemblyDef = oPartDef.ReferenceComponents.DerivedAssemblyComponents.CreateDefinition(oDoc.FullDocumentName)

    '  various shrinkwrap related options
    oDerivedAssemblyDef.DeriveStyle = kDeriveAsSingleBodyNoSeams
    oDerivedAssemblyDef.IncludeAllTopLevelWorkFeatures = kDerivedIncludeAll
    oDerivedAssemblyDef.IncludeAllTopLevelSketches = kDerivedExcludeAll' Based on testing this will only effect the top assembly sketches, by defualt all sub assembly sketches will be removed
	oDerivedAssemblyDef.IncludeAllTopLeveliMateDefinitions = kDerivedExcludeAll
    oDerivedAssemblyDef.IncludeAllTopLevelParameters = kDerivedExcludeAll
    oDerivedAssemblyDef.ReducedMemoryMode = True

'    Call oDerivedAssemblyDef.HolePatchingOptions(kDerivedPatchAll)
    'Call oDerivedAssemblyDef.RemoveByVisibilityOptions(kDerivedRemovePartsAndFaces, 25)

    ' Create the shrinkwrap component
    Dim oDerivedAssembly As DerivedAssemblyComponent
     oDerivedAssembly = oPartDef.ReferenceComponents.DerivedAssemblyComponents.Add(oDerivedAssemblyDef)

    ' Save the part
    Dim strSubstituteFileName As String
    strSubstituteFileName = Left$(oDoc.FullFileName, Len(oDoc.FullFileName) - 4)
    strSubstituteFileName = strSubstituteFileName & "_ShrinkwrapSubstitute.ipt"

    ThisApplication.SilentOperation = True
    Call oPartDoc.SaveAs(strSubstituteFileName, False)
    ThisApplication.SilentOperation = False

    ' Create a substitute level of detail using the shrinkwrap part.
    Dim oSubstituteLOD As LevelOfDetailRepresentation
     oSubstituteLOD = oDef.RepresentationsManager.LevelOfDetailRepresentations.AddSubstitute(strSubstituteFileName)

    ' Release reference of the invisibly opened part document.
    oPartDoc.ReleaseReference
End Sub

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 5 of 18

RolfEven
Enthusiast
Enthusiast

Thank you for taking the time to help me with this case. I'm new to this iLogic world, so the help is highly appreciated.

I've tried to do a little bit more research. I've added a assembly and a part file to this post. Inside the assembly file there is a iLogic rule "Shrink wrap substitute". If you change which one of line 22 / 23 that is commented out, the derived substitute part will either be without or with the sketch with the text "Top Level Assembly Sketch".

If one remove the comment on line 28, the derived substitute part will include both the visible sketch "Sketch1" and the invisible shared sketch "Sketch4".

So for top level sketches I'm able to code if I want sketches to be included or not in the derived part. For sketches inside assembly parts I'm able to code how to include them. What I do not understand is how I can create a code that excludes all sketches inside assembly parts, regardless of the sketch being visible or shared?

iLogic Shrink wrap substituteiLogic Shrink wrap substitute

 

Assembly_Derived_SourceAssembly_Derived_Source

 

Assembly_Derived_Part Include All Top Level SketchesAssembly_Derived_Part Include All Top Level Sketches

Assembly_Derived_Part Include All SketchesAssembly_Derived_Part Include All Sketches

/Rolf Even

0 Likes
Message 6 of 18

A.Acheson
Mentor
Mentor

If I read your post correctly you want to remove all sketches. In my testing on 2020 this snippet removed sketches from the derived part. 

oDerivedAssemblyDef.IncludeAllTopLevelSketches = kDerivedExcludeAll'

Are you seeing the same thing? 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 7 of 18

RolfEven
Enthusiast
Enthusiast

Correct, I'm looking for a way to have no sketches in the derived part, as shown in picture "Derived substitute with no Sketches". With "oDerivedAssemblyDef.IncludeAllTopLevelSketches = kDerivedExcludeAll" all top level sketches in the assembly is excluded. But visible sketches in parts are included.

I've added a R2020 assembly that is used in the below pictures. Assembly.iam has an iLogic rule "Shrink wrap substitute"

Assembly with some Sketches visibleAssembly with some Sketches visible

Derived substitute with SketchesDerived substitute with Sketches

Derived substitute with no SketchesDerived substitute with no Sketches

/Rolf Even

0 Likes
Message 8 of 18

J-Camper
Advisor
Advisor

I have been helping another user in This Thread 

 

I think the goals are similar, and I just figured out a way to get the part level sketches to not show up in the derived part.  You can find the most Up-to-Date full code from my last post on the thread linked above.  The subroutine handling the ObjectVisibility code is below:

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 need help adapting your code to work with the Sub routine above, or if you need help converting the full code, posted on the linked thread, to function the way you need.

0 Likes
Message 9 of 18

RolfEven
Enthusiast
Enthusiast

Thank you for the input and the subrutine code. I've embedded your code inside the code found in the link below. The derived part is now without sketches, and also without the other work features specified in the code you provided.

https://microconcepts.typepad.com/design_automation/2015/07/ilogic-rule-to-create-a-single-derived-p...

Since this is still work in progress I've attached an updated Assembly.iam with the modified rule to create derived part without sketches. I will post a working code when it is more complete. A remaining task is to reset sketch visibility in the assembly file. Pressing F10 by hand does this, but I'm not sure on how I should code this. In other words, I only need the sketches to be invisible when the derived part is created. Visible sketches in the assembly should ideally be the same in the two assembly pictures below.

If anyone could download Assembly.iam and the two parts from post #7 and check the code I'll highly appreciate that. Also if it is better to post the work in progress code directly in the thread please let me know.

Assembly with some Sketches visible 2Assembly with some Sketches visible 2

Derived part without SketchesDerived part without Sketches

Assembly with Sketche visibility turned offAssembly with Sketche visibility turned off

/Rolf Even

0 Likes
Message 10 of 18

J-Camper
Advisor
Advisor

@RolfEven,

I was running the Sub routine above with (AssemblyDocument, False) at the beginning of the process then with (AssemblyDocument, True) after the derived part was created.  The second call is there to turn ObjectVisibilty back on in the main assembly. 

 

I prefer looking at posted code alone in most cases.  I only prefer parts/assemblies if the code is meant to be very specific to a particular work flow or if there is a unique issue that I cannot recreate myself.  That's just my opinion though.

 

If you still need help implementing this, please let me know.

0 Likes
Message 11 of 18

RolfEven
Enthusiast
Enthusiast

@J-Camper,

I'm completely new to the programing world so I'm more than likely to ask the same question over and over again. But with the help of kind souls out there I'm taking step by step away from the start location. Thank you for taking the time to help me.

 

Since you are kind enough to give away a finger, why shouldn't I take the whole hand... I think I'll learn more with your explanations instead of my copy/paste until it works method. So, if you have the time to look at the code below and help me understand how I should/could write the sequence to turn visibility on/off in the assembly I'm grateful for that.

 

This is what I have puzzled together so far:

Dim g_App As Inventor.InventorServer = ThisApplication
Dim AssDoc As Inventor.AssemblyDocument = ThisDoc.Document

Dim ObjectVisibility As AssemblyDocument
Dim oToggle As Boolean
Dim oVis As ObjectVisibility = AssDoc.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

' 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 the part
Dim partname As String=ThisDoc.PathAndFileName(False)& ".ipt"
ThisApplication.ActiveView.Fit
ThisApplication.CommandManager.ControlDefinitions.Item("AppIsometricViewCmd").Execute
Call oPartDoc.SaveAs(partname ,  False)

/Rolf Even

0 Likes
Message 12 of 18

J-Camper
Advisor
Advisor

I believe this should work for you:

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 ReturnState As Boolean = visRep.Locked
	
	If visRep.DesignViewType = DesignViewTypeEnum.kMasterDesignViewType
		ReturnState = False
		MessageBox.Show("ObjectVisibility Toggles don't affect Derived Parts using the ""Master"" View Representation", "Limited Functionality")
	End If
	
	If ReturnState Then visRep.Locked = Not(ReturnState)
	
	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)
	
	If ReturnState Then visRep.Locked = ReturnState
	
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

 

I moved a few things to separate sub routines as it makes overall code easier to read/edit later.  I also added some logic to help avoid errors.  Let me know if you have any questions, or if this is not working as intended.

0 Likes
Message 13 of 18

RolfEven
Enthusiast
Enthusiast

@J-Camper,

Thank you for the solution, and even more for taking the time to help me.

 

Do I read the code correctly that "If visRep.DesignViewType = DesignViewTypeEnum.kMasterDesignViewType" is a check to see if the assembly has Master selected as View Representation? If yes, the code, to my knowledge, does not show the message box in the if sentence when assembly view representation is set to "Master".

 

My original idea was to use Master View Representation as a method to make sure that all parts within the assembly was visible and hence included in the derived part, but I think this is possible to achieve in different ways. I need to tinker a little bit more with the code to have all parts in the derived make this work. Maybe I can include part visibility in the same sub as object visibility?

 

Assembly Master ViewAssembly Master View

/Rolf Even

0 Likes
Message 14 of 18

J-Camper
Advisor
Advisor
Accepted solution

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

 

0 Likes
Message 15 of 18

RolfEven
Enthusiast
Enthusiast

@J-Camper,

Beautiful, thank you so much for taking the time to help me with this project.

I added a couple of lines to the code so that View Representation in the assembly file is set back to "Default" after the derived part is created. Modified code is posted below if anybody else is interested.

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
	Dim DefaultRep As DesignViewRepresentation = AssDoc.ComponentDefinition.RepresentationsManager.DesignViewRepresentations.Item("Default")
	DefaultRep.Activate
	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

/Rolf Even

0 Likes
Message 16 of 18

RolfEven
Enthusiast
Enthusiast

Hi,

I need to revisit this thread because I have overlooked that I need to delete/unlink parameters. The parameter "Thickness" is exported in sheet metal parts and used in drawing title block. In the derived part this parameter is included, but I want to exclude it, and all other parameters for that sake. The code in this thread's post 14 excludes all top-level parameters, but parameters from assembly parts gets included.

The picture below from GUI is to illustrate what I want to accomplish. I've spent some time trying to search for a solution, and the closest thing I've found is the two links below. The code below is from the second link, post 3 by @DRoam. This code is working for a derived part. But it is not working for a derived assembly. If anybody can point me in the right direction to solve this, I would highly appreciate it.

https://forums.autodesk.com/t5/inventor-ilogic-api-vba-forum/i-logic-with-derived-parts/td-p/1024475... 

https://forums.autodesk.com/t5/inventor-ilogic-api-vba-forum/deleting-derived-parameters-that-are-no... 

 

Derived part exclude parametersDerived part exclude parameters

Dim oDoc As PartDocument = ThisDoc.Document

For Each oDerivedPartComponent As Inventor.DerivedPartComponent In oDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents
	Dim oDerivedPartDefinition As Inventor.DerivedPartDefinition = oDerivedPartComponent.Definition
	
	For Each oParameterEntity As Inventor.DerivedPartEntity In oDerivedPartDefinition.Parameters
		oParameterEntity.IncludeEntity = False
	Next 'Derived parameter
	oDerivedPartComponent.Definition = oDerivedPartDefinition
Next 'Derived part component

/Rolf Even

0 Likes
Message 17 of 18

J-Camper
Advisor
Advisor

I don't see an easy access to DerivedOccurrence Parameters, but once you break the link all the linked parameters become normal User Parameters.  You should be able to delete them after you break the link.  Like this:

'.... more code above

Call oDerivedAss.BreakLinkToFile()
	
'New lines start:
	For Each p As Inventor.Parameter In oPartDoc.ComponentDefinition.Parameters
		Try
			p.Delete()
		Catch : End Try
	Next
'New lines end

	'Save New Document
	Call SaveFile(oPartDoc, partname)

'.... more code below

 

Let me know if this does not work in your testing.

 

0 Likes
Message 18 of 18

RolfEven
Enthusiast
Enthusiast

@J-Camper,

Thank you for the quick reply. The code you created is working when the link to the source assembly is broken. I guess this would be the perfect moment to share this bit of info; After a little bit of thought since post #14, I'm trying to keep the derived part linked to the source assembly...

So, if it is impractical to get rid of these parameters I see three options. A; do some work by hand (GUI) to unlink parameters. B; leave the parameters there, as I don't think they do anything wrong or causes to much harm. C; Do it the Inception way with a derived in a derived. Idea with C is to first derive the assembly to an IPT, and then derive the IPT into another IPT and there have no parameters. Right now I'm thinking option B.

/Rolf Even

 

0 Likes