what is the "correct" way to write this line of code for a rule?

what is the "correct" way to write this line of code for a rule?

chris
Advisor Advisor
265 Views
5 Replies
Message 1 of 6

what is the "correct" way to write this line of code for a rule?

chris
Advisor
Advisor

I have a top level assembly, and within that top level assembly I have a sub-assembly. That sub-assembly contains a pattern feature called "Array", I'd like to control this sub-assembly feature from the top level to where it will be either "True" or "False".

 

I'm trying to use this snippet:    Feature.IsActive("iStairHandrail:1", "Array") = True

 

But I keep getting an error that says this:     Feature.IsActive: No feature found with the name: "Array".

 

chris_0-1754878738380.png

 

he image clearly shows there is a feature called "Array" (see image)

0 Likes
266 Views
5 Replies
Replies (5)
Message 2 of 6

kerem.izmirli
Contributor
Contributor

Hey mate, I'm certainly no expert so if my solution doesn't work, I apologise in advance.

 

However, I think because you're in a top level assembly, and you're trying to access a feature in a sub-assembly, I believe you need to define the sub-assemblies and the component definitions first in order to access that lower level feature.

This is a rule I have which I used to explode patterns, which I believe will show you how to access the pattern feature. The other rule I have is used to see if all lower assemblies have a View Representation named "Hidden" and if it does, it will set it to active, which is used to hide my master sketch parts from the top-level assembly without needing to go turn all of them off individually. Please note, I don't take any credit for either of these, I have found bits and pieces of code and examples from the internet and modified it to make it work.

 

If this is of any help, please let me know 🙂

' <FireOthersImmediately>False</FireOthersImmediately>
Sub Main() ExplodePattern
'**** Define Assembly & Pattern Occurence.
Dim oDoc As AssemblyDocument
        oDoc = ThisApplication.ActiveDocument

Dim oPattern As OccurrencePattern
		oPatternInput = InputBox("Pattern Feature Name")
        oPattern = oDoc.ComponentDefinition.OccurrencePatterns.Item(oPatternInput)
'**** Make each element dependent starting from the 2nd element.
Dim i As Integer

'**** Count the amount of elements after the 2nd.
    For i = 2 To oPattern.OccurrencePatternElements.Count

'**** Make all elements "Independent".
            oPattern.OccurrencePatternElements.Item(i).Independent = True
      Next

'**** Delete pattern leaving only original and independent items.
oPattern.Delete

 End Sub

 

 

Dim oAssyDoc As AssemblyDocument
oAssyDoc = ThisApplication.ActiveDocument

Dim oAssyCompDef As AssemblyComponentDefinition
oAssyCompDef = oAssyDoc.ComponentDefinition

Dim oOccurrences As ComponentOccurrences
oOccurrences = oAssyCompDef.Occurrences

Dim oLeafOccs As ComponentOccurrencesEnumerator
oLeafOccs = oOccurrences.AllLeafOccurrences

Dim oLeafOcc As ComponentOccurrence

For Each oLeafOcc In oLeafOccs
 ' DO YOUR WORK HERE
	
' ########## - TURN OFF VISIBILITY FOR ALL PARTS CONTAINING STRING BELOW - ###########	
	Dim oPDef As PartComponentDefinition = oLeafOcc.Definition
	oDVRepName = "Hidden"
	oDVReps = oPDef.RepresentationsManager.DesignViewRepresentations
	For Each oDVRep As DesignViewRepresentation In oDVReps
		If oDVRep.Name = oDVRepName Then
			'Found it'
			oLeafOcc.SetDesignViewRepresentation(oDVRepName, , True)
		End If
		Next
' ########## - END OF MY SECTION - ###########	

Next

 

 

0 Likes
Message 3 of 6

mat_hijs
Collaborator
Collaborator

Occurrence patterns are not recognized as features in iLogic, but instead they are recognized as components. So you should use:

Component.IsActive("Array") = BooleanParameter

For actual components you could use that same line with a MakePath to point to the correct component, but for occurrence patterns that doesn't seem to work. I'm not sure if that's a bug or just a limitation. Maybe @MjDeck could take a look a that. 

Anyway, it is possible to do the same thing using the Inventor API like this:

' This line doesn't work because Component.IsActive doesn't seem to accept a path to the Occurrence Pattern
' Component.IsActive(MakePath("iStairHandrail:1", "Array")) = BooleanParameter

' Set a reference to the Assembly Document
Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument

' Set a reference to the Assembly Component Definition
Dim oAsmCompDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition

' Set a reference to the Component Occurrences
Dim oOccurrences As ComponentOccurrences = oAsmCompDef.Occurrences

' Set a reference to a Component Occurrence
Dim oOcc As ComponentOccurrence = oOccurrences.ItemByName("iStairHandrail:1") ' You should probably change this name to avoid undesirable behavior

' Set a reference to the Occurrence Component Definition
Dim oOccCompDef As AssemblyComponentDefinition = oOcc.Definition

' Set a reference to the Occurrence Pattern
Dim oOccPattern As OccurrencePattern = oOccCompDef.OccurrencePatterns.Item("Array")

' Suppress or Unsuppress the Occurrence Pattern
If BooleanParameter = False Then
	oOccPattern.Suppress
Else
	oOccPattern.Unsuppress
End If

 

0 Likes
Message 4 of 6

WCrihfield
Mentor
Mentor

If you really want to stick with uniquely iLogic resources, there is also the iLogic 'Rule Object' named 'Patterns' (representing the IManagedPatterns Interface), which you could try out in a situation like this.  It is obviously designed just for patterns, but more for creating and deleting them, rather than suppressing them, so not as simple to use for that.  You would first have to use its 'Item' Property, which is where you would specify the name of the pattern it should find/get.  But I am not sure if that property allows for specifying the name of the component representing the sub assembly, as part of that name specification.  I never really used it that much myself, opting for the original Inventor API route in most situations.  That Property will return a uniquely iLogic 'ManagedPattern' object (if found).  Both of that object's Properties will return the native Inventor API objects associated with that pattern (Pattern = OccurrencePattern ; Element = OccurrencePatternElement).  Once you have the OccurrencePattern object, you can check its Suppressed property (ReadOnly), then use either its Suppress method, or its Unsuppress method.  But all that hinges on whether or not it allows working within a sub assembly, instead of directly in the 'active/local' assembly.

Just another angle that could be checked-out.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 6

MjDeck
Autodesk
Autodesk

Hi @chris - the standard iLogic way to do this is to add a rule in the subassembly.
First, in the subassembly add a True/False parameter named ArrayIsActive. Then add a rule with this line:

Component.IsActive("Array") = ArrayIsActive

 Then you can drive the ArrayIsActive parameter from the top-level assembly, in the same way you might drive other parameters.


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 6 of 6

Michael.Navara
Advisor
Advisor

Hi @chris 

Usually I use full API for this purposes, but sometimes it can be useful to use advantages of iLogic. In this case you can create variable (subAsmComponent) which is of the same type as property Component in active rule. But this variable has the context of the subAsmDoc. It means it is the same as property Component in rule in sub assembly. Then you can use code similar to the standard one:

 

Dim topAsm As AssemblyDocument = ThisDoc.Document
Dim subAsmOcc As ComponentOccurrence = topAsm.ComponentDefinition.Occurrences(1) 'First occurrence of the top assembly
Dim subAsmDoc As AssemblyDocument = subAsmOcc.Definition.Document

Dim subAsmComponent As ICadComponent = Autodesk.iLogic.Interfaces.StandardObjectFactory.Create(subAsmDoc).Component

Dim isActive As Boolean = subAsmComponent.IsActive("Array")
subAsmComponent.IsActive("Array") = Not isActive' switch the state of Array

 

0 Likes