Does anyone know if there is a way to change the Orientation of a circular pattern with iLogic?
Solved! Go to Solution.
Solved by chandra.shekar.g. Go to Solution.
Solved by chandra.shekar.g. Go to Solution.
Solved by chandra.shekar.g. Go to Solution.
Solved by chandra.shekar.g. Go to Solution.
Solved by Curtis_Waguespack. Go to Solution.
Hi josephcooley,
Here is a quick example (see the attached file also).
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
app = ThisApplication 'flip rectangular pattern direction if Feature.InventorFeature("Rectangular Pattern1").NaturalXDirection = True then Feature.InventorFeature("Rectangular Pattern1").NaturalXDirection = False Else Feature.InventorFeature("Rectangular Pattern1").NaturalXDirection = True End if 'flip circular pattern direction if Feature.InventorFeature("Circular Pattern1").NaturalAxisDirection = True then Feature.InventorFeature("Circular Pattern1").NaturalAxisDirection = False Else Feature.InventorFeature("Circular Pattern1").NaturalAxisDirection = True End if
Hi Long time no post but it looks like something has stopped working with this rule in the new release for some reason.
SyntaxEditor Code Snippet
app = ThisApplication If Orientation="CW" Then Feature.InventorFeature("NubPattern").NaturalAxisDirection = True 'flip circular pattern direction Else If Orientation="CCW" Feature.InventorFeature("Pattern").NaturalAxisDirection = False 'flip circular pattern direction End If
Its giving me this Error Message
Error in rule: Orientation, in document: Headcell3DesignTool.ipt
Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
And this is on the More Info Tab
System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
at Microsoft.VisualBasic.CompilerServices.LateBinding.InternalLateSet(Object o, Type& objType, String name, Object[] args, String[] paramnames, Boolean OptimisticSet, CallType UseCallType)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateSet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean OptimisticSet, Boolean RValueBase, CallType CallType)
at LmiRuleScript.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
Any idea why this rule would have stopped working suddenly with the new release, or if there is a new syntax that needs to be used in Inventor 2018?
How would I do this same thing for an assembly? For a circular pattern with parts instead of features.
Try below iLogic code to change orientation of circular pattern.
For Part Document:
Dim doc = ThisDoc.Document Dim oDef As PartComponentDefinition oDef = doc.ComponentDefinition If oDef.Features.CircularPatternFeatures.Item("Circular Pattern1").NaturalAxisDirection = False Then oDef.Features.CircularPatternFeatures.Item("Circular Pattern1").NaturalAxisDirection = True Else oDef.Features.CircularPatternFeatures.Item("Circular Pattern1").NaturalAxisDirection = False End If
For Assembly Document:
Dim oDoc = ThisDoc.Document Dim oDef As AssemblyComponentDefinition oDef = oDoc.ComponentDefinition Dim oPattern As CircularOccurrencePattern oPattern = oDef.OccurrencePatterns.Item("Component Pattern 1:1") If oPattern.AxisEntityNaturalDirection = True Then oPattern.AxisEntityNaturalDirection = False Else oPattern.AxisEntityNaturalDirection = True End If
Please feel free to contact if there is any queries.
If solves problem, click on "Accept as solution" / give a "Kudo".
Thanks and regards,
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
Unfortunately, nested CircularOccurrencePattern is unable to list in OccurrencePatterns Object. So, a change request (INVGEN - 13017) is raised on this.
Thanks and regards,
For nested circular pattern, needs some changes in iLogic code. Try the below iLogic code.
Sub Main() Dim oDoc As AssemblyDocument oDoc = ThisApplication.ActiveDocument Dim oDef As AssemblyComponentDefinition oDef = oDoc.ComponentDefinition Dim oTopPattern As OccurrencePattern oTopPattern = oDef.OccurrencePatterns(1) Dim oPatternElement As OccurrencePatternElement oPatternElement = oTopPattern.OccurrencePatternElements(1) Dim oSubPattern As OccurrencePattern oSubPattern = oPatternElement.Components(1) If oSubPattern.AxisEntityNaturalDirection = True Then oSubPattern.AxisEntityNaturalDirection = False Else oSubPattern.AxisEntityNaturalDirection = True End If End Sub
Please feel free to contact if there is any queries.
If solves problem, click on "accept as solution" / give a "Kudo".
Thanks and regards,
Looks like I spoke too soon. It triggers fine when I run the rule exclusively when that assembly is open. However that assembly is in another top level assembly. I have it set to trigger the rule before save.
here is the code text:
SyntaxEditor Code Snippet
Sub Main() Dim oDoc As AssemblyDocument oDoc = ThisApplication.ActiveDocument Dim oDef As AssemblyComponentDefinition oDef = oDoc.ComponentDefinition Dim oTopPattern As OccurrencePattern oTopPattern = oDef.OccurrencePatterns(1) Dim oPatternElement As OccurrencePatternElement oPatternElement = oTopPattern.OccurrencePatternElements(1) Dim oSubPattern As OccurrencePattern oSubPattern = oPatternElement.Components(1) If OrientationNumeric = 0 Then oSubPattern.AxisEntityNaturalDirection = False Else oSubPattern.AxisEntityNaturalDirection = True End If End Sub
The problem is that I want it to run when I save the Top level asembly each sub assmebly that the above rule is in gives me this:
ERROR MESSAGE:
Error in rule: Orientation, in document: Tray Stack, Bottom_HC3.iam
Unable to cast COM object of type 'System.__ComObject' to interface type 'Inventor.OccurrencePattern'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{09A5CE88-D529-499E-82EF-246D8DC4F5B3}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
MORE INFO:
System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'Inventor.OccurrencePattern'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{09A5CE88-D529-499E-82EF-246D8DC4F5B3}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
at LmiRuleScript.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
Any idea why the rule would run fine when it was executed from the assembly the rule is in, but when its run as a result of the top level assembly being saved trigger an error?
My apologies for late reply.
Try the below iLogic code. oDoc = ThisApplication.ActiveDocument represents top level assembly not sub assembly. Searching for OccurencePattern in main assembly or top level assembly. Instead of this, oDoc = ThisDoc.Document would solve the issue.
Sub Main()
Dim oDoc As AssemblyDocument
oDoc = ThisDoc.Document
Dim oDef As AssemblyComponentDefinition
oDef = oDoc.ComponentDefinition
Dim oTopPattern As OccurrencePattern
oTopPattern = oDef.OccurrencePatterns(1)
Dim oPatternElement As OccurrencePatternElement
oPatternElement = oTopPattern.OccurrencePatternElements(1)
Dim oSubPattern As OccurrencePattern
oSubPattern = oPatternElement.Components(1)
If OrientationNumeric = 1 Then
oSubPattern.AxisEntityNaturalDirection = True
Else
oSubPattern.AxisEntityNaturalDirection = False
End If
End Sub
Please feel free to contact if there is any queries.
If solves problem, click on "Accept as solution" / give a "Kudo".
Thanks and regards,
That was exactly what the problem was. Thank you again so much. You really saved me here. Works Flawlessly!