modify the part rule to be called by the assembly

modify the part rule to be called by the assembly

mostafamahmoudseddek94
Advocate Advocate
461 Views
2 Replies
Message 1 of 3

modify the part rule to be called by the assembly

mostafamahmoudseddek94
Advocate
Advocate

Hi, 

I have a part that contains a sketch pattern in which I try to suppress a specific occurrence of that pattern the rule does work pretty well when I run the rule in the part environment. Still, when I run the rule from the assembly that contains this part, the rule does not work at all, probably because of the first two lines of my code.

I need to modify my code a little bit to be called from the assembly environment.

Dim oCompD As PartComponentDefinition
     oCompD = ThisApplication.ActiveDocument.ComponentDefinition
 
Dim oFeature As PartFeatures
     oFeature = oCompD.Features
 
Dim oPattern As SketchDrivenPatternFeature
     oPattern = oFeature.SketchDrivenPatternFeatures.Item(1)

If Bags_NO = 6 Or Bags_NO = 8 Or Bags_NO = 11 Then
	oPattern.PatternElements.Item(2).Suppressed = False
    L2 = 400
Else
	oPattern.PatternElements.Item(2).Suppressed = False
	L2 = 600
End If


If Bags_NO = 5 Then 
	oPattern.PatternElements.Item(2).Suppressed = True
	End If

If Bags_NO <=9  Then
   oPattern.PatternElements.Item(3).Suppressed = True
Else If Bags_NO = 14 
	oPattern.PatternElements.Item(3).Suppressed = False
	L3 = 400 
Else 
	oPattern.PatternElements.Item(3).Suppressed = False
	L3 = 600
End If

If Bags_NO <=10 Or Bags_NO = 12  Then
    oPattern.PatternElements.Item(4).Suppressed = True
Else If Bags_NO = 11
	oPattern.PatternElements.Item(4).Suppressed = False
	L4 = 400 
Else 
	oPattern.PatternElements.Item(4).Suppressed = False
	L4 = 600
End If

InventorVb.DocumentUpdate()
iLogicVb.UpdateWhenDone = True
ThisDoc.Save

that part, it does not work at all 

0 Likes
Accepted solutions (2)
462 Views
2 Replies
Replies (2)
Message 2 of 3

Michael.Navara
Advisor
Advisor
Accepted solution

Modify your rule as follows

In part document:

Dim partDoc As PartDocument = ThisDoc.Document
Dim oCompD As PartComponentDefinition = partDoc.ComponentDefinition

 Now when you run this rule from edited part n assembly context it works.

 

If you want to call this rule from assembly iLogic, use following syntax:

iLogicVb.RunRule("Part1:1", "Rule0")

Where "Part1:1" is occurrence name in assembly, "Rule0" is name of your rule in part context

 

0 Likes
Message 3 of 3

JelteDeJong
Mentor
Mentor
Accepted solution

try replacing

Dim oCompD As PartComponentDefinition
     oCompD = ThisApplication.ActiveDocument.ComponentDefinition

with:

Dim yourOccurenceName = "Fill the occurence name from your assembly browser name here!"
Dim doc As AssemblyDocument = ThisDoc.Document
Dim partDoc As PartDocument
Try
	Dim occ As ComponentOccurrence = doc.ComponentDefinition.Occurrences.ItemByName(yourOccurenceName)
	partDoc = occ.ReferencedDocumentDescriptor.ReferencedDocument
Catch ex As Exception
	MsgBox("Could not get occurence: " & yourOccurenceName)
	return
End Try

Dim oCompD As PartComponentDefinition = partDoc.ComponentDefinitio

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes