Inventor iLogic : Unfold an edited sheet metal component occurrence of an assembly.

Inventor iLogic : Unfold an edited sheet metal component occurrence of an assembly.

vpeuvion
Advocate Advocate
343 Views
6 Replies
Message 1 of 7

Inventor iLogic : Unfold an edited sheet metal component occurrence of an assembly.

vpeuvion
Advocate
Advocate

Hi, I'm trying to unfold an edited sheet metal component occurrence of an assembly with no success. I took a rule that works in a part and transposed it to an assembly but it doesn't work. The component occurrence is well edited but I can't unfold it. Something escapes me. Can someone help me?
Attached is the rule I use.

Sub Main()
	Dim oAsm As AssemblyDocument = ThisDoc.Document
	Dim oAsmCompDef As AssemblyComponentDefinition = oAsm.ComponentDefinition

	' Edit ComponentOccurrence
	Dim oPartOccurrence As ComponentOccurrence = oAsmCompDef.Occurrences.ItemByName("Part1:1")
	oPartOccurrence.Edit
	
	Dim oPartDoc As PartDocument = oPartOccurrence.Definition.Document
	Dim oSMCD As SheetMetalComponentDefinition = oPartDoc.ComponentDefinition
	Dim oBendsEnum As BendsEnumerator = oSMCD.Bends
	Dim oSMF As SheetMetalFeatures = oSMCD.Features
	Dim oCM As CommandManager = ThisApplication.CommandManager
	
	' Choix de la face de référence
	Dim oFace As Face = oCM.Pick(SelectionFilterEnum.kPartFaceFilter,"Sélectionner la face de référence")
	If IsNothing(oFace) Then Return
	
	' Dépliage complet de la pièce
	Dim oBends As Inventor.ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
	Dim oUnFoldFeat As UnfoldFeature
	For Each oB In oBendsEnum
		oBends.Add(oB)
	Next
	oUnFoldFeat = oSMF.UnfoldFeatures.Add(oFace, oBends)
	
	'oPartOccurrence.ExitEdit(ExitTypeEnum.kExitToParent)
End Sub

 Thank you in advance. Vincent.

0 Likes
Accepted solutions (1)
344 Views
6 Replies
Replies (6)
Message 2 of 7

WCrihfield
Mentor
Mentor

Hi @vpeuvion.  Are you trying to create the FlatPattern of the sheet metal part, or just unfold every individual bend in the part, leaving behind a series of UnFoldFeatures in the model tree?  If you want to create a true FlatPattern, you need to use the SheetMetalComponentDefinition.Unfold() (or Unfold2()) method.  Also, I noticed a variable in your code that was not defined, which might cause a problem.

In the below code:

 

For Each oB In oBendsEnum
	oBends.Add(oB)
Next

 

...the variable 'oB' is not defined (no Type set).

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 7

vpeuvion
Advocate
Advocate

Hi @WCrihfield. Thank you for your reply.

I wish unfold every individual bend in the part, leaving behind a series of UnFoldFeatures in the model tree.

0 Likes
Message 4 of 7

vpeuvion
Advocate
Advocate

If I open the part with 

ThisDoc.Launch(oPartDoc.FullDocumentName)

it works.
I tried with

For Each oB As Bend In oBendsEnum

but the result is the same.

oBendsEnum is declared : 

Dim oBendsEnum As BendsEnumerator = oSMCD.Bends

 

0 Likes
Message 5 of 7

WCrihfield
Mentor
Mentor

Yea, I saw the oBendsEnum variable in there, just after I originally responded.  For some reason I did not see it when I first looked at your code.  Then I also quickly realized that when looping a specific type of Enumerator, you may not need to define that object variable's Type, because it is implied.  Does the part have any custom model states?  If so, then when you use its FullDocumentName, that will contain the name of its 'active' model state at the end, and opening it that way makes sure that you are working with its 'factory document' version, which would be the only version you can make edit changes to.  Plus some edits simply need the document to be visibly open before they will work.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 7

vpeuvion
Advocate
Advocate

Hi @WCrihfield . No problem 😉. The part does not have custom model states.

Thank you for your help, I will continue my research and will publish if I get results.

Vincent.

0 Likes
Message 7 of 7

vpeuvion
Advocate
Advocate
Accepted solution

Hi. I think I found a solution using proxy faces.

I noticed that when going from the assembly to the edited part some properties of the face are preserved but the face object is not usable as it is.

Here is an example that may help someone.

Sub Main()
	Dim oAsm As AssemblyDocument = ThisDoc.Document
	Dim oAsmCompDef As AssemblyComponentDefinition = oAsm.ComponentDefinition

	Dim oPartOccurrence As ComponentOccurrence = oAsmCompDef.Occurrences.ItemByName("Part1:1")
	oPartOccurrence.Edit
	
	Dim oCM As CommandManager = ThisApplication.CommandManager
	Dim oFaceProxy As FaceProxy = oCM.Pick(SelectionFilterEnum.kPartFaceFilter, "Sélectionner la face de référence")
	Dim oPartDoc As PartDocument = oPartOccurrence.Definition.Document
	Dim oSMCD As SheetMetalComponentDefinition = oPartDoc.ComponentDefinition
	Dim oSMF As SheetMetalFeatures = oSMCD.Features
	Dim oUnFoldFeat As UnfoldFeature
	oUnFoldFeat = oSMF.UnfoldFeatures.Add(oFaceProxy.NativeObject)
End Sub

 

0 Likes