Flipping component pattern in assemblies with iLogic

Flipping component pattern in assemblies with iLogic

Anonymous
Not applicable
2,149 Views
12 Replies
Message 1 of 13

Flipping component pattern in assemblies with iLogic

Anonymous
Not applicable

I have an assembly with a component pattern that I want to flip the direction with iLogic (or other rule type) by reading a multivalue parameter which reads either "LEFT" or "RIGHT". Can this be done?

0 Likes
Accepted solutions (1)
2,150 Views
12 Replies
Replies (12)
Message 2 of 13

Anonymous
Not applicable

Hello and welcome to the community.

 

Is the pattern you are changing a rectangular pattern? and if so is it just the the column direction you want to change?

0 Likes
Message 3 of 13

Anonymous
Not applicable
Accepted solution

Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument

 

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = oDoc.ComponentDefinition

 

Dim oOccPat As OccurrencePattern
oOccPat = oAsmCompDef.OccurrencePatterns.Item(1)

 

If parameter = "LEFT" Then

oOccPat.ColumnEntityNaturalDirection = False

Else

oOccPat.ColumnEntityNaturalDirection = True

End If

 

If you have more than one pattern, you may want to define the pattern by its name rather than item number. In that instance you would use:

oOccPat = oAsmCompDef.OccurrencePatterns.Item("Component Pattern Name")

Message 4 of 13

frederic.vandenplas
Collaborator
Collaborator

(This must be posted exactly at the same moment as someone else)

 

in 2015 i could not use a multivalue parameter, so i used a True/False paramer, this may be altered if needed.

 

Sub FlipPattern()

Dim oIamDoc As AssemblyDocument
Set oIamDoc = ThisApplication.ActiveDocument

Dim oIamDocDef As AssemblyComponentDefinition
oIamDocDef = oIamDoc.ComponentDefinition

Dim oRecPattern As RectangularOccurrencePattern
oRecPattern = oIamDocDef.OccurrencePatterns("Component Pattern 1:1")  'Change as needed

Dim oUserParamDirection As UserParameter
oUserParamDirection = oIamDocDef.Parameters.UserParameters.Item("Direction")

If oUserParamDirection.Value = "True" Then 'Change as needed
    oRecPattern.ColumnEntityNaturalDirection = True
Else
    oRecPattern.ColumnEntityNaturalDirection = False
End If

End Sub

 

 

If you think this answer fullfilled your needs, improved your knowledge or leads to a solution,
please feel free to "kudos"
0 Likes
Message 5 of 13

Anonymous
Not applicable

This worked beautifully...thank you

0 Likes
Message 6 of 13

Anonymous
Not applicable

I received an error using this one, but I probably overlooked or mistakenly edited the code improperly to fit my situation. Since the code posted above worked, I didn't chase down the error. I still want to thank you for your help though...

0 Likes
Message 7 of 13

Anonymous
Not applicable

Set oIamDoc = ThisApplication.ActiveDocument

 

Removing the word Set  from this line would probably fix the error.

0 Likes
Message 8 of 13

josephcooley
Advocate
Advocate

I'm having trouble with this I have a circular pattern that is not working for me.

 

SyntaxEditor Code Snippet

Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = oDoc.ComponentDefinition

Dim oOccPat As OccurrencePattern
oOccPat = oAsmCompDef.OccurrencePatterns.Item("NubSupportPattern")

If OrientationNumeric = 1 Then
oOccPat.ColumnEntityNaturalDirection = False
Else
oOccPat.ColumnEntityNaturalDirection = True
End If

ERROR MESSAGE:

Error in rule: Orientation, in document: Tray Stack, Top_HC3.iam

The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

 

INFO:

System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.OccurrencePatterns.get_Item(Object Index)
at LmiRuleScript.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

0 Likes
Message 9 of 13

josephcooley
Advocate
Advocate

I am trying to do flip a circular pattern does that make a difference?

0 Likes
Message 10 of 13

Anonymous
Not applicable

Not able to test it myself, but I think if you change ColumnEntityNaturalDirection to AxisEntityNaturalDirection it will work.

 

I found that via the API help:

http://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-1C7846A1-15A4-4C97-9C0B-B2F852A927D3

 

Message 11 of 13

josephcooley
Advocate
Advocate

Perfect that worked exactly as intended thank you!

0 Likes
Message 12 of 13

josephcooley
Advocate
Advocate

This worked for one assembly but I have a circular pattern nested within a linear pattern in another assembly and its not working correctly. its giving me this message below:

 

Error Message:

Error in rule: Orientation, in document: Tray Stack, Bottom_HC3.iam

The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

 

More Info

System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.OccurrencePatterns.get_Item(Object Index)
at LmiRuleScript.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

I have attached a screenshot of the model tree structure.  The "rotational pattern" is the one I want to switch within the "Linear Pattern"


Here is the code:

 

SyntaxEditor Code Snippet

trigger = OrientationNumeric

Dim oDoc = ThisDoc.Document

Dim oDef As AssemblyComponentDefinition
oDef = oDoc.ComponentDefinition

Dim oPattern As CircularOccurrencePattern
oPattern = oDef.OccurrencePatterns.Item("Rotational Pattern")

If OrientationNumeric = 0 Then
	oPattern.AxisEntityNaturalDirection = False 
Else
	oPattern.AxisEntityNaturalDirection = True 
End If 

 

0 Likes
Message 13 of 13

jfenter
Enthusiast
Enthusiast

I am working on something similar, except I would like to reverse the direction of a feature pattern within a part.   How do I define the features within the part?

0 Likes